Merge lp:~mhall119/wordpress-teams-integration/fix-role-assignment into lp:wordpress-teams-integration

Proposed by Michael Hall
Status: Merged
Approved by: Michael Hall
Approved revision: 29
Merged at revision: 28
Proposed branch: lp:~mhall119/wordpress-teams-integration/fix-role-assignment
Merge into: lp:wordpress-teams-integration
Diff against target: 65 lines (+26/-14)
1 file modified
openid-teams.php (+26/-14)
To merge this branch: bzr merge lp:~mhall119/wordpress-teams-integration/fix-role-assignment
Reviewer Review Type Date Requested Status
Danny Tamez (community) Approve
Matthew Nuzum (community) Approve
Review via email: mp+69831@code.launchpad.net

Commit message

Pass user identity and team membership information on the session between the openid callback and the login callback

Description of the change

Overview
========
The mapping between LP Teams and WP Roles was not being set at user login

Details
=======
User and team information was being lost between callback requests, they need to be stored in the user's session.

To post a comment you must log in.
Revision history for this message
Matthew Nuzum (newz) wrote :

Looks good. Tested both with and without authorized team access and it authenticated properly with the right team mapping and failed to authenticate when the proper team mapping was missing.

review: Approve
Revision history for this message
Danny Tamez (zematynnad) wrote :

Looks fine - just the comments from IRC.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openid-teams.php'
--- openid-teams.php 2010-04-27 09:43:42 +0000
+++ openid-teams.php 2011-07-29 16:33:29 +0000
@@ -545,7 +545,6 @@
545 * @param string $identity_url545 * @param string $identity_url
546 */546 */
547function openid_teams_finish_auth($identity_url) {547function openid_teams_finish_auth($identity_url) {
548 global $openid_teams;
549 set_include_path(dirname(__FILE__).'/../openid/' . PATH_SEPARATOR .548 set_include_path(dirname(__FILE__).'/../openid/' . PATH_SEPARATOR .
550 get_include_path());549 get_include_path());
551 require_once 'teams-extension.php';550 require_once 'teams-extension.php';
@@ -557,7 +556,10 @@
557 $raw_teams = $teams_resp->getTeams();556 $raw_teams = $teams_resp->getTeams();
558 $endpoint = $response->endpoint;557 $endpoint = $response->endpoint;
559 $openid_teams = get_approved_team_mappings($raw_teams, $endpoint->server_url);558 $openid_teams = get_approved_team_mappings($raw_teams, $endpoint->server_url);
559 $_SESSION['openid_teams'] = $openid_teams;
560 $_SESSION['openid_identity_url'] = $identity_url;
560561
562 # If restricted teams is enabled, check the list against allowed teams
561 if (openid_teams_is_restricted_access_enabled()) {563 if (openid_teams_is_restricted_access_enabled()) {
562 $teams = openid_teams_get_restricted_teams();564 $teams = openid_teams_get_restricted_teams();
563 $teams = array_merge($teams, get_all_local_teams());565 $teams = array_merge($teams, get_all_local_teams());
@@ -579,20 +581,30 @@
579 * @param string $password (Default '')581 * @param string $password (Default '')
580 */582 */
581function openid_teams_assign_on_login($username, $password='') {583function openid_teams_assign_on_login($username, $password='') {
582 global $openid_teams;584 session_start();
583 $user = restore_old_roles(new WP_User($username));585 $identity_url = $_SESSION['openid_identity_url'];
584 if ($openid_teams) {586 if (is_numeric($identity_url)) {
585 $existing_roles = array_keys($user->caps);587 $user_id = $identity_url;
586 $openid_assigned_roles = array();588 } else {
587 $all_teams = openid_teams_get_trust_list();589 $user_id = get_user_by_openid($identity_url);
588 foreach ($openid_teams as $id) {590 }
589 $role = $all_teams[$id]->role;591 $openid_teams = $_SESSION['openid_teams'];
590 if (!in_array($role, $existing_roles) && !isset($user->caps[$role])) {592 if ($user_id) {
591 $user->add_role($role);593 $user = new WP_User($user_id);
592 $openid_assigned_roles[] = $role;594 $user = restore_old_roles($user);
595 if ($user && $openid_teams) {
596 $existing_roles = array_keys($user->caps);
597 $openid_assigned_roles = array();
598 $all_teams = openid_teams_get_trust_list();
599 foreach ($openid_teams as $id) {
600 $role = $all_teams[$id]->role;
601 if (!in_array($role, $existing_roles) && !isset($user->caps[$role])) {
602 $user->add_role($role);
603 $openid_assigned_roles[] = $role;
604 }
605 }
606 update_usermeta($user->ID, 'openid_assigned_roles', $openid_assigned_roles);
593 }607 }
594 }
595 update_usermeta($user->ID, 'openid_assigned_roles', $openid_assigned_roles);
596 }608 }
597}609}
598610

Subscribers

People subscribed via source and target branches