fix #34 (default role overides role assignment at times)

This commit is contained in:
Josh Panter 2021-12-28 19:51:25 -05:00
parent 475417ff91
commit ff31aff5c2
No known key found for this signature in database
GPG Key ID: 59903022E9AC64FC
2 changed files with 27 additions and 11 deletions

View File

@ -27,6 +27,7 @@ Installation
1. Copy the `authMgrPlus` folder into your `user/plugins` folder for YOURLS. 1. Copy the `authMgrPlus` folder into your `user/plugins` folder for YOURLS.
1. Set up some parameters for authMgrPlus (details below) 1. Set up some parameters for authMgrPlus (details below)
1. Activate the plugin with the plugin manager in the YOURLS admin interface. 1. Activate the plugin with the plugin manager in the YOURLS admin interface.
1. If you have pre-existing links in your database, you will have to manually asign them a user via an sql querry.
Default Roles Default Roles
------------- -------------

View File

@ -268,11 +268,14 @@ function amp_have_capability( $capability ) {
// List capabilities of particular user role // List capabilities of particular user role
$user = defined('YOURLS_USER') ? YOURLS_USER : NULL; $user = defined('YOURLS_USER') ? YOURLS_USER : NULL;
$user_caps = array(); $user_caps = array();
foreach ( $amp_role_capabilities as $rolename => $rolecaps ) { if ( amp_user_is_assigned ( $user ) )
if ( amp_user_has_role( $user, $rolename ) ) { foreach ( $amp_role_capabilities as $rolename => $rolecaps )
if ( amp_user_has_role( $user, $rolename ) )
$user_caps = array_merge( $user_caps, $rolecaps ); $user_caps = array_merge( $user_caps, $rolecaps );
}
} elseif ( isset( $amp_default_role ) && in_array ($amp_default_role, array_keys( $amp_role_capabilities ) ) )
$user_caps = $amp_role_capabilities [ $amp_default_role ];
$user_caps = array_unique( $user_caps ); $user_caps = array_unique( $user_caps );
// Is the requested capability in this list? // Is the requested capability in this list?
$return = in_array( $capability, $user_caps ); $return = in_array( $capability, $user_caps );
@ -287,11 +290,23 @@ function amp_have_capability( $capability ) {
break; break;
} }
} }
if( !$return ) {
if ( isset( $amp_default_role ) && in_array ($amp_default_role, array_keys( $amp_role_capabilities ) ) ) { return $return;
$default_caps = $amp_role_capabilities [ $amp_default_role ]; }
$return = in_array( $capability, $default_caps );
} // Determine if a user has been assigned a role
function amp_user_is_assigned ( $username ) {
global $amp_role_assignment;
if ( empty( $amp_role_assignment ) )
return false;
$return = false;
foreach ( $amp_role_assignment as $role )
if ( in_array( $username, $role ) ) {
$return = true;
break;
} }
return $return; return $return;
} }