Skip to content

Commit a0acbd4

Browse files
committed
fixed admin actions visible while guest
1 parent d26c0fd commit a0acbd4

5 files changed

Lines changed: 36 additions & 28 deletions

File tree

lib/api/CategoryAPI.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Future<Map<String,dynamic>> fetchAlbums(String albumID) async {
3030
var categoryList = result['result']['categories'];
3131
for (var cat in categoryList) {
3232
bool canUpload = false;
33-
if (API.prefs.getString('user_status') != 'normal'
33+
if (!['normal', 'guest'].contains(API.prefs.getString('user_status'))
3434
|| uploadCategoryIdList.contains(cat['id'].toString())) {
3535
canUpload = true;
3636
}

lib/api/SessionAPI.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Future<String> loginUser(String url, String username, String password) async {
4343
return 'Something happened';
4444
}
4545
Future<String> loginGuest(String url) async {
46-
4746
API().dio.options.baseUrl = url;
4847

4948
try {

lib/views/CategoryViewPage.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class _CategoryViewPageState extends State<CategoryViewPage> with SingleTickerPr
356356
title: _isEditMode ?
357357
Text("${_selectedItems.length}", overflow: TextOverflow.fade, softWrap: true) :
358358
Text(widget.title),
359-
actions: [
359+
actions: widget.isAdmin ? [
360360
_isEditMode ? IconButton(
361361
onPressed: _onSelectAll,
362362
icon: _selectedItems.length == imageList.length ?
@@ -365,11 +365,11 @@ class _CategoryViewPageState extends State<CategoryViewPage> with SingleTickerPr
365365
_isEditMode ? IconButton(
366366
onPressed: closeEditMode,
367367
icon: Icon(Icons.cancel),
368-
) : widget.isAdmin? IconButton(
368+
) : widget.isAdmin ? IconButton(
369369
onPressed: openEditMode,
370370
icon: Icon(Icons.touch_app_rounded),
371371
) : SizedBox(),
372-
],
372+
] : [],
373373
);
374374
}
375375

@@ -422,7 +422,8 @@ class _CategoryViewPageState extends State<CategoryViewPage> with SingleTickerPr
422422
overlayOpacity: 0.5,
423423
shape: CircleBorder(),
424424
children: [
425-
SpeedDialChild(
425+
if(widget.isAdmin)
426+
SpeedDialChild(
426427
elevation: 5,
427428
labelWidget: Text(appStrings(context).createNewAlbum_title, style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: Colors.white)),
428429
child: Icon(Icons.create_new_folder),
@@ -540,8 +541,10 @@ class _CategoryViewPageState extends State<CategoryViewPage> with SingleTickerPr
540541
physics: NeverScrollableScrollPhysics(),
541542
itemBuilder: (BuildContext context, int index) {
542543
var album = albums[index];
544+
print(widget.isAdmin);
543545
return AlbumListItem(album,
544-
isAdmin: API.prefs.getString('user_status') != 'normal',
546+
isAdmin: widget.isAdmin && API.prefs.getString('user_status') != 'normal',
547+
canUpload: API.prefs.getString('user_status') == 'normal' && _canUpload,
545548
onClose: () {
546549
setState(() {
547550
_getData();

lib/views/RootCategoryViewPage.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ class _RootCategoryViewPageState extends State<RootCategoryViewPage> with Single
211211
itemBuilder: (BuildContext context, int index) {
212212
var album = albums[index];
213213
return AlbumListItem(album,
214-
isAdmin: API.prefs.getString('user_status') != 'normal',
214+
isAdmin: widget.isAdmin && API.prefs.getString('user_status') != 'normal',
215+
canUpload: API.prefs.getString('user_status') == 'normal' && album['can_upload'],
215216
onClose: () {
216217
setState(() {
217218
_getData();

lib/views/components/list_item.dart

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ String albumSubCount(dynamic album, context) {
2020
}
2121

2222
class AlbumListItem extends StatefulWidget {
23-
const AlbumListItem(this.album, {Key key, this.isAdmin = false, this.onClose, this.onOpen}) : super(key: key);
23+
const AlbumListItem(this.album, {Key key, this.isAdmin = false, this.onClose, this.onOpen, this.canUpload = false}) : super(key: key);
2424

2525
final dynamic album;
2626
final bool isAdmin;
27+
final bool canUpload;
2728
final Function() onClose;
2829
final Function() onOpen;
2930

@@ -138,37 +139,40 @@ class _AlbumListItemState extends State<AlbumListItem> {
138139
borderRadius: BorderRadius.circular(10),
139140
child: Slidable(
140141
enabled: widget.isAdmin,
141-
child: AlbumListCard(widget.album, isAdmin: widget.isAdmin),
142+
child: AlbumListCard(widget.album, isAdmin: widget.isAdmin, canUpload: widget.canUpload,),
142143
endActionPane: ActionPane(
143144
motion: DrawerMotion(),
144145
children: [
145146
CustomSlidableAction(
146147
backgroundColor: Theme.of(context).colorScheme.primary,
147-
onPressed: (_) {
148-
_onEditAlbum();
149-
},
150-
child: Center(
151-
child: Icon(Icons.edit, size: 38, color: Colors.white),
148+
onPressed: (_) => _onEditAlbum(),
149+
child: SizedBox.expand(
150+
child: FittedBox(
151+
fit: BoxFit.contain,
152+
child: Icon(Icons.edit, color: Colors.white),
153+
),
152154
),
153155
),
154156
CustomSlidableAction(
155157
backgroundColor: Color(0xFF4B4B4B),
156-
child: Center(
157-
child: Icon(Icons.reply, size: 38, color: Colors.white),
158+
onPressed: (_) => _onMoveAlbum(),
159+
child: SizedBox.expand(
160+
child: FittedBox(
161+
fit: BoxFit.contain,
162+
child: Icon(Icons.reply, color: Colors.white),
163+
),
158164
),
159-
onPressed: (_) {
160-
_onMoveAlbum();
161-
},
162165
),
163166
CustomSlidableAction(
164167
backgroundColor: Colors.red,
165-
child: Center(
166-
child: Icon(Icons.delete, size: 38, color: Colors.white),
167-
),
168168
autoClose: true,
169-
onPressed: (_) {
170-
_onDeleteAlbum();
171-
},
169+
onPressed: (_) => _onDeleteAlbum(),
170+
child: SizedBox.expand(
171+
child: FittedBox(
172+
fit: BoxFit.contain,
173+
child: Icon(Icons.delete, color: Colors.white),
174+
),
175+
),
172176
),
173177
],
174178
),
@@ -179,10 +183,11 @@ class _AlbumListItemState extends State<AlbumListItem> {
179183
}
180184

181185
class AlbumListCard extends StatelessWidget {
182-
const AlbumListCard(this.album, {Key key, this.isAdmin = false}) : super(key: key);
186+
const AlbumListCard(this.album, {Key key, this.isAdmin = false, this.canUpload = false,}) : super(key: key);
183187

184188
final dynamic album;
185189
final bool isAdmin;
190+
final bool canUpload;
186191

187192
@override
188193
Widget build(BuildContext context) {
@@ -244,7 +249,7 @@ class AlbumListCard extends StatelessWidget {
244249
maxLines: 1,
245250
),
246251
),
247-
if(album["can_upload"] ?? false) Padding(
252+
if(canUpload) Padding(
248253
padding: const EdgeInsets.only(left: 5),
249254
child: Icon(Icons.upload, size: 18,),
250255
),

0 commit comments

Comments
 (0)