Merge lp:~canonical-isd-hackers/wordpress-teams-integration/prevent-removing-bound-server-fix into lp:wordpress-teams-integration

Proposed by Szilveszter Farkas
Status: Merged
Approved by: Stuart Metcalfe
Approved revision: 30
Merged at revision: not available
Proposed branch: lp:~canonical-isd-hackers/wordpress-teams-integration/prevent-removing-bound-server-fix
Merge into: lp:wordpress-teams-integration
Diff against target: 76 lines (+37/-10)
1 file modified
openid-teams.php (+37/-10)
To merge this branch: bzr merge lp:~canonical-isd-hackers/wordpress-teams-integration/prevent-removing-bound-server-fix
Reviewer Review Type Date Requested Status
Stuart Metcalfe (community) Approve
Review via email: mp+24203@code.launchpad.net

Description of the change

Do not allow deleting servers if one of the selected servers are bound to an existing role.

To post a comment you must log in.
Revision history for this message
Stuart Metcalfe (stuartmetcalfe) wrote :

Everything in rev. 27 looks good so far. We discussed removing the 'delete' checkbox from the servers form for each server already assigned to a team to avoid even giving the option to delete a server which the user shouldn't be able to delete. This looks possible, so will re-review when that's landed.

Revision history for this message
Stuart Metcalfe (stuartmetcalfe) wrote :

The usual exception to missing tests, for the record. This code doesn't have any unit test coverage and the app doesn't provide a framework that we're aware of so no unit test coverage is included.

28. By Szilveszter Farkas

Do not display the checkbox if cannot delete.

29. By Szilveszter Farkas

Add missing documentation.

30. By Szilveszter Farkas

Add docstring for delete_server_from_trusted().

Revision history for this message
Stuart Metcalfe (stuartmetcalfe) wrote :

With the doctest improvements discussed in IRC, which landed in rev. 30, this is approved. Good work!

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-03-02 14:45:34 +0000
3+++ openid-teams.php 2010-04-27 09:45:38 +0000
4@@ -175,20 +175,45 @@
5 }
6 }
7
8-function delete_server_from_trusted($id, $trusted_servers = null) {
9- if (is_null($trusted_servers)) {
10- $trusted_servers = openid_get_server_list();
11- }
12- unset($trusted_servers[$id]);
13- openid_teams_update_trusted_servers($trusted_servers);
14+/**
15+ * Check if given server is bound to a role
16+ *
17+ * @param int $id Internal ID of the server to be queried
18+ *
19+ * @return boolean
20+ */
21+function is_server_bound($id) {
22 $all_trust_maps = openid_teams_get_trust_list();
23+ $role_found = false;
24 foreach ($all_trust_maps as $map_id => $trust_map) {
25 if ($trust_map->server == $id) {
26- $all_trust_maps[$map_id]->server = -1;
27+ $role_found = true;
28+ break;
29 }
30 }
31- openid_teams_update_trust_list($all_trust_maps);
32-}
33+ return $role_found;
34+}
35+
36+/**
37+ * Delete given server from the list of trusted servers
38+ *
39+ * @param int $id
40+ * @param array $trusted_servers
41+ */
42+function delete_server_from_trusted($id, $trusted_servers = null) {
43+ if (is_null($trusted_servers)) {
44+ $trusted_servers = openid_get_server_list();
45+ }
46+ if (is_server_bound($id)) {
47+ print '<div id="message" class="error"><p>'.__("You cannot remove a server that has roles associated with it.").'</p></div>';
48+ } else {
49+ $all_trust_maps = openid_teams_get_trust_list();
50+ unset($trusted_servers[$id]);
51+ openid_teams_update_trusted_servers($trusted_servers);
52+ openid_teams_update_trust_list($all_trust_maps);
53+ }
54+}
55+
56 /**
57 * Get the list of trusted servers
58 *
59@@ -223,6 +248,8 @@
60 * Check if given server is on trusted server list
61 *
62 * @param string $server
63+ *
64+ * @return bool
65 */
66 function in_trusted_servers($server) {
67 foreach (openid_get_server_list() as $trusted) {
68@@ -330,7 +357,7 @@
69 ?>
70 <tr>
71 <td><?php print htmlentities($server); ?></td>
72- <td><input type="checkbox" name="delete[<?php print $id ?>]" value="1" /></td>
73+ <td style="text-align:center;"><?php if (!is_server_bound($id)): ?><input type="checkbox" name="delete[<?php print $id ?>]" value="1" /><?php else: print __("(associated with a role)"); endif; ?></td>
74 </tr>
75 <?php
76 }

Subscribers

People subscribed via source and target branches