From 6c170b309978d5e440ddbc938685634de994cdd1 Mon Sep 17 00:00:00 2001 From: David Christiandy <1299411+dvdchr@users.noreply.github.com> Date: Thu, 9 Mar 2023 17:37:12 +0700 Subject: [PATCH] Hide Pages menu for users with insufficient roles --- .../Classes/Models/Blog+Capabilities.swift | 6 ++++++ WordPress/Classes/Models/Blog.h | 4 +++- WordPress/Classes/Models/Blog.m | 2 ++ .../Blog Details/BlogDetailsViewController.m | 18 ++++++++++-------- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/WordPress/Classes/Models/Blog+Capabilities.swift b/WordPress/Classes/Models/Blog+Capabilities.swift index c244f974c87a..9dbfc66ec254 100644 --- a/WordPress/Classes/Models/Blog+Capabilities.swift +++ b/WordPress/Classes/Models/Blog+Capabilities.swift @@ -61,6 +61,12 @@ extension Blog { return !hasBusinessPlan && isUserCapableOf("scan") } + /// Returns true if the current user is allowed to list and edit the blog's Pages + /// + @objc public func isListingPagesAllowed() -> Bool { + return isAdmin || isUserCapableOf(.EditPages) + } + private func isUserCapableOf(_ capability: String) -> Bool { return capabilities?[capability] as? Bool ?? false } diff --git a/WordPress/Classes/Models/Blog.h b/WordPress/Classes/Models/Blog.h index 7bed7c6eaf6e..1128318f87a8 100644 --- a/WordPress/Classes/Models/Blog.h +++ b/WordPress/Classes/Models/Blog.h @@ -104,7 +104,9 @@ typedef NS_ENUM(NSUInteger, BlogFeature) { BlogFeatureFileDownloadsStats, /// Does the blog support Blaze? BlogFeatureBlaze, - + /// Does the blog support listing and editing Pages? + BlogFeaturePages, + }; typedef NS_ENUM(NSInteger, SiteVisibility) { diff --git a/WordPress/Classes/Models/Blog.m b/WordPress/Classes/Models/Blog.m index ecfc05487e7d..efc82067a094 100644 --- a/WordPress/Classes/Models/Blog.m +++ b/WordPress/Classes/Models/Blog.m @@ -612,6 +612,8 @@ - (BOOL)supports:(BlogFeature)feature return [self isHostedAtWPcom]; case BlogFeatureBlaze: return [self isBlazeApproved]; + case BlogFeaturePages: + return [self isListingPagesAllowed]; } } diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController.m b/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController.m index 6ac4c98bdac0..d97bca6d412e 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController.m +++ b/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController.m @@ -991,14 +991,16 @@ - (BlogDetailsSection *)publishTypeSectionViewModel mediaRow.quickStartIdentifier = QuickStartTourElementMediaScreen; [rows addObject:mediaRow]; - BlogDetailsRow *pagesRow = [[BlogDetailsRow alloc] initWithTitle:NSLocalizedString(@"Pages", @"Noun. Title. Links to the blog's Pages screen.") - accessibilityIdentifier:@"Site Pages Row" - image:[UIImage gridiconOfType:GridiconTypePages] - callback:^{ - [weakSelf showPageListFromSource:BlogDetailsNavigationSourceRow]; - }]; - pagesRow.quickStartIdentifier = QuickStartTourElementPages; - [rows addObject:pagesRow]; + if ([self.blog supports:BlogFeaturePages]) { + BlogDetailsRow *pagesRow = [[BlogDetailsRow alloc] initWithTitle:NSLocalizedString(@"Pages", @"Noun. Title. Links to the blog's Pages screen.") + accessibilityIdentifier:@"Site Pages Row" + image:[UIImage gridiconOfType:GridiconTypePages] + callback:^{ + [weakSelf showPageListFromSource:BlogDetailsNavigationSourceRow]; + }]; + pagesRow.quickStartIdentifier = QuickStartTourElementPages; + [rows addObject:pagesRow]; + } BlogDetailsRow *commentsRow = [[BlogDetailsRow alloc] initWithTitle:NSLocalizedString(@"Comments", @"Noun. Title. Links to the blog's Comments screen.") image:[[UIImage gridiconOfType:GridiconTypeComment] imageFlippedForRightToLeftLayoutDirection]