Skip to content

Commit

Permalink
fix joshp23#34 (default role overides role assignment at times)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshp23 committed Dec 29, 2021
1 parent 475417f commit ff31aff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Installation
1. Copy the `authMgrPlus` folder into your `user/plugins` folder for YOURLS.
1. Set up some parameters for authMgrPlus (details below)
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
-------------
Expand Down
37 changes: 26 additions & 11 deletions authMgrPlus/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,14 @@ function amp_have_capability( $capability ) {
// List capabilities of particular user role
$user = defined('YOURLS_USER') ? YOURLS_USER : NULL;
$user_caps = array();
foreach ( $amp_role_capabilities as $rolename => $rolecaps ) {
if ( amp_user_has_role( $user, $rolename ) ) {
$user_caps = array_merge( $user_caps, $rolecaps );
}
}
if ( amp_user_is_assigned ( $user ) )
foreach ( $amp_role_capabilities as $rolename => $rolecaps )
if ( amp_user_has_role( $user, $rolename ) )
$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 );
// Is the requested capability in this list?
$return = in_array( $capability, $user_caps );
Expand All @@ -287,15 +290,27 @@ function amp_have_capability( $capability ) {
break;
}
}
if( !$return ) {
if ( isset( $amp_default_role ) && in_array ($amp_default_role, array_keys( $amp_role_capabilities ) ) ) {
$default_caps = $amp_role_capabilities [ $amp_default_role ];
$return = in_array( $capability, $default_caps );
}
}

return $return;
}

// 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;
}

// Determine whether a specific user has a role.
function amp_user_has_role( $username, $rolename ) {

Expand Down

0 comments on commit ff31aff

Please sign in to comment.