Skip to content

Commit

Permalink
Merge pull request #20287 from wordpress-mobile/issue/19885-hide-page…
Browse files Browse the repository at this point in the history
…s-for-insufficient-roles

Fix: Hide Pages menu for users with insufficient roles
  • Loading branch information
dvdchr authored Mar 13, 2023
2 parents 28ebe98 + 6c170b3 commit cf7dfb0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions WordPress/Classes/Models/Blog+Capabilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion WordPress/Classes/Models/Blog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions WordPress/Classes/Models/Blog.m
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ - (BOOL)supports:(BlogFeature)feature
return [self isHostedAtWPcom];
case BlogFeatureBlaze:
return [self isBlazeApproved];
case BlogFeaturePages:
return [self isListingPagesAllowed];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit cf7dfb0

Please sign in to comment.