Skip to content

Commit

Permalink
Merge pull request pkp#9603 from bozana/9552
Browse files Browse the repository at this point in the history
pkp#9552 add masthead option to user roles
  • Loading branch information
bozana authored Jan 17, 2024
2 parents bce6816 + 66004b5 commit 190f0d0
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 4 deletions.
1 change: 1 addition & 0 deletions classes/migration/install/RolesAndUserGroupsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function up(): void
$table->smallInteger('show_title')->default(1);
$table->smallInteger('permit_self_registration')->default(0);
$table->smallInteger('permit_metadata_edit')->default(0);
$table->smallInteger('masthead')->default(0);
$table->index(['user_group_id'], 'user_groups_user_group_id');
$table->index(['context_id'], 'user_groups_context_id');
$table->index(['role_id'], 'user_groups_role_id');
Expand Down
44 changes: 44 additions & 0 deletions classes/migration/upgrade/v3_5_0/I9552_UserGroupsMasthead.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* @file classes/migration/upgrade/v3_5_0/I9552_UserGroupsMasthead.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 I9552_UserGroupsMasthead
*
* @brief Add masthead column to the user_groups table.
*/

namespace PKP\migration\upgrade\v3_5_0;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use PKP\migration\Migration;

class I9552_UserGroupsMasthead extends Migration
{
/**
* Run the migration.
*/
public function up(): void
{
Schema::table('user_groups', function (Blueprint $table) {
$table->smallInteger('masthead')->default(0);
});
}

/**
* Reverse the downgrades
*/
public function down(): void
{
Schema::table('user_groups', function (Blueprint $table) {
if (Schema::hasColumn($table->getTable(), 'masthead')) {
$table->dropColumn('masthead');
};
});
}
}
17 changes: 16 additions & 1 deletion classes/userGroup/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Collector implements CollectorInterface
public const ORDERBY_ROLE_ID = 'roleId';
public const ORDERBY_ID = 'id';

public ?string $orderBy = null;
public ?string $orderBy = self::ORDERBY_ID;

/** @var DAO */
public $dao;
Expand Down Expand Up @@ -63,6 +63,8 @@ class Collector implements CollectorInterface

public UserUserGroupStatus $userUserGroupStatus = UserUserGroupStatus::STATUS_ACTIVE;

public ?bool $masthead = null;


public function __construct(DAO $dao)
{
Expand Down Expand Up @@ -173,6 +175,15 @@ public function filterByPermitMetadataEdit(?bool $permitMetadataEdit): self
return $this;
}

/**
* Filter by masthead
*/
public function filterByMasthead(?bool $masthead): self
{
$this->masthead = $masthead;
return $this;
}

/**
* Filter by permit metadata edit
*/
Expand Down Expand Up @@ -304,6 +315,10 @@ public function getQueryBuilder(): Builder
$q->where('ug.permit_metadata_edit', $this->permitMetadataEdit ? 1 : 0);
});

$q->when($this->masthead !== null, function (Builder $q) {
$q->where('ug.masthead', $this->masthead ? 1 : 0);
});

$q->when($this->showTitle !== null, function (Builder $q) {
$q->where('ug.show_title', $this->showTitle ? 1 : 0);
});
Expand Down
1 change: 1 addition & 0 deletions classes/userGroup/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class DAO extends EntityDAO
'showTitle' => 'show_title',
'permitSelfRegistration' => 'permit_self_registration',
'permitMetadataEdit' => 'permit_metadata_edit',
'masthead' => 'masthead',
];

