Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For super admins with no role set, treat them as administrators #689

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions includes/Classifai/Admin/UserProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,19 @@ public function get_allowed_features( int $user_id ): array {

// Check if user has access to the feature by role.
$allowed_roles = $settings['roles'] ?? [];
if (
$role_based_access_enabled &&
! empty( $allowed_roles ) &&
! empty( array_intersect( $user_roles, $allowed_roles ) )
) {
$allowed_features[ $feature_class::ID ] = $feature_class->get_label();
continue;
if ( $role_based_access_enabled ) {
// For super admins that don't have a specific role on a site, treat them as admins.
if ( is_multisite() && is_super_admin( $user_id ) && empty( $user_roles ) ) {
$user_roles = [ 'administrator' ];
}

if (
! empty( $allowed_roles ) &&
! empty( array_intersect( $user_roles, $allowed_roles ) )
) {
$allowed_features[ $feature_class::ID ] = $feature_class->get_label();
continue;
}
}

// Check if user has access to the feature.
Expand Down
5 changes: 5 additions & 0 deletions includes/Classifai/Features/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,11 @@ public function has_access(): bool {
* Checks if Role-based access is enabled and user role has access to the feature.
*/
if ( $role_based_access_enabled ) {
// For super admins that don't have a specific role on a site, treat them as admins.
if ( is_multisite() && is_super_admin( $user_id ) && empty( $user_roles ) ) {
$user_roles = [ 'administrator' ];
}

$access = ( ! empty( $feature_roles ) && ! empty( array_intersect( $user_roles, $feature_roles ) ) );
}

Expand Down
Loading