Short Description
Forcing the user to choose one role after login, and led to other roles
does not work. User can switch role anytime just visit select_role/landing.
Description
This module is useful if your site have differences significantly related
layout and menu item on each role.
For example, you have a website of journal system, which has roles: author,
editor, and reviewer. Sometimes there is one user who has three roles at once.
If that user login, you want that user has to choose one role only. As soon as
the user login, the user must choose one role. After one role is selected,
then other roles will be removed for a while. So, if he/she selects a role as
an author, then the permission and access at the time he role as a reviewer
will not work.
This module uses hook_boot to remove unused roles from $GLOBALS['user']->roles.
Steps to test this module
- Login as user#1, then make roles: author, editor, reviewer, lecturer, student, administrator, and reader.
- Visit: admin/config/people/select_role, then check for author, editor, and reviewer, then save.
- Create one user called desi. give her role of author and reviewer. Save.
- Give access to the role author which can create article.
- Give access to the role reviewer which can create basic page.
- Logout from user#1, and login as desi. Now you will see the effect of this module. Visit node/add
Project Sandbox link
https://www.drupal.org/sandbox/m_roji28/2330439
http://git.drupal.org/sandbox/m_roji28/2330439.git
Git clone link
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/m_roji28/2330439.git select_role
Pareview.sh passed
http://pareview.sh/pareview/httpgitdrupalorgsandboxmroji282330439git
My Background
Drupal Developer in Universitas Indonesia. Build some website using Drupal.
- Active maintener at http://sirip.ui.ac.id
- Active maintener at http://staff.ui.ac.id
Comments
Comment #1
PA robot CreditAttribution: PA robot commentedWe are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)
Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).
I'm a robot and this is an automated message from Project Applications Scraper.
Comment #2
ijortengab CreditAttribution: ijortengab commentedComment #3
rajesh.vishwakarma CreditAttribution: rajesh.vishwakarma commentedManual Review
The starred items (*) are fairly big issues and warrant going back to Needs Work. Items marked with a plus sign (+) are important and should be addressed before a stable project release. The rest of the comments in the code walkthrough are recommendations.
Comment #4
ijortengab CreditAttribution: ijortengab commentedComment #5
ijortengab CreditAttribution: ijortengab commentedComment #6
ijortengab CreditAttribution: ijortengab commentedthx rajesh.vishwakarma,
i've update README, then i hope clear about goal of this module.
also add hook_help
Comment #7
ijortengab CreditAttribution: ijortengab commentedComment #8
pkamerakodi CreditAttribution: pkamerakodi commentedThanks for your contribution. Please find some review notes from my review.
1) delete the schema in unistall
2) updated the below code in select_role_boot
if (isset($_SESSION['select_role'])) {
if (!empty($_SESSION['select_role']['role_removed'])) {
global $user;
foreach ($_SESSION['select_role']['role_removed'] as $rid => $label) {
unset($user->roles[$rid]);
}
}
}
to
if (!empty($_SESSION['select_role']['role_removed'])) {
global $user;
foreach ($_SESSION['select_role']['role_removed'] as $rid => $label) {
unset($user->roles[$rid]);
}
}
3) I am really not sure if its a good practice to place html tags within t function, it actually takes out the purpose of translation function
Your current role now set to @role
4) In hook_permission as per drupal convention change the key to administer select role
5) For checking if user is anonymouse use
https://api.drupal.org/api/drupal/modules!user!user.module/function/user...
6) Call user_roles(TRUE) so it doesnot return you annon user role
Regards,
Prajwal
Comment #9
pkamerakodi CreditAttribution: pkamerakodi commentedComment #10
ijortengab CreditAttribution: ijortengab commented@pkamerakodi, thx for review
1) hook_schema don't need uninstall, it's automatically.
2) OK, changed
3) I think it's not problem
4) OK, changed
5) OK, changed
6) OK, changed
Comment #11
ijortengab CreditAttribution: ijortengab commentedComment #12
ijortengab CreditAttribution: ijortengab commentedComment #13
gaurav.pahuja CreditAttribution: gaurav.pahuja commentedHi Ijor,
It seems you are giving logged in user option to change role at anytime but there is no interface for that.
I gave two roles to a user i.e Administrator and editor. At time of login i was asked to choose a role.
I chose editor and then landed to homepage.
Now I directly went to 'select_role/landing' and selected as administrator and role is assigned to me.
Menu Callback:
Is this a expected functionality? If yes, there must be some way for a user to interchange roles.
My initial understanding was that user is not allowed to change role once logged in.
Comment #14
gaurav.pahuja CreditAttribution: gaurav.pahuja commentedCouple of more feedback points:
Unused $user variable on line # 103
Also I was not able to understand how you are using function
select_role_form_user_profile_form_alter
Can you please brief me more on usage of this function? I may be missing something.
Comment #15
gaurav.pahuja CreditAttribution: gaurav.pahuja commentedComment #16
ijortengab CreditAttribution: ijortengab commentedthx for reviewing it.
1. sorry for incomplete information, i expect user can switch to other role,
prevent troublesome users. i think it's a waste of time if the user must relogin to
switch role. I've update issue summary.
2. remove unused $user. thx.
3. about select_role_form_user_profile_form_alter().
3.1. i've add extra information above: Provide extra fields to give the select roles to certain users.
3.2. i've add extra #description: Select roles that will be selected by this user. This configuration effected for this user only. Leave blank to use !url.
Comment #17
ijortengab CreditAttribution: ijortengab commentedComment #18
naveenvalechaHi @ijortengab,
Thanks for your contribution.
Automated Review
Best practice issues identified by pareview.sh / drupalcs / coder. are passed.
Manual Review
return system_settings_form($form);
insteadreturn $form;
so that the fields value(like select role field values will be stored in the variable select_role_global) automatically get stored in the variables and remove the submit handler easily.global $user; <code> in place of <code>$user = $GLOBALS['user'];
This review uses the Project Application Review Template.
As I am not a git administrator, so I would recommend you, please help to review other project applications to get a review bonus. This will put you on the high priority list, then git administrators will take a look at your project right away :-)
Thanks Again!
Comment #19
klausiIt is perfectly fine to use $_SESSION (that is the "API") and $GLOBALS can also be used. The other stuff mentioned in your review are minor improvements, any other application blockers that you found?
Comment #20
naveenvalecha@klausi,
Thanks, I have not found any application blocker to set this to RTBC.Setting this to RTBC.
@ijortengab,
Please do the following minor coding style changes(#2,#3) as mentioned in #18. Regarding #1 and #4 we can directly use them as @kalusi mentioned in #19
please review 2 other project applications to get a review bonus as you have already reviewed 1 other project application. This will put you on the high priority list, then git administrators will take a look at your project right away :-)
Thanks Again!
Comment #21
naveenvalechaChanged status.
Comment #22
naveenvalecha@ijortengab,
As I did not find any release blocker in the module last time.To make this module publish just address the #18 and get a review bonus as you have already reviewed 1 other project application. This will put you on the high priority list, then git administrators will take a look at your project right away :-)
Comment #23
ijortengab CreditAttribution: ijortengab commentedthx @naveenvalecha and @klausi, for your review.
sory for delayed update..
About of review other project, I'll do it soon to .
Comment #24
ijortengab CreditAttribution: ijortengab commentedComment #25
klausiReview of the 7.x-1.x branch (commit 40abe1e):
This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. You have to get a review bonus to get a review from me.
manual review:
But otherwise looks good to me, so ...
Thanks for your contribution, ijortengab!
I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
Thanks to the dedicated reviewer(s) as well.
Comment #26
ijortengab CreditAttribution: ijortengab commentedI've updated code to add t().
Thx @klausi, @naveenvalecha, and all reviewers for reviewing this module.
Kind regards,
@ijortengab