Skip to content

Commit

Permalink
Dont show stats module on my Jetpack if user does not have permissions (
Browse files Browse the repository at this point in the history
#41445)

* Dont show stats module on my Jetpack if user does not have permissions to see it

* a few small updates to stats permission check
  • Loading branch information
jboland88 authored Jan 31, 2025
1 parent c8023b1 commit 2f12118
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ const ProductCardsSection: FC< ProductCardsSectionProps > = ( { noticeMessage }
data: { ownedProducts, unownedProducts },
} = useProductsByOwnership();

const { canUserViewStats } = getMyJetpackWindowInitialState();

const unownedSectionTitle = useMemo( () => {
return ownedProducts.length > 0
? __( 'Discover more', 'jetpack-my-jetpack' )
Expand All @@ -117,11 +119,12 @@ const ProductCardsSection: FC< ProductCardsSectionProps > = ( { noticeMessage }

const filterProducts = ( products: JetpackModule[] ) => {
const productsWithNoCard = [ 'scan', 'security', 'growth', 'extras', 'complete' ];
// If the user cannot view stats, filter out the stats card
if ( ! canUserViewStats ) {
productsWithNoCard.push( 'stats' );
}
return products.filter( product => {
if ( productsWithNoCard.includes( product ) ) {
return false;
}
return true;
return ! productsWithNoCard.includes( product );
} );
};

Expand Down
1 change: 1 addition & 0 deletions projects/packages/my-jetpack/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ interface Window {
blogID: string;
fileSystemWriteAccess: 'yes' | 'no';
isStatsModuleActive: string;
canUserViewStats: boolean;
isUserFromKnownHost: string;
jetpackManage: {
isAgencyAccount: boolean;
Expand Down
1 change: 1 addition & 0 deletions projects/packages/my-jetpack/src/class-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public static function enqueue_scripts() {
'dismissed' => \Jetpack_Options::get_option( 'dismissed_recommendations', false ),
),
'isStatsModuleActive' => $modules->is_active( 'stats' ),
'canUserViewStats' => current_user_can( 'manage_options' ) || current_user_can( 'view_stats' ),
'isUserFromKnownHost' => self::is_user_from_known_host(),
'isCommercial' => self::is_commercial_site(),
'sandboxedDomain' => $sandboxed_domain,
Expand Down

0 comments on commit 2f12118

Please sign in to comment.