Skip to content

Commit

Permalink
Change ‘can set password’ from threshold to bool
Browse files Browse the repository at this point in the history
Since it now applies to a specific user or a default, use bool instead
of threshold.
  • Loading branch information
vboctor committed Apr 16, 2017
1 parent 6935b44 commit 7ac97ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
9 changes: 2 additions & 7 deletions core/authentication_api.php
Expand Up @@ -267,14 +267,9 @@ function auth_logout_redirect_page() {
* @return bool true: can set password, false: otherwise.
*/
function auth_can_set_password( $p_user_id = null ) {
$t_auth_flags = auth_flags();

# If it is a signup scenario and user is not authenticated, return false.
if( $p_user_id == NO_USER ) {
return $t_auth_flags->getSetPasswordThreshold() === ANYBODY;
}
$t_auth_flags = auth_flags( $p_user_id );

if( !access_has_global_level( $t_auth_flags->getSetPasswordThreshold(), $p_user_id ) ) {
if( !$t_auth_flags->getCanSetPassword() ) {
return false;
}

Expand Down
18 changes: 7 additions & 11 deletions core/classes/AuthFlags.class.php
Expand Up @@ -37,10 +37,10 @@
*/
class AuthFlags {
/**
* The access level or array of access levels that can leverage MantisBT native passwords.
* @var int|array|null
* Indicates whether the user can set their password within MantisBT or not.
* @var bool|null
*/
private $access_level_set_password = null;
private $can_set_password = null;

/**
* The message to display indicating that passwords are not managed by MantisBT native passwords.
Expand Down Expand Up @@ -121,16 +121,12 @@ class AuthFlags {
function __construct() {
}

function setSetPasswordThreshold( $p_threshold ) {
$this->access_level_set_password = $p_threshold;
function setCanSetPassword( $p_enabled ) {
$this->can_set_password = $p_enabled;
}

function getSetPasswordThreshold() {
if( is_null( $this->access_level_set_password ) ) {
return ANYBODY;
}

return $this->access_level_set_password;
function getCanSetPassword() {
return is_null( $this->can_set_password ) ? true : $this->can_set_password;
}

function setPasswordManagedExternallyMessage( $p_message ) {
Expand Down

0 comments on commit 7ac97ab

Please sign in to comment.