-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add membership endpoint GET support (#5)
* Add membership endpoint GET support * remove misleading location filter
- Loading branch information
1 parent
5d86f84
commit 3defccc
Showing
4 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
from SakaiPy import SakaiSession | ||
|
||
class Membership(object): | ||
""" | ||
Contains logic for the Sakai Membership API endpoint. | ||
More information about the RESTful interface can be found at: | ||
https://trunk-mysql.nightly.sakaiproject.org/direct/membership/describe | ||
""" | ||
|
||
def __init__(self, sess): | ||
""" | ||
Creates a standalone Membershop Object | ||
:param sess: The Session to use. | ||
:return: A Membership object | ||
""" | ||
assert isinstance(sess, SakaiSession.SakaiSession) | ||
self.session = sess | ||
|
||
def getUserMembership(self, user=None, includeSites=True, includeGroups=False, | ||
includeMemberDetails=True, role=None): | ||
""" | ||
Get a list of all site memberships for a user | ||
:param user: The ID of the user to retrieve. Defaults to the current. | ||
:param includeSites: True to include sites in the list (default: True) | ||
:param includeGroups: True to include groups in the list (default: False) | ||
:param includeMemberDetails: True to include full member details. It | ||
cannot be used with includeGroups=true | ||
(default: True) | ||
:param role: Restrict the list to a member role type | ||
""" | ||
params_temp = { | ||
'user': user, | ||
'includeSites': includeSites, | ||
'includeGroups': includeGroups, | ||
'includeMemberDetails': includeMemberDetails, | ||
'role': role | ||
} | ||
if includeGroups: | ||
includeMemberDetails = False | ||
# Do not submit None values | ||
params = {k: v for (k, v) in params_temp.items() if params_temp[k] is not None } | ||
|
||
return self.session.executeRequest('GET', '/membership.json', params=params) | ||
|
||
def getAllMembershipForSite(self, siteid): | ||
""" | ||
Get a list of all members of a site | ||
:param siteid: The ID of the site | ||
""" | ||
return self.session.executeRequest('GET', | ||
'/membership/site/{0}.json'.format(siteid)) | ||
|
||
def getUserRoles(self, uid=None): | ||
""" | ||
Get an user's role in all joined sites | ||
:param uid: The user's ID. Defaults to the current user | ||
""" | ||
if uid is None: | ||
return self.session.executeRequest('GET', '/membership.json') | ||
else: | ||
return self.session.executeRequest('GET', '/membership/{0}.json'.format(uid)) | ||
|
||
def getAllMembershipForGroup(self, groupid): | ||
""" | ||
Get a list of all members of a group | ||
:param groupid: The ID of the group | ||
""" | ||
return self.session.executeRequest('GET', | ||
'/membership/group/{0}.json'.format(groupid)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from . import Announcement, Assignment, Calendar, Forums, Gradebook, News, WebContent | ||
from . import Announcement, Assignment, Calendar, Forums, Gradebook, Membership, News, WebContent | ||
|
||
__all__ = [Announcement, Assignment, Calendar, Forums, Gradebook, News, WebContent] | ||
__all__ = [Announcement, Assignment, Calendar, Forums, Gradebook, Membership, News, WebContent] |