Skip to content

Commit

Permalink
SharePoint API: permissions and sharing namespaces changes
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Jul 1, 2020
1 parent 99a9757 commit 92cc6ed
Show file tree
Hide file tree
Showing 35 changed files with 552 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/sharepoint/connect_with_user_creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from office365.runtime.auth.userCredential import UserCredential
from office365.sharepoint.client_context import ClientContext

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

Expand Down
2 changes: 1 addition & 1 deletion generator/metadata/SharePoint.xml

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions office365/runtime/clientValue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ class ClientValue(object):
containing entity or as a temporary value
"""

def __init__(self):
def __init__(self, namespace=None):
super(ClientValue, self).__init__()
self._namespace = namespace

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

@property
def entity_type_name(self):
return None
if self._namespace:
return ".".join([self._namespace, type(self).__name__])
return type(self).__name__

@property
def is_server_object_null(self):
Expand Down
23 changes: 19 additions & 4 deletions office365/runtime/clientValueCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,26 @@ def __iter__(self):
def to_json(self):
return self._data

def set_property(self, index, value, persist_changes=False):
child_value = self._item_type
if isinstance(child_value, ClientValue):
for k, v in value.items():
child_value.set_property(k, v, False)
else:
child_value = value
self.add(child_value)

@property
def entity_type_name(self):
edm_primitive_types = {
int: "Edm.Int32",
str: "Edm.String",
primitive_types = {
"bool": "Edm.Boolean",
"int": "Edm.Int32",
"str": "Edm.String",
}
item_type_name = edm_primitive_types.get(self._item_type, "Edm.Int32")
item_type_name = type(self._item_type).__name__
is_primitive = primitive_types.get(item_type_name, None) is not None
if is_primitive:
item_type_name = primitive_types[item_type_name]
elif isinstance(self._item_type, ClientValue):
item_type_name = self._item_type.entity_type_name
return "Collection({0})".format(item_type_name)
5 changes: 5 additions & 0 deletions office365/sharepoint/forms/form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.sharepoint.base_entity import BaseEntity


class Form(BaseEntity):
"""A form provides a display and editing interface for a single list item."""
7 changes: 7 additions & 0 deletions office365/sharepoint/forms/formCollection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from office365.runtime.client_object_collection import ClientObjectCollection


class FormCollection(ClientObjectCollection):

def get_by_page_type(self):
pass
13 changes: 13 additions & 0 deletions office365/sharepoint/permissions/roleAssignmentCollection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from office365.runtime.client_object_collection import ClientObjectCollection


class RoleAssignmentCollection(ClientObjectCollection):
"""Represents a collection of RoleAssignment resources."""

def remove_role_assignment(self, principal_id, role_def_id):
"""Removes the role assignment with the specified principal and role definition from the collection.
:param int role_def_id: The ID of the role definition in the role assignment.
:param int principal_id: The ID of the user or group in the role assignment.
"""
pass
25 changes: 25 additions & 0 deletions office365/sharepoint/permissions/roleDefinition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from office365.sharepoint.base_entity import BaseEntity


class RoleDefinition(BaseEntity):
"""Defines a single role definition, including a name, description, and set of rights."""

@property
def name(self):
"""Gets a value that specifies the role definition name."""
return self.properties.get('Name', None)

@name.setter
def name(self, value):
"""Sets a value that specifies the role definition name."""
self.set_property('Name', value)

@property
def description(self):
"""Gets or sets a value that specifies the description of the role definition."""
return self.properties.get('Description', None)

@description.setter
def description(self, value):
"""Gets or sets a value that specifies the description of the role definition."""
self.set_property('Description', value)
8 changes: 8 additions & 0 deletions office365/sharepoint/permissions/roleDefinitionCollection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from office365.runtime.client_object_collection import ClientObjectCollection
from office365.sharepoint.permissions.roleDefinition import RoleDefinition


class RoleDefinitionCollection(ClientObjectCollection):

def __init__(self, context, resource_path=None):
super(RoleDefinitionCollection, self).__init__(context, RoleDefinition, resource_path)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from office365.runtime.clientValue import ClientValue
from office365.sharepoint.permissions.basePermissions import BasePermissions


class RoleDefinitionCreationInformation(ClientValue):

def __init__(self):
"""Contains properties that are used as parameters to initialize a role definition."""
super(RoleDefinitionCreationInformation, self).__init__()
self.Name = None
self.Description = None
self.BasePermissions = BasePermissions()
7 changes: 7 additions & 0 deletions office365/sharepoint/permissions/utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from office365.sharepoint.base_entity import BaseEntity


class Utility(BaseEntity):

def __init__(self, context, resource_path):
super().__init__(context, resource_path, "SP.Utilities")
12 changes: 12 additions & 0 deletions office365/sharepoint/principal/principalSource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class PrincipalSource:
"""Specifies the source of a principal."""

def __init__(self):
pass

None_ = 0
UserInfoList = 1
Windows = 2
MembershipProvider = 4
RoleProvider = 8
All = 15
12 changes: 12 additions & 0 deletions office365/sharepoint/principal/principalType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class PrincipalType:
"""Specifies the type of a principal."""

def __init__(self):
pass

None_ = 0
User = 1
DistributionList = 2
SecurityGroup = 4
SharePointGroup = 8
All = 15
6 changes: 6 additions & 0 deletions office365/sharepoint/sharing/externalSharingSiteOption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ExternalSharingSiteOption:
def __init__(self):
pass

Edit = "role:1073741827"
View = "role:1073741826"
10 changes: 10 additions & 0 deletions office365/sharepoint/sharing/invitationCreationResult.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from office365.runtime.clientValue import ClientValue


class SPInvitationCreationResult(ClientValue):

def __init__(self):
super().__init__("SP")
self.Email = None
self.InvitationLink = None
self.Succeeded = None
5 changes: 5 additions & 0 deletions office365/sharepoint/sharing/objectSharingInformation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.sharepoint.base_entity import BaseEntity


class ObjectSharingInformation(BaseEntity):
pass
21 changes: 21 additions & 0 deletions office365/sharepoint/sharing/objectSharingSettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from office365.runtime.resource_path import ResourcePath
from office365.sharepoint.base_entity import BaseEntity
from office365.sharepoint.sharing.objectSharingInformation import ObjectSharingInformation


class ObjectSharingSettings(BaseEntity):

@property
def web_url(self):
"""
:return: str
"""
return self.properties.get("WebUrl", None)

@property
def object_sharing_information(self):
return self.properties.get("ObjectSharingInformation",
ObjectSharingInformation(self.context,
ResourcePath("ObjectSharingInformation",
self.resource_path)))
11 changes: 11 additions & 0 deletions office365/sharepoint/sharing/pickerEntityInformationRequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from office365.runtime.clientValue import ClientValue


class PickerEntityInformationRequest(ClientValue):

def __init__(self):
super().__init__()
self.Key = None
self.GroupId = None
self.PrincipalType = None
self.EmailAddress = None
4 changes: 4 additions & 0 deletions office365/sharepoint/sharing/sharedObjectType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class SharedObjectType:

def __init__(self):
pass
9 changes: 9 additions & 0 deletions office365/sharepoint/sharing/sharingLinkAccessRequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from office365.runtime.clientValue import ClientValue


class SharingLinkAccessRequest(ClientValue):

def __init__(self):
super().__init__()
self.ensureAccess = None
self.password = None
2 changes: 2 additions & 0 deletions office365/sharepoint/sharing/sharingLinkInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
class SharingLinkInfo(ClientValue):

def __init__(self):
super().__init__()
self.AllowsAnonymousAccess = None
self.ApplicationId = None
self.CreatedBy = None
self.PasswordProtected = None
46 changes: 46 additions & 0 deletions office365/sharepoint/sharing/sharingResult.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from office365.runtime.clientValueCollection import ClientValueCollection
from office365.runtime.resource_path import ResourcePath
from office365.sharepoint.base_entity import BaseEntity
from office365.sharepoint.principal.group_collection import GroupCollection
from office365.sharepoint.sharing.invitationCreationResult import SPInvitationCreationResult
from office365.sharepoint.sharing.userSharingResult import UserSharingResult


class SharingResult(BaseEntity):

def __init__(self, context):
super().__init__(context)

@property
def errorMessage(self):
return self.properties.get("ErrorMessage", None)

@property
def name(self):
return self.properties.get("Name", None)

@property
def iconUrl(self):
return self.properties.get("IconUrl", None)

@property
def statusCode(self):
return self.properties.get("StatusCode", None)

@property
def permissionsPageRelativeUrl(self):
return self.properties.get("PermissionsPageRelativeUrl", None)

@property
def invited_users(self):
return self.properties.get("InvitedUsers", ClientValueCollection(SPInvitationCreationResult()))

@property
def uniquelyPermissionedUsers(self):
return self.properties.get("UniquelyPermissionedUsers", ClientValueCollection(UserSharingResult()))

@property
def groupsSharedWith(self):
return self.properties.get("GroupsSharedWith",
GroupCollection(self.context, ResourcePath("GroupsSharedWith", self.resource_path)))

27 changes: 27 additions & 0 deletions office365/sharepoint/sharing/sharingUtility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from office365.runtime.queries.serviceOperationQuery import ServiceOperationQuery
from office365.runtime.resource_path import ResourcePath
from office365.sharepoint.base_entity import BaseEntity
from office365.sharepoint.sharing.userDirectoryInfo import UserDirectoryInfo


class SharingUtility(BaseEntity):

def __init__(self, context):
super().__init__(context, ResourcePath("SharingUtility"))

@staticmethod
def get_user_directory_info_by_email(context, email):
"""
:param str email:
:param office365.sharepoint.client_context.ClientContext context:
"""
result = UserDirectoryInfo()
payload = {
"email": email
}
utility = SharingUtility(context)
qry = ServiceOperationQuery(utility, "GetUserDirectoryInfoByEmail", None, payload, None, result)
qry.static = True
context.add_query(qry)
return result
5 changes: 5 additions & 0 deletions office365/sharepoint/sharing/userDirectoryInfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.runtime.clientValue import ClientValue


class UserDirectoryInfo(ClientValue):
pass
17 changes: 17 additions & 0 deletions office365/sharepoint/sharing/userSharingResult.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from office365.runtime.clientValue import ClientValue
from office365.runtime.clientValueCollection import ClientValueCollection


class UserSharingResult(ClientValue):

def __init__(self):
super().__init__("SP.Sharing")
self.AllowedRoles = ClientValueCollection(int)
self.CurrentRole = None
self.DisplayName = None
self.Email = None
self.InvitationLink = None
self.IsUserKnown = None
self.Message = None
self.Status = None
self.User = None
Empty file.
Empty file.
Loading

0 comments on commit 92cc6ed

Please sign in to comment.