-
Notifications
You must be signed in to change notification settings - Fork 56
plg_groups_members: order member roles and save canned deny replies #1928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.4-main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
| /** | ||
| * @package hubzero-cms | ||
| * @copyright Copyright (c) 2005-2026 The Regents of the University of California. | ||
| * @license http://opensource.org/licenses/MIT MIT | ||
| */ | ||
|
|
||
| use Hubzero\Content\Migration\Base; | ||
|
|
||
| // No direct access | ||
| defined('_HZEXEC_') or die(); | ||
|
|
||
| /** | ||
| * Migration script for manager-ordered group member roles | ||
| * | ||
| * Every existing role starts at 0, so a group that has never been reordered | ||
| * keeps listing its roles by name. | ||
| **/ | ||
| class Migration20260915000000ComGroups extends Base | ||
| { | ||
| /** | ||
| * Up | ||
| **/ | ||
| public function up() | ||
| { | ||
| if ($this->db->tableExists('#__xgroups_roles') | ||
| && !$this->db->tableHasField('#__xgroups_roles', 'ordering')) | ||
| { | ||
| $query = "ALTER TABLE `#__xgroups_roles` | ||
| ADD COLUMN `ordering` int(11) NOT NULL DEFAULT 0 AFTER `name`"; | ||
| $this->db->setQuery($query); | ||
| $this->db->query(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Down | ||
| **/ | ||
| public function down() | ||
| { | ||
| if ($this->db->tableExists('#__xgroups_roles') | ||
| && $this->db->tableHasField('#__xgroups_roles', 'ordering')) | ||
| { | ||
| $query = "ALTER TABLE `#__xgroups_roles` DROP COLUMN `ordering`"; | ||
| $this->db->setQuery($query); | ||
| $this->db->query(); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,6 +93,19 @@ public function save() | |
| $this->set('permissions', json_encode($this->get('permissions'))); | ||
| } | ||
|
|
||
| // A new role goes to the end of its group's list rather than jumping | ||
| // ahead of roles a manager has already put in order | ||
| if ($this->isNew() && !$this->get('ordering')) | ||
| { | ||
| $last = self::blank() | ||
| ->whereEquals('gidNumber', (int) $this->get('gidNumber')) | ||
| ->order('ordering', 'desc') | ||
| ->limit(1) | ||
| ->row(); | ||
|
|
||
| $this->set('ordering', (int) $last->get('ordering') + 1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Severity: low — this breaks the "roles list by name until a manager sorts them" promise the migration docblock makes, the first time a role is added. After the migration every role sits at The method comment says a new role should not jump ahead of "roles a manager has already put in order" — in a group where nothing has been ordered there is no arranged list to protect. Only appending when the group actually has an order satisfies both intents: $last = self::blank()
->whereEquals('gidNumber', (int) $this->get('gidNumber'))
->order('ordering', 'desc')
->limit(1)
->row();
// A group whose roles have never been ordered keeps listing by name
$this->set('ordering', ((int) $last->get('ordering') > 0)
? (int) $last->get('ordering') + 1
: 0);Flagging rather than asserting — if new-roles-always-last is the deliberate choice, then the migration docblock is the thing that needs rewording. |
||
| } | ||
|
|
||
| return parent::save(); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Severity: low — the matching column is missing from
core/bootstrap/Install/sql/mysql/schema.sql, which still declares#__xgroups_rolesas(id, gidNumber, name, permissions)(around line 5954).That file is the canonical fresh-install schema, and the convention in this tree is to change both: the sibling feature in the same area (45f83df, PR #1915) shipped
Migration20260810000000ComGroups.phpand aschema.sqlupdate in the same commit. Leaving it out means the file no longer describes a current database, so anything that builds or diffs a schema straight from it (test fixtures, a restored baseline, the next regeneration) is missingordering, and every query added by this PR —getRoles(), the per-member query inviews/browse/tmpl/default.php, andplg_groups_messages— is a fatalUnknown column 'ordering'until the migration runs against it.Adding
`ordering` int(11) NOT NULL DEFAULT 0after`name`inschema.sqlkeeps the two in step.