Skip to content

Commit

Permalink
Hide Pages menu for users with insufficient roles
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdchr committed Mar 9, 2023
1 parent 373c9a1 commit 6c170b3
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 6c170b3

Please sign in to comment.