forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp#5504 Add 'permit settings' flag on user groups
- Loading branch information
Showing
27 changed files
with
281 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
classes/migration/upgrade/v3_5_0/I5504_UserGroupsSettings.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/migration/upgrade/v3_5_0/I5504_UserGroupsSettings.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class I5504_UserGroupsSettings | ||
* | ||
* @brief Add permit_settings column to the user_groups table. | ||
*/ | ||
|
||
namespace PKP\migration\upgrade\v3_5_0; | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
use PKP\migration\Migration; | ||
|
||
class I5504_UserGroupsSettings extends Migration | ||
{ | ||
/** | ||
* Run the migration. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('user_groups', function (Blueprint $table) { | ||
$table->smallInteger('permit_settings')->default(0); | ||
}); | ||
DB::table('user_groups')->where('role_id', 1)->update(['permit_settings' => 1]); // role_id = 1 is ROLE_ID_SITE_ADMIN | ||
DB::table('user_groups')->where('role_id', 16)->update(['permit_settings' => 1]); // role_id = 16 is ROLE_ID_MANAGER | ||
} | ||
|
||
/** | ||
* Reverse the downgrades | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('user_groups', function (Blueprint $table) { | ||
if (Schema::hasColumn($table->getTable(), 'permit_settings')) { | ||
$table->dropColumn('permit_settings'); | ||
}; | ||
}); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
classes/security/authorization/CanAccessSettingsPolicy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* @file classes/security/authorization/CanAccessSettingsPolicy.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class CanAccessSettingsPolicy | ||
* | ||
* @brief Check to ensure that the user has access to the context settings area. | ||
*/ | ||
|
||
namespace PKP\security\authorization; | ||
|
||
use APP\core\Application; | ||
use PKP\security\Role; | ||
|
||
class CanAccessSettingsPolicy extends AuthorizationPolicy | ||
{ | ||
// | ||
// Implement template methods from AuthorizationPolicy | ||
// | ||
/** | ||
* @see AuthorizationPolicy::effect() | ||
*/ | ||
public function effect() | ||
{ | ||
// At least one user group must be an admin, or a manager with setup access. | ||
$userGroups = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_USER_GROUP); | ||
foreach ($userGroups as $userGroup) { | ||
if ($userGroup->getRoleId() == ROLE_ID_SITE_ADMIN) { | ||
return AuthorizationPolicy::AUTHORIZATION_PERMIT; | ||
} | ||
if ($userGroup->getRoleId() == Role::ROLE_ID_MANAGER && $userGroup->getPermitSettings()) { | ||
return AuthorizationPolicy::AUTHORIZATION_PERMIT; | ||
} | ||
} | ||
|
||
return AuthorizationPolicy::AUTHORIZATION_DENY; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.