Skip to content

Commit 92cc6ed

Browse files
vvgrem@gmail.comvvgrem@gmail.com
vvgrem@gmail.com
authored and
vvgrem@gmail.com
committed
SharePoint API: permissions and sharing namespaces changes
1 parent 99a9757 commit 92cc6ed

35 files changed

+552
-15
lines changed

examples/sharepoint/connect_with_user_creds.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from office365.runtime.auth.userCredential import UserCredential
44
from office365.sharepoint.client_context import ClientContext
55

6-
ctx = ClientContext.connect_with_credentials("https://mediadev8.sharepoint.com/sites/team/",
6+
ctx = ClientContext.connect_with_credentials(settings["url"],
77
UserCredential(settings['user_credentials']['username'],
88
settings['user_credentials']['password']))
99

generator/metadata/SharePoint.xml

+1-1
Large diffs are not rendered by default.

office365/runtime/clientValue.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ class ClientValue(object):
44
containing entity or as a temporary value
55
"""
66

7-
def __init__(self):
7+
def __init__(self, namespace=None):
88
super(ClientValue, self).__init__()
9+
self._namespace = namespace
910

1011
def set_property(self, k, v, persist_changes=True):
1112
if hasattr(self, k):
@@ -26,7 +27,9 @@ def to_json(self):
2627

2728
@property
2829
def entity_type_name(self):
29-
return None
30+
if self._namespace:
31+
return ".".join([self._namespace, type(self).__name__])
32+
return type(self).__name__
3033

3134
@property
3235
def is_server_object_null(self):

office365/runtime/clientValueCollection.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,26 @@ def __iter__(self):
1818
def to_json(self):
1919
return self._data
2020

21+
def set_property(self, index, value, persist_changes=False):
22+
child_value = self._item_type
23+
if isinstance(child_value, ClientValue):
24+
for k, v in value.items():
25+
child_value.set_property(k, v, False)
26+
else:
27+
child_value = value
28+
self.add(child_value)
29+
2130
@property
2231
def entity_type_name(self):
23-
edm_primitive_types = {
24-
int: "Edm.Int32",
25-
str: "Edm.String",
32+
primitive_types = {
33+
"bool": "Edm.Boolean",
34+
"int": "Edm.Int32",
35+
"str": "Edm.String",
2636
}
27-
item_type_name = edm_primitive_types.get(self._item_type, "Edm.Int32")
37+
item_type_name = type(self._item_type).__name__
38+
is_primitive = primitive_types.get(item_type_name, None) is not None
39+
if is_primitive:
40+
item_type_name = primitive_types[item_type_name]
41+
elif isinstance(self._item_type, ClientValue):
42+
item_type_name = self._item_type.entity_type_name
2843
return "Collection({0})".format(item_type_name)

office365/sharepoint/forms/form.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.sharepoint.base_entity import BaseEntity
2+
3+
4+
class Form(BaseEntity):
5+
"""A form provides a display and editing interface for a single list item."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from office365.runtime.client_object_collection import ClientObjectCollection
2+
3+
4+
class FormCollection(ClientObjectCollection):
5+
6+
def get_by_page_type(self):
7+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from office365.runtime.client_object_collection import ClientObjectCollection
2+
3+
4+
class RoleAssignmentCollection(ClientObjectCollection):
5+
"""Represents a collection of RoleAssignment resources."""
6+
7+
def remove_role_assignment(self, principal_id, role_def_id):
8+
"""Removes the role assignment with the specified principal and role definition from the collection.
9+
10+
:param int role_def_id: The ID of the role definition in the role assignment.
11+
:param int principal_id: The ID of the user or group in the role assignment.
12+
"""
13+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from office365.sharepoint.base_entity import BaseEntity
2+
3+
4+
class RoleDefinition(BaseEntity):
5+
"""Defines a single role definition, including a name, description, and set of rights."""
6+
7+
@property
8+
def name(self):
9+
"""Gets a value that specifies the role definition name."""
10+
return self.properties.get('Name', None)
11+
12+
@name.setter
13+
def name(self, value):
14+
"""Sets a value that specifies the role definition name."""
15+
self.set_property('Name', value)
16+
17+
@property
18+
def description(self):
19+
"""Gets or sets a value that specifies the description of the role definition."""
20+
return self.properties.get('Description', None)
21+
22+
@description.setter
23+
def description(self, value):
24+
"""Gets or sets a value that specifies the description of the role definition."""
25+
self.set_property('Description', value)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.runtime.client_object_collection import ClientObjectCollection
2+
from office365.sharepoint.permissions.roleDefinition import RoleDefinition
3+
4+
5+
class RoleDefinitionCollection(ClientObjectCollection):
6+
7+
def __init__(self, context, resource_path=None):
8+
super(RoleDefinitionCollection, self).__init__(context, RoleDefinition, resource_path)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from office365.runtime.clientValue import ClientValue
2+
from office365.sharepoint.permissions.basePermissions import BasePermissions
3+
4+
5+
class RoleDefinitionCreationInformation(ClientValue):
6+
7+
def __init__(self):
8+
"""Contains properties that are used as parameters to initialize a role definition."""
9+
super(RoleDefinitionCreationInformation, self).__init__()
10+
self.Name = None
11+
self.Description = None
12+
self.BasePermissions = BasePermissions()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from office365.sharepoint.base_entity import BaseEntity
2+
3+
4+
class Utility(BaseEntity):
5+
6+
def __init__(self, context, resource_path):
7+
super().__init__(context, resource_path, "SP.Utilities")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class PrincipalSource:
2+
"""Specifies the source of a principal."""
3+
4+
def __init__(self):
5+
pass
6+
7+
None_ = 0
8+
UserInfoList = 1
9+
Windows = 2
10+
MembershipProvider = 4
11+
RoleProvider = 8
12+
All = 15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class PrincipalType:
2+
"""Specifies the type of a principal."""
3+
4+
def __init__(self):
5+
pass
6+
7+
None_ = 0
8+
User = 1
9+
DistributionList = 2
10+
SecurityGroup = 4
11+
SharePointGroup = 8
12+
All = 15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class ExternalSharingSiteOption:
2+
def __init__(self):
3+
pass
4+
5+
Edit = "role:1073741827"
6+
View = "role:1073741826"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from office365.runtime.clientValue import ClientValue
2+
3+
4+
class SPInvitationCreationResult(ClientValue):
5+
6+
def __init__(self):
7+
super().__init__("SP")
8+
self.Email = None
9+
self.InvitationLink = None
10+
self.Succeeded = None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.sharepoint.base_entity import BaseEntity
2+
3+
4+
class ObjectSharingInformation(BaseEntity):
5+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from office365.runtime.resource_path import ResourcePath
2+
from office365.sharepoint.base_entity import BaseEntity
3+
from office365.sharepoint.sharing.objectSharingInformation import ObjectSharingInformation
4+
5+
6+
class ObjectSharingSettings(BaseEntity):
7+
8+
@property
9+
def web_url(self):
10+
"""
11+
12+
:return: str
13+
"""
14+
return self.properties.get("WebUrl", None)
15+
16+
@property
17+
def object_sharing_information(self):
18+
return self.properties.get("ObjectSharingInformation",
19+
ObjectSharingInformation(self.context,
20+
ResourcePath("ObjectSharingInformation",
21+
self.resource_path)))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from office365.runtime.clientValue import ClientValue
2+
3+
4+
class PickerEntityInformationRequest(ClientValue):
5+
6+
def __init__(self):
7+
super().__init__()
8+
self.Key = None
9+
self.GroupId = None
10+
self.PrincipalType = None
11+
self.EmailAddress = None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class SharedObjectType:
2+
3+
def __init__(self):
4+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from office365.runtime.clientValue import ClientValue
2+
3+
4+
class SharingLinkAccessRequest(ClientValue):
5+
6+
def __init__(self):
7+
super().__init__()
8+
self.ensureAccess = None
9+
self.password = None

office365/sharepoint/sharing/sharingLinkInfo.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
class SharingLinkInfo(ClientValue):
55

66
def __init__(self):
7+
super().__init__()
78
self.AllowsAnonymousAccess = None
89
self.ApplicationId = None
910
self.CreatedBy = None
11+
self.PasswordProtected = None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from office365.runtime.clientValueCollection import ClientValueCollection
2+
from office365.runtime.resource_path import ResourcePath
3+
from office365.sharepoint.base_entity import BaseEntity
4+
from office365.sharepoint.principal.group_collection import GroupCollection
5+
from office365.sharepoint.sharing.invitationCreationResult import SPInvitationCreationResult
6+
from office365.sharepoint.sharing.userSharingResult import UserSharingResult
7+
8+
9+
class SharingResult(BaseEntity):
10+
11+
def __init__(self, context):
12+
super().__init__(context)
13+
14+
@property
15+
def errorMessage(self):
16+
return self.properties.get("ErrorMessage", None)
17+
18+
@property
19+
def name(self):
20+
return self.properties.get("Name", None)
21+
22+
@property
23+
def iconUrl(self):
24+
return self.properties.get("IconUrl", None)
25+
26+
@property
27+
def statusCode(self):
28+
return self.properties.get("StatusCode", None)
29+
30+
@property
31+
def permissionsPageRelativeUrl(self):
32+
return self.properties.get("PermissionsPageRelativeUrl", None)
33+
34+
@property
35+
def invited_users(self):
36+
return self.properties.get("InvitedUsers", ClientValueCollection(SPInvitationCreationResult()))
37+
38+
@property
39+
def uniquelyPermissionedUsers(self):
40+
return self.properties.get("UniquelyPermissionedUsers", ClientValueCollection(UserSharingResult()))
41+
42+
@property
43+
def groupsSharedWith(self):
44+
return self.properties.get("GroupsSharedWith",
45+
GroupCollection(self.context, ResourcePath("GroupsSharedWith", self.resource_path)))
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from office365.runtime.queries.serviceOperationQuery import ServiceOperationQuery
2+
from office365.runtime.resource_path import ResourcePath
3+
from office365.sharepoint.base_entity import BaseEntity
4+
from office365.sharepoint.sharing.userDirectoryInfo import UserDirectoryInfo
5+
6+
7+
class SharingUtility(BaseEntity):
8+
9+
def __init__(self, context):
10+
super().__init__(context, ResourcePath("SharingUtility"))
11+
12+
@staticmethod
13+
def get_user_directory_info_by_email(context, email):
14+
"""
15+
16+
:param str email:
17+
:param office365.sharepoint.client_context.ClientContext context:
18+
"""
19+
result = UserDirectoryInfo()
20+
payload = {
21+
"email": email
22+
}
23+
utility = SharingUtility(context)
24+
qry = ServiceOperationQuery(utility, "GetUserDirectoryInfoByEmail", None, payload, None, result)
25+
qry.static = True
26+
context.add_query(qry)
27+
return result
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.runtime.clientValue import ClientValue
2+
3+
4+
class UserDirectoryInfo(ClientValue):
5+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from office365.runtime.clientValue import ClientValue
2+
from office365.runtime.clientValueCollection import ClientValueCollection
3+
4+
5+
class UserSharingResult(ClientValue):
6+
7+
def __init__(self):
8+
super().__init__("SP.Sharing")
9+
self.AllowedRoles = ClientValueCollection(int)
10+
self.CurrentRole = None
11+
self.DisplayName = None
12+
self.Email = None
13+
self.InvitationLink = None
14+
self.IsUserKnown = None
15+
self.Message = None
16+
self.Status = None
17+
self.User = None

office365/sharepoint/ui/__init__.py

Whitespace-only changes.

office365/sharepoint/ui/applicationpages/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)