← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~sinzui/launchpad/retract-membership-0 into lp:launchpad/devel

 

Curtis Hovey has proposed merging lp:~sinzui/launchpad/retract-membership-0 into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #680152 add retractTeamMembership() to API
  https://bugs.launchpad.net/bugs/680152


This is my branch to allow team admins to remove their team from another team
via an API call.

    lp:~sinzui/launchpad/retract-membership-0
    Diff size: 47
    Launchpad bug: https://bugs.launchpad.net/bugs/680152
    Test command: ./bin/test -vv -t webservice/xx-person.txt
    Pre-implementation: abentley, leonardr
    Target release: 10.12


Allow team admins to remove their team from another team via an API call
------------------------------------------------------------------------

Team admins can accept or decline the invitation to join a team, but
they cannot retract an accepted invitation. The only way a team can
leave another team is by the the admin of the subteam requesting an admin
of the superteam to do the removal. Team admins, like users, should have
the power to retract their memberships.


Rules
-----

    * Export retractTeamMembership over the API.


QA
--

# This script tests that a team admin can remove his team from it's
# super teams.
from launchpadlib.launchpad import Launchpad STAGING_SERVICE_ROOT


def retract_registry_memberships():
    lp = Launchpad.login_with('testing', STAGING_SERVICE_ROOT)
    my_team = lp.people['registry']
    for super_team in my_team.teams_participated_in:
        print "Removing %s from %s" % (my_team.name, super_team.name)
        try:
            my_team.retractTeamMembership(team=super_team)
        except:
            pass


if __name__ == '__main__':
    retract_registry_memberships()


Lint
----

Linting changed files:
  lib/lp/registry/interfaces/person.py
  lib/lp/registry/stories/webservice/xx-person.txt

There are indentation and header issues in the test that I can fix after the
review.
-- 
https://code.launchpad.net/~sinzui/launchpad/retract-membership-0/+merge/41511
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~sinzui/launchpad/retract-membership-0 into lp:launchpad/devel.
=== modified file 'lib/lp/registry/interfaces/person.py'
--- lib/lp/registry/interfaces/person.py	2010-11-18 12:05:34 +0000
+++ lib/lp/registry/interfaces/person.py	2010-11-22 20:29:48 +0000
@@ -1075,10 +1075,10 @@
         since it inherits from `IPerson`) is a member of himself
         (i.e. `person1.inTeam(person1)`).
 
-        :param team: One of an object providing `IPerson`, the string name of a
-            team or `None`. If a string was supplied the team is looked up.
+        :param team: One of an object providing `IPerson`, the string name of
+            a team or `None`. If a string was supplied the team is looked up.
         :return: A bool with the result of the membership lookup. When looking
-            up the team from a string finds nothing or team was `None` then 
+            up the team from a string finds nothing or team was `None` then
             `False` is returned.
         """
 
@@ -1551,6 +1551,11 @@
         to INVITATION_DECLINED.
         """
 
+    @call_with(user=REQUEST_USER)
+    @operation_parameters(
+        team=copy_field(ITeamMembership['team']),
+        comment=Text(required=False))
+    @export_write_operation()
     def retractTeamMembership(team, user, comment=None):
         """Retract this team's membership in the given team.
 
@@ -2238,6 +2243,7 @@
     (IPersonEditRestricted['addMember'], 'person'),
     (IPersonEditRestricted['acceptInvitationToBeMemberOf'], 'team'),
     (IPersonEditRestricted['declineInvitationToBeMemberOf'], 'team'),
+    (IPersonEditRestricted['retractTeamMembership'], 'team'),
     ]
 for method, name in params_to_fix:
     method.queryTaggedValue(

=== modified file 'lib/lp/registry/stories/webservice/xx-person.txt'
--- lib/lp/registry/stories/webservice/xx-person.txt	2010-10-18 22:24:59 +0000
+++ lib/lp/registry/stories/webservice/xx-person.txt	2010-11-22 20:29:48 +0000
@@ -749,6 +749,18 @@
     >>> webservice.get("/~ubuntu-team/+member/name20").jsonBody()['status']
     u'Invitation declined'
 
+The retractTeamMembership method allows a team admin to remove his team from
+another team.
+
+    >>> print webservice.named_post(
+    ...     landscape_developers['self_link'], 'retractTeamMembership',
+    ...     {}, team=ubuntu_team['self_link'], comment='bye bye')
+    HTTP/1.1 200 Ok
+    ...
+    >>> webservice.get("/~ubuntu-team/+member/landscape-developers"
+    ...     ).jsonBody()['status']
+    u'Deactivated'
+
 To check whether or not a given person is a participant in a team, use the
 'inTeam' custom operation.