You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(app): update AppBloc to handle user roles list
This refactors the AppBloc's user change handler to correctly evaluate dashboard access based on the user.roles list instead of a singular role property.
The logic now checks for 'admin' or 'publisher' roles to grant authenticated status. It also corrects the condition for fetching user settings to depend on this authenticated status, not just the presence of a user object.
Copy file name to clipboardExpand all lines: lib/app_configuration/view/app_configuration_page.dart
+35-24Lines changed: 35 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -282,8 +282,13 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
282
282
horizontal:AppSpacing.xxl,
283
283
),
284
284
children: [
285
-
_UserPreferenceLimitsForm(
286
-
userRole:UserRole.guestUser,
285
+
_UserPreferenceLimitsForm(refactor(app_configuration): use UserRoles string constants
286
+
287
+
This change refactors the AppConfigurationPage and its helper form widgets to use string-based role constants from the `UserRoles` class instead of an obsolete `UserRole` enum.
288
+
289
+
This aligns the UIwith the updated `User` model, which represents roles as a list of strings, ensuring consistency across the application.
290
+
291
+
userRole:UserRoles.guestUser,
287
292
appConfig: appConfig,
288
293
onConfigChanged: (newConfig) {
289
294
context.read<AppConfigurationBloc>().add(
@@ -303,7 +308,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
303
308
),
304
309
children: [
305
310
_UserPreferenceLimitsForm(
306
-
userRole:UserRole.standardUser,
311
+
userRole:UserRoles.standardUser,
307
312
appConfig: appConfig,
308
313
onConfigChanged: (newConfig) {
309
314
context.read<AppConfigurationBloc>().add(
@@ -323,7 +328,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
323
328
),
324
329
children: [
325
330
_UserPreferenceLimitsForm(
326
-
userRole:UserRole.premiumUser,
331
+
userRole:UserRoles.premiumUser,
327
332
appConfig: appConfig,
328
333
onConfigChanged: (newConfig) {
329
334
context.read<AppConfigurationBloc>().add(
@@ -359,7 +364,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
359
364
),
360
365
children: [
361
366
_AdConfigForm(
362
-
userRole:UserRole.guestUser,
367
+
userRole:UserRoles.guestUser,
363
368
appConfig: appConfig,
364
369
onConfigChanged: (newConfig) {
365
370
context.read<AppConfigurationBloc>().add(
@@ -379,7 +384,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
379
384
),
380
385
children: [
381
386
_AdConfigForm(
382
-
userRole:UserRole.standardUser,
387
+
userRole:UserRoles.standardUser,
383
388
appConfig: appConfig,
384
389
onConfigChanged: (newConfig) {
385
390
context.read<AppConfigurationBloc>().add(
@@ -399,7 +404,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
399
404
),
400
405
children: [
401
406
_AdConfigForm(
402
-
userRole:UserRole.premiumUser,
407
+
userRole:UserRoles.premiumUser,
403
408
appConfig: appConfig,
404
409
onConfigChanged: (newConfig) {
405
410
context.read<AppConfigurationBloc>().add(
@@ -438,7 +443,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
438
443
),
439
444
children: [
440
445
_AccountActionConfigForm(
441
-
userRole:UserRole.guestUser,
446
+
userRole:UserRoles.guestUser,
442
447
appConfig: appConfig,
443
448
onConfigChanged: (newConfig) {
444
449
context.read<AppConfigurationBloc>().add(
@@ -458,7 +463,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
458
463
),
459
464
children: [
460
465
_AccountActionConfigForm(
461
-
userRole:UserRole.standardUser,
466
+
userRole:UserRoles.standardUser,
462
467
appConfig: appConfig,
463
468
onConfigChanged: (newConfig) {
464
469
context.read<AppConfigurationBloc>().add(
@@ -779,7 +784,7 @@ class _UserPreferenceLimitsForm extends StatefulWidget {
779
784
requiredthis.buildIntField,
780
785
});
781
786
782
-
finalUserRole userRole;
787
+
finalString userRole;
783
788
finalAppConfig appConfig;
784
789
finalValueChanged<AppConfig> onConfigChanged;
785
790
finalWidgetFunction(
@@ -936,7 +941,7 @@ class _UserPreferenceLimitsFormState extends State<_UserPreferenceLimitsForm> {
936
941
final userPreferenceLimits = widget.appConfig.userPreferenceLimits;
937
942
938
943
switch (widget.userRole) {
939
-
caseUserRole.guestUser:
944
+
caseUserRoles.guestUser:
940
945
returnColumn(
941
946
children: [
942
947
widget.buildIntField(
@@ -975,7 +980,7 @@ class _UserPreferenceLimitsFormState extends State<_UserPreferenceLimitsForm> {
975
980
),
976
981
],
977
982
);
978
-
caseUserRole.standardUser:
983
+
caseUserRoles.standardUser:
979
984
returnColumn(
980
985
children: [
981
986
widget.buildIntField(
@@ -1015,7 +1020,7 @@ class _UserPreferenceLimitsFormState extends State<_UserPreferenceLimitsForm> {
1015
1020
),
1016
1021
],
1017
1022
);
1018
-
caseUserRole.premiumUser:
1023
+
caseUserRoles.premiumUser:
1019
1024
returnColumn(
1020
1025
children: [
1021
1026
widget.buildIntField(
@@ -1055,10 +1060,12 @@ class _UserPreferenceLimitsFormState extends State<_UserPreferenceLimitsForm> {
1055
1060
),
1056
1061
],
1057
1062
);
1058
-
caseUserRole.admin:
1063
+
caseUserRoles.admin:
1059
1064
// Admin role might not have specific limits here, or could be
1060
1065
// a separate configuration. For now, return empty.
1061
1066
returnconstSizedBox.shrink();
1067
+
default:
1068
+
returnconstSizedBox.shrink();
1062
1069
}
1063
1070
}
1064
1071
}
@@ -1071,7 +1078,7 @@ class _AdConfigForm extends StatefulWidget {
1071
1078
requiredthis.buildIntField,
1072
1079
});
1073
1080
1074
-
finalUserRole userRole;
1081
+
finalString userRole;
1075
1082
finalAppConfig appConfig;
1076
1083
finalValueChanged<AppConfig> onConfigChanged;
1077
1084
finalWidgetFunction(
@@ -1271,7 +1278,7 @@ class _AdConfigFormState extends State<_AdConfigForm> {
1271
1278
final adConfig = widget.appConfig.adConfig;
1272
1279
1273
1280
switch (widget.userRole) {
1274
-
caseUserRole.guestUser:
1281
+
caseUserRoles.guestUser:
1275
1282
returnColumn(
1276
1283
children: [
1277
1284
widget.buildIntField(
@@ -1329,7 +1336,7 @@ class _AdConfigFormState extends State<_AdConfigForm> {
1329
1336
),
1330
1337
],
1331
1338
);
1332
-
caseUserRole.standardUser:
1339
+
caseUserRoles.standardUser:
1333
1340
returnColumn(
1334
1341
children: [
1335
1342
widget.buildIntField(
@@ -1391,7 +1398,7 @@ class _AdConfigFormState extends State<_AdConfigForm> {
1391
1398
),
1392
1399
],
1393
1400
);
1394
-
caseUserRole.premiumUser:
1401
+
caseUserRoles.premiumUser:
1395
1402
returnColumn(
1396
1403
children: [
1397
1404
widget.buildIntField(
@@ -1450,7 +1457,9 @@ class _AdConfigFormState extends State<_AdConfigForm> {
1450
1457
),
1451
1458
],
1452
1459
);
1453
-
caseUserRole.admin:
1460
+
caseUserRoles.admin:
1461
+
returnconstSizedBox.shrink();
1462
+
default:
1454
1463
returnconstSizedBox.shrink();
1455
1464
}
1456
1465
}
@@ -1464,7 +1473,7 @@ class _AccountActionConfigForm extends StatefulWidget {
1464
1473
requiredthis.buildIntField,
1465
1474
});
1466
1475
1467
-
finalUserRole userRole;
1476
+
finalString userRole;
1468
1477
finalAppConfig appConfig;
1469
1478
finalValueChanged<AppConfig> onConfigChanged;
1470
1479
finalWidgetFunction(
@@ -1553,7 +1562,7 @@ class _AccountActionConfigFormState extends State<_AccountActionConfigForm> {
1553
1562
final accountActionConfig = widget.appConfig.accountActionConfig;
1554
1563
1555
1564
switch (widget.userRole) {
1556
-
caseUserRole.guestUser:
1565
+
caseUserRoles.guestUser:
1557
1566
returnColumn(
1558
1567
children: [
1559
1568
widget.buildIntField(
@@ -1576,7 +1585,7 @@ class _AccountActionConfigFormState extends State<_AccountActionConfigForm> {
1576
1585
),
1577
1586
],
1578
1587
);
1579
-
caseUserRole.standardUser:
1588
+
caseUserRoles.standardUser:
1580
1589
returnColumn(
1581
1590
children: [
1582
1591
widget.buildIntField(
@@ -1599,8 +1608,10 @@ class _AccountActionConfigFormState extends State<_AccountActionConfigForm> {
0 commit comments