@@ -119,6 +119,30 @@ class _FeedDecoratorFormState extends State<FeedDecoratorForm>
119119 super .dispose ();
120120 }
121121
122+ /// Determines if a given decorator type is logically applicable to a user role.
123+ ///
124+ /// This method centralizes the business logic for decorator visibility
125+ /// to prevent illogical configurations in the dashboard.
126+ bool _isDecoratorApplicableToRole (
127+ FeedDecoratorType decoratorType,
128+ AppUserRole role,
129+ ) {
130+ switch (decoratorType) {
131+ // The 'linkAccount' decorator is only for guest users.
132+ case FeedDecoratorType .linkAccount:
133+ return role == AppUserRole .guestUser;
134+ // The 'upgrade' decorator is only for standard users.
135+ case FeedDecoratorType .upgrade:
136+ return role == AppUserRole .standardUser;
137+ // All other decorators are applicable to any user role.
138+ case FeedDecoratorType .rateApp:
139+ case FeedDecoratorType .enableNotifications:
140+ case FeedDecoratorType .suggestedTopics:
141+ case FeedDecoratorType .suggestedSources:
142+ return true ;
143+ }
144+ }
145+
122146 @override
123147 Widget build (BuildContext context) {
124148 final l10n = AppLocalizationsX (context).l10n;
@@ -210,18 +234,19 @@ class _FeedDecoratorFormState extends State<FeedDecoratorForm>
210234 FeedDecoratorConfig decoratorConfig,
211235 ) {
212236 final roleConfig = decoratorConfig.visibleTo[role];
213- final isLinkAccountForStandardOrPremium =
214- widget.decoratorType == FeedDecoratorType .linkAccount &&
215- (role == AppUserRole .standardUser || role == AppUserRole .premiumUser);
237+ final isApplicable = _isDecoratorApplicableToRole (
238+ widget.decoratorType,
239+ role,
240+ );
216241
217242 return Column (
218243 children: [
219244 CheckboxListTile (
220245 title: Text (l10n.visibleToRoleLabel (role.l10n (context))),
221- value: roleConfig != null ,
222- onChanged : isLinkAccountForStandardOrPremium
223- ? null // Disable for standard and premium users for linkAccount
224- : (value) {
246+ value: roleConfig != null && isApplicable ,
247+ // Disable the checkbox if the decorator is not applicable to the role.
248+ onChanged : isApplicable
249+ ? (value) {
225250 final newVisibleTo =
226251 Map <AppUserRole , FeedDecoratorRoleConfig >.from (
227252 decoratorConfig.visibleTo,
@@ -245,7 +270,8 @@ class _FeedDecoratorFormState extends State<FeedDecoratorForm>
245270 feedDecoratorConfig: newFeedDecoratorConfig,
246271 ),
247272 );
248- },
273+ }
274+ : null ,
249275 ),
250276 if (roleConfig != null )
251277 Padding (
0 commit comments