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
=== modified file 'openid-teams.php'
--- openid-teams.php 2010-03-02 14:45:34 +0000
+++ openid-teams.php 2010-04-27 09:45:38 +0000
@@ -175,20 +175,45 @@
175 }175 }
176}176}
177177
178function delete_server_from_trusted($id, $trusted_servers = null) {178/**
179 if (is_null($trusted_servers)) {179 * Check if given server is bound to a role
180 $trusted_servers = openid_get_server_list();180 *
181 }181 * @param int $id Internal ID of the server to be queried
182 unset($trusted_servers[$id]);182 *
183 openid_teams_update_trusted_servers($trusted_servers);183 * @return boolean
184 */
185function is_server_bound($id) {
184 $all_trust_maps = openid_teams_get_trust_list();186 $all_trust_maps = openid_teams_get_trust_list();
187 $role_found = false;
185 foreach ($all_trust_maps as $map_id => $trust_map) {188 foreach ($all_trust_maps as $map_id => $trust_map) {
186 if ($trust_map->server == $id) {189 if ($trust_map->server == $id) {
187 $all_trust_maps[$map_id]->server = -1;190 $role_found = true;
191 break;
188 }192 }
189 }193 }
190 openid_teams_update_trust_list($all_trust_maps);194 return $role_found;
191}195}
196
197/**
198 * Delete given server from the list of trusted servers
199 *
200 * @param int $id
201 * @param array $trusted_servers
202 */
203function delete_server_from_trusted($id, $trusted_servers = null) {
204 if (is_null($trusted_servers)) {
205 $trusted_servers = openid_get_server_list();
206 }
207 if (is_server_bound($id)) {
208 print '<div id="message" class="error"><p>'.__("You cannot remove a server that has roles associated with it.").'</p></div>';
209 } else {
210 $all_trust_maps = openid_teams_get_trust_list();
211 unset($trusted_servers[$id]);
212 openid_teams_update_trusted_servers($trusted_servers);
213 openid_teams_update_trust_list($all_trust_maps);
214 }
215}
216
192/**217/**
193 * Get the list of trusted servers218 * Get the list of trusted servers
194 *219 *
@@ -223,6 +248,8 @@
223 * Check if given server is on trusted server list248 * Check if given server is on trusted server list
224 *249 *
225 * @param string $server250 * @param string $server
251 *
252 * @return bool
226 */253 */
227function in_trusted_servers($server) {254function in_trusted_servers($server) {
228 foreach (openid_get_server_list() as $trusted) {255 foreach (openid_get_server_list() as $trusted) {
@@ -330,7 +357,7 @@
330 ?>357 ?>
331 <tr>358 <tr>
332 <td><?php print htmlentities($server); ?></td>359 <td><?php print htmlentities($server); ?></td>
333 <td><input type="checkbox" name="delete[<?php print $id ?>]" value="1" /></td>360 <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>
334 </tr>361 </tr>
335 <?php362 <?php
336 }363 }

Subscribers

People subscribed via source and target branches