Skip to content

Commit 7fd9f18

Browse files
committed
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.
1 parent 80c1ed5 commit 7fd9f18

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

lib/app_configuration/view/app_configuration_page.dart

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,13 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
282282
horizontal: AppSpacing.xxl,
283283
),
284284
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 UI with the updated `User` model, which represents roles as a list of strings, ensuring consistency across the application.
290+
291+
userRole: UserRoles.guestUser,
287292
appConfig: appConfig,
288293
onConfigChanged: (newConfig) {
289294
context.read<AppConfigurationBloc>().add(
@@ -303,7 +308,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
303308
),
304309
children: [
305310
_UserPreferenceLimitsForm(
306-
userRole: UserRole.standardUser,
311+
userRole: UserRoles.standardUser,
307312
appConfig: appConfig,
308313
onConfigChanged: (newConfig) {
309314
context.read<AppConfigurationBloc>().add(
@@ -323,7 +328,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
323328
),
324329
children: [
325330
_UserPreferenceLimitsForm(
326-
userRole: UserRole.premiumUser,
331+
userRole: UserRoles.premiumUser,
327332
appConfig: appConfig,
328333
onConfigChanged: (newConfig) {
329334
context.read<AppConfigurationBloc>().add(
@@ -359,7 +364,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
359364
),
360365
children: [
361366
_AdConfigForm(
362-
userRole: UserRole.guestUser,
367+
userRole: UserRoles.guestUser,
363368
appConfig: appConfig,
364369
onConfigChanged: (newConfig) {
365370
context.read<AppConfigurationBloc>().add(
@@ -379,7 +384,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
379384
),
380385
children: [
381386
_AdConfigForm(
382-
userRole: UserRole.standardUser,
387+
userRole: UserRoles.standardUser,
383388
appConfig: appConfig,
384389
onConfigChanged: (newConfig) {
385390
context.read<AppConfigurationBloc>().add(
@@ -399,7 +404,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
399404
),
400405
children: [
401406
_AdConfigForm(
402-
userRole: UserRole.premiumUser,
407+
userRole: UserRoles.premiumUser,
403408
appConfig: appConfig,
404409
onConfigChanged: (newConfig) {
405410
context.read<AppConfigurationBloc>().add(
@@ -438,7 +443,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
438443
),
439444
children: [
440445
_AccountActionConfigForm(
441-
userRole: UserRole.guestUser,
446+
userRole: UserRoles.guestUser,
442447
appConfig: appConfig,
443448
onConfigChanged: (newConfig) {
444449
context.read<AppConfigurationBloc>().add(
@@ -458,7 +463,7 @@ class _AppConfigurationPageState extends State<AppConfigurationPage> {
458463
),
459464
children: [
460465
_AccountActionConfigForm(
461-
userRole: UserRole.standardUser,
466+
userRole: UserRoles.standardUser,
462467
appConfig: appConfig,
463468
onConfigChanged: (newConfig) {
464469
context.read<AppConfigurationBloc>().add(
@@ -779,7 +784,7 @@ class _UserPreferenceLimitsForm extends StatefulWidget {
779784
required this.buildIntField,
780785
});
781786

782-
final UserRole userRole;
787+
final String userRole;
783788
final AppConfig appConfig;
784789
final ValueChanged<AppConfig> onConfigChanged;
785790
final Widget Function(
@@ -936,7 +941,7 @@ class _UserPreferenceLimitsFormState extends State<_UserPreferenceLimitsForm> {
936941
final userPreferenceLimits = widget.appConfig.userPreferenceLimits;
937942

938943
switch (widget.userRole) {
939-
case UserRole.guestUser:
944+
case UserRoles.guestUser:
940945
return Column(
941946
children: [
942947
widget.buildIntField(
@@ -975,7 +980,7 @@ class _UserPreferenceLimitsFormState extends State<_UserPreferenceLimitsForm> {
975980
),
976981
],
977982
);
978-
case UserRole.standardUser:
983+
case UserRoles.standardUser:
979984
return Column(
980985
children: [
981986
widget.buildIntField(
@@ -1015,7 +1020,7 @@ class _UserPreferenceLimitsFormState extends State<_UserPreferenceLimitsForm> {
10151020
),
10161021
],
10171022
);
1018-
case UserRole.premiumUser:
1023+
case UserRoles.premiumUser:
10191024
return Column(
10201025
children: [
10211026
widget.buildIntField(
@@ -1055,10 +1060,12 @@ class _UserPreferenceLimitsFormState extends State<_UserPreferenceLimitsForm> {
10551060
),
10561061
],
10571062
);
1058-
case UserRole.admin:
1063+
case UserRoles.admin:
10591064
// Admin role might not have specific limits here, or could be
10601065
// a separate configuration. For now, return empty.
10611066
return const SizedBox.shrink();
1067+
default:
1068+
return const SizedBox.shrink();
10621069
}
10631070
}
10641071
}
@@ -1071,7 +1078,7 @@ class _AdConfigForm extends StatefulWidget {
10711078
required this.buildIntField,
10721079
});
10731080

1074-
final UserRole userRole;
1081+
final String userRole;
10751082
final AppConfig appConfig;
10761083
final ValueChanged<AppConfig> onConfigChanged;
10771084
final Widget Function(
@@ -1271,7 +1278,7 @@ class _AdConfigFormState extends State<_AdConfigForm> {
12711278
final adConfig = widget.appConfig.adConfig;
12721279

12731280
switch (widget.userRole) {
1274-
case UserRole.guestUser:
1281+
case UserRoles.guestUser:
12751282
return Column(
12761283
children: [
12771284
widget.buildIntField(
@@ -1329,7 +1336,7 @@ class _AdConfigFormState extends State<_AdConfigForm> {
13291336
),
13301337
],
13311338
);
1332-
case UserRole.standardUser:
1339+
case UserRoles.standardUser:
13331340
return Column(
13341341
children: [
13351342
widget.buildIntField(
@@ -1391,7 +1398,7 @@ class _AdConfigFormState extends State<_AdConfigForm> {
13911398
),
13921399
],
13931400
);
1394-
case UserRole.premiumUser:
1401+
case UserRoles.premiumUser:
13951402
return Column(
13961403
children: [
13971404
widget.buildIntField(
@@ -1450,7 +1457,9 @@ class _AdConfigFormState extends State<_AdConfigForm> {
14501457
),
14511458
],
14521459
);
1453-
case UserRole.admin:
1460+
case UserRoles.admin:
1461+
return const SizedBox.shrink();
1462+
default:
14541463
return const SizedBox.shrink();
14551464
}
14561465
}
@@ -1464,7 +1473,7 @@ class _AccountActionConfigForm extends StatefulWidget {
14641473
required this.buildIntField,
14651474
});
14661475

1467-
final UserRole userRole;
1476+
final String userRole;
14681477
final AppConfig appConfig;
14691478
final ValueChanged<AppConfig> onConfigChanged;
14701479
final Widget Function(
@@ -1553,7 +1562,7 @@ class _AccountActionConfigFormState extends State<_AccountActionConfigForm> {
15531562
final accountActionConfig = widget.appConfig.accountActionConfig;
15541563

15551564
switch (widget.userRole) {
1556-
case UserRole.guestUser:
1565+
case UserRoles.guestUser:
15571566
return Column(
15581567
children: [
15591568
widget.buildIntField(
@@ -1576,7 +1585,7 @@ class _AccountActionConfigFormState extends State<_AccountActionConfigForm> {
15761585
),
15771586
],
15781587
);
1579-
case UserRole.standardUser:
1588+
case UserRoles.standardUser:
15801589
return Column(
15811590
children: [
15821591
widget.buildIntField(
@@ -1599,8 +1608,10 @@ class _AccountActionConfigFormState extends State<_AccountActionConfigForm> {
15991608
),
16001609
],
16011610
);
1602-
case UserRole.premiumUser:
1603-
case UserRole.admin:
1611+
case UserRoles.premiumUser:
1612+
case UserRoles.admin:
1613+
return const SizedBox.shrink();
1614+
default:
16041615
return const SizedBox.shrink();
16051616
}
16061617
}

0 commit comments

Comments
 (0)