/**
Expand Down
2 changes: 2 additions & 0 deletions classes/userGroup/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ public function installSettings($contextId, $filename)
$abbrevKey = $setting->getAttribute('abbrev');
$permitSelfRegistration = $setting->getAttribute('permitSelfRegistration');
$permitMetadataEdit = $setting->getAttribute('permitMetadataEdit');
$masthead = $setting->getAttribute('masthead');

// If has manager role then permitMetadataEdit can't be overridden
if (in_array($roleId, [Role::ROLE_ID_MANAGER])) {
Expand All @@ -416,6 +417,7 @@ public function installSettings($contextId, $filename)
$userGroup->setPermitMetadataEdit($permitMetadataEdit ?? false);
$userGroup->setDefault(true);
$userGroup->setShowTitle(true);
$userGroup->setMasthead($masthead ?? false);

// insert the group into the DB
$userGroupId = $this->add($userGroup);
Expand Down
16 changes: 16 additions & 0 deletions classes/userGroup/UserGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@ public function setPermitMetadataEdit(bool $permitMetadataEdit)
{
$this->setData('permitMetadataEdit', $permitMetadataEdit);
}

/**
* Get the masthead flag
*/
public function getMasthead(): bool
{
return $this->getData('masthead');
}

/**
* Set the masthead flag
*/
public function setMasthead(bool $masthead)
{
$this->setData('masthead', $masthead);
}
}

if (!PKP_STRICT_MODE) {
Expand Down
7 changes: 4 additions & 3 deletions controllers/grid/settings/roles/form/UserGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public function initData()
'permitSelfRegistration' => $userGroup->getPermitSelfRegistration(),
'permitMetadataEdit' => $userGroup->getPermitMetadataEdit(),
'recommendOnly' => $userGroup->getRecommendOnly(),
'masthead' => $userGroup->getMasthead(),
];

foreach ($data as $field => $value) {
Expand All @@ -137,7 +138,7 @@ public function initData()
*/
public function readInputData()
{
$this->readUserVars(['roleId', 'name', 'abbrev', 'assignedStages', 'showTitle', 'permitSelfRegistration', 'recommendOnly', 'permitMetadataEdit']);
$this->readUserVars(['roleId', 'name', 'abbrev', 'assignedStages', 'showTitle', 'permitSelfRegistration', 'recommendOnly', 'permitMetadataEdit', 'masthead']);
}

/**
Expand Down Expand Up @@ -210,7 +211,7 @@ public function execute(...$functionParams)

$userGroup->setRecommendOnly($this->getData('recommendOnly') && in_array($userGroup->getRoleId(), $this->getRecommendOnlyRoles()));
$userGroup = $this->_setUserGroupLocaleFields($userGroup, $request);

$userGroup->setMasthead($this->getData('masthead') ?? false);
$userGroupId = Repo::userGroup()->add($userGroup);
} else {
$userGroup = Repo::userGroup()->get($userGroupId);
Expand All @@ -233,7 +234,7 @@ public function execute(...$functionParams)
}

$userGroup->setRecommendOnly($this->getData('recommendOnly') && in_array($userGroup->getRoleId(), $this->getRecommendOnlyRoles()));

$userGroup->setMasthead($this->getData('masthead') ?? false);
Repo::userGroup()->edit($userGroup, []);
}

Expand Down
3 changes: 3 additions & 0 deletions locale/en/manager.po
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,9 @@ msgstr "Payment Method"
msgid "manager.paymentMethod.currency"
msgstr "Currency"

msgid "settings.roles.masthead"
msgstr "Consider role in masthead list"

msgid "settings.roles.roleOptions"
msgstr "Role Options"

Expand Down
3 changes: 3 additions & 0 deletions schemas/userGroup.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"apiSummary": true,
"multilingual": true
},
"masthead": {
"type": "boolean"
},
"name": {
"type": "string",
"description": "The name of the user group.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
{fbvElement type="checkbox" name="permitSelfRegistration" id="permitSelfRegistration" checked=$permitSelfRegistration label="settings.roles.permitSelfRegistration"}
{fbvElement type="checkbox" name="recommendOnly" id="recommendOnly" checked=$recommendOnly label="settings.roles.recommendOnly"}
{fbvElement type="checkbox" name="permitMetadataEdit" id="permitMetadataEdit" checked=$permitMetadataEdit label="settings.roles.permitMetadataEdit"}
{fbvElement type="checkbox" name="masthead" id="masthead" checked=$masthead label="settings.roles.masthead"}
{/fbvFormSection}
{/fbvFormArea}
</div>
Expand Down

0 comments on commit 190f0d0

Please sign in to comment.