Skip to content
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

2840664 - Create extra user management permissions #429

Merged

Conversation

ribel
Copy link
Contributor

@ribel ribel commented Jun 15, 2017

Original PR: #427
Related issue: https://www.drupal.org/node/2840664

Summary

This PR changes some conditions for accessing 'admin/people' page by adding new permissions: 'view users', 'block users'. A user that has such permissions could view 'admin/people' page, use filters and use action 'Block the selected user(s)'.

Changes:

  1. Created custom permissions 'view users', 'block users'
  2. Added a new views access plugin to the 'admin/people' page, added conditions for checking by custom permissions.
  3. Override a block user action with the custom plugin and added here conditions for checking by custom permissions.
  4. Added update hook to set up new permissions for 'contentmanager' role.
  5. Altered 'admin/people' form to show actions based on permissions.
  6. Added Behat test 'content-manage-view-block-people-page' for testing.

HTT

There are Behat test 'content-manage-view-block-people-page.feature' for testing.

1) Create custom permissions 'view users', 'block users'
1) Added a new views access plugin to the 'admin/people' page, added conditions for checking by custom permissions.
2) Override a block user action with the custom plugin and added here conditions for checking by custom permissions.
3) Added update hook to set up new permissions for 'contentmanager' role.
4) Altered 'admin/people' form to show actions based on permissions.
5) Added Behat test 'content-manage-view-block-people-page' for testing.
…extra-user-permissions' into feature/2840664-content-managers-extra-user-permissions
@@ -36,6 +36,15 @@ function social_user_update_8001(&$sandbox) {
}

/**
* Add view, block users permissions for the content manager.
*/
function social_user_update_8002() {
Copy link
Contributor Author

@ribel ribel Jun 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@A-Kom, please also add the same permissions for sitemanager role.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ribel, this is fixed now.

@jochemvn jochemvn added the team: enterprise This PR originates from the ECI team label Jun 16, 2017
Updated hook update to set permissions to all roles.
…extra-user-permissions' into feature/2840664-content-managers-extra-user-permissions
@frankgraave frankgraave added the type: feature This PR adds a new feature to Open Social label Aug 23, 2017
@bramtenhove
Copy link
Member

@ribel, you added the duplicate label to this pull request. Should we close it? What is the status?

* Add view, block users permissions for the content,site managers.
*/
function social_user_update_8002() {
_social_user_set_permissions();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just grant the new permissions here to the role that should have them (preferably based on the permission it's splitting off from if possible). Calling this function in an update hook might reset permissions that a site-administrator or developer has changed.

e.g. if a site using Open Social has revoked the "select account cancellation method" (which should probably not be given to all users anyway?) then this update hook will grant that permission again.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @Kingdutch, yup we could update method for setting permissions. If you want - you could fix it by yourself, otherwise, I could fix it later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a friendly reminder that this still needs a little bit of work ;)

@Kingdutch
Copy link
Member

Removing the Duplicate tag as the duplicate of this (#427) has been closed unmerged.

@jochemvn
Copy link
Contributor

Had a small discussion with @jaapjan about granting these permissions to the CM. We agreed we shouldn't just give these permissions to the CM.

Also the remarks from @Kingdutch are correct. So as far as I can see we need to change the following:

  1. Remove the 'view users' and 'block users' permission from the CM and only grant them to the SM
  2. On install granting all permissions is fine, but in the update hook only grant the 2 selected permissions to the SM
  3. Change the supplied behat test

If there's the need in some project to grant these permissions to the CM, please do that in these projects, but not in the distro.

@jochemvn jochemvn added the status: needs work This PR needs work done before it can be reviewed (again) and merged label Oct 17, 2017
@ribel ribel added team: external This PR originates from an external contributor and removed team: enterprise This PR originates from the ECI team labels Oct 18, 2017
@bramtenhove
Copy link
Member

@ribel @andrii-khomych-lemberg-co-uk could one of you make the changes to the pull request as suggested in @jochemvn's comment?

@ribel ribel removed the status: needs work This PR needs work done before it can be reviewed (again) and merged label Nov 10, 2017
@jochemvn jochemvn self-requested a review December 4, 2017 14:10
@jochemvn
Copy link
Contributor

jochemvn commented Dec 4, 2017

Works as described. Can be merged when the tests are 'green'

@jochemvn jochemvn changed the title Issue #2840664 by Andriy Khomych: Create extra user management permissions for Content Managers 2840664 - Create extra user management permissions for Content Managers Dec 4, 2017
@jochemvn jochemvn changed the title 2840664 - Create extra user management permissions for Content Managers 2840664 - Create extra user management permissions Dec 4, 2017
@jochemvn jochemvn added this to the 1.8 Release milestone Dec 4, 2017
@Kingdutch
Copy link
Member

I think the revised update hook does what it's supposed to. However, I think in the future we should try less to write 'clean code' vs more stable code. What I mean with this:

Prefer:

function update_hook_N() {
   $new_permissions = ['some_permission'];
   drupal_grant_permissions('some_role', $new_permissions);
}

Over:

function update_hook_N() {
  $new_permissions = some_permission_function('some_role');
  drupal_grant_permissions('some_role', $new_permissions);
}

The motivation for this is that the contents of some_permission_function will change in the project lifetime to reflect the permissions granted to roles at installation time. This means that if these permissions change and you want to know what update_hook_N did in a few months time, it will no longer be accurate (which means that updating from 1.0 to 1.1 can be different than from 1.0 to 1.5). This is dangerous.

We should strive for update hooks to be deterministic.

It leads to slightly more lines of code but the upgrade path will be easier to reason about, now and in the future.

@jochemvn jochemvn merged commit 0446b80 into 8.x-1.x Dec 5, 2017
@jochemvn jochemvn deleted the feature/2840664-content-managers-extra-user-permissions branch December 5, 2017 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team: external This PR originates from an external contributor type: feature This PR adds a new feature to Open Social
8 participants