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
1=== modified file 'openid-teams.php'
2--- openid-teams.php 2010-04-27 09:43:42 +0000
3+++ openid-teams.php 2011-07-29 16:33:29 +0000
4@@ -545,7 +545,6 @@
5 * @param string $identity_url
6 */
7 function openid_teams_finish_auth($identity_url) {
8- global $openid_teams;
9 set_include_path(dirname(__FILE__).'/../openid/' . PATH_SEPARATOR .
10 get_include_path());
11 require_once 'teams-extension.php';
12@@ -557,7 +556,10 @@
13 $raw_teams = $teams_resp->getTeams();
14 $endpoint = $response->endpoint;
15 $openid_teams = get_approved_team_mappings($raw_teams, $endpoint->server_url);
16+ $_SESSION['openid_teams'] = $openid_teams;
17+ $_SESSION['openid_identity_url'] = $identity_url;
18
19+ # If restricted teams is enabled, check the list against allowed teams
20 if (openid_teams_is_restricted_access_enabled()) {
21 $teams = openid_teams_get_restricted_teams();
22 $teams = array_merge($teams, get_all_local_teams());
23@@ -579,20 +581,30 @@
24 * @param string $password (Default '')
25 */
26 function openid_teams_assign_on_login($username, $password='') {
27- global $openid_teams;
28- $user = restore_old_roles(new WP_User($username));
29- if ($openid_teams) {
30- $existing_roles = array_keys($user->caps);
31- $openid_assigned_roles = array();
32- $all_teams = openid_teams_get_trust_list();
33- foreach ($openid_teams as $id) {
34- $role = $all_teams[$id]->role;
35- if (!in_array($role, $existing_roles) && !isset($user->caps[$role])) {
36- $user->add_role($role);
37- $openid_assigned_roles[] = $role;
38+ session_start();
39+ $identity_url = $_SESSION['openid_identity_url'];
40+ if (is_numeric($identity_url)) {
41+ $user_id = $identity_url;
42+ } else {
43+ $user_id = get_user_by_openid($identity_url);
44+ }
45+ $openid_teams = $_SESSION['openid_teams'];
46+ if ($user_id) {
47+ $user = new WP_User($user_id);
48+ $user = restore_old_roles($user);
49+ if ($user && $openid_teams) {
50+ $existing_roles = array_keys($user->caps);
51+ $openid_assigned_roles = array();
52+ $all_teams = openid_teams_get_trust_list();
53+ foreach ($openid_teams as $id) {
54+ $role = $all_teams[$id]->role;
55+ if (!in_array($role, $existing_roles) && !isset($user->caps[$role])) {
56+ $user->add_role($role);
57+ $openid_assigned_roles[] = $role;
58+ }
59+ }
60+ update_usermeta($user->ID, 'openid_assigned_roles', $openid_assigned_roles);
61 }
62- }
63- update_usermeta($user->ID, 'openid_assigned_roles', $openid_assigned_roles);
64 }
65 }
66

Subscribers

People subscribed via source and target branches