def get_object_sharing_settings(context, object_url, group_id, use_simplified_roles): """Given a path to an object in SharePoint, this will generate a sharing settings object which contains necessary information for rendering sharing information.. :param office365.sharepoint.client_context.ClientContext context: SharePoint client :param str object_url: A URL with one of two possible formats. The two possible URL formats are: 1) The URL of the site, with the path of the object in SharePoint represented as query string parameters, forSharing set to 1 if sharing, and mbypass set to 1 to bypass any mobile logic e.g. http://contoso.com/?forSharing=1&mbypass=1&List=%7BCF908473%2D72D4%2D449D%2D8A53%2D4BD01EC54B84%7D&obj={CF908473-72D4-449D-8A53-4BD01EC54B84},1,DOCUMENT 2) The URL of the SharePoint object (web, list, item) intended for sharing e.g. http://contoso.com/Documents/SampleFile.docx :param int group_id: The id value of the permissions group if adding to a group, 0 otherwise. :param bool use_simplified_roles: A Boolean value indicating whether to use the SharePoint simplified roles (Edit, View) or not. """ result = ObjectSharingSettings(context) payload = { "objectUrl": object_url, "groupId": group_id, "useSimplifiedRoles": use_simplified_roles } qry = ServiceOperationQuery(context.web, "GetObjectSharingSettings", None, payload, None, result) qry.static = True context.add_query(qry) return result
def get_role_definition(self, role): """his method returns a role definition in the current web that is associated with a given Role (section 3.2.5.188) value. :param int role: A Role value for which to obtain the associated role definition object. """ role_def = RoleDefinition(self.context) qry = ServiceOperationQuery(self, "GetRoleDefinition", [role], None, None, role_def) qry.static = True self.context.add_query(qry) return role_def
def exists(context, url): """Determine whether site exists :type context: office365.sharepoint.client_context.ClientContext :type url: str """ result = ClientResult(bool) payload = { "url": url } qry = ServiceOperationQuery(context.site, "Exists", None, payload, None, result) qry.static = True context.add_query(qry) return result
def share_object(context, url, peoplePickerInput, roleValue=None, groupId=0, propagateAcl=False, sendEmail=True, includeAnonymousLinkInEmail=False, emailSubject=None, emailBody=None, useSimplifiedRoles=True): """ This method shares an object in SharePoint such as a list item or site. It returns a SharingResult object which contains the completion script and a page to redirect to if desired. :param office365.sharepoint.client_context.ClientContext context: SharePoint context :param str url: The URL of the website with the path of an object in SharePoint query string parameters. :param str roleValue: The sharing role value for the type of permission to grant on the object. :param str peoplePickerInput: A string of JSON representing users in people picker format. :param int groupId: The ID of the group to be added. Zero if not adding to a permissions group. :param bool propagateAcl: A flag to determine if permissions SHOULD be pushed to items with unique permissions. :param bool sendEmail: A flag to determine if an email notification SHOULD be sent (if email is configured). :param bool includeAnonymousLinkInEmail: If an email is being sent, this determines if an anonymous link SHOULD be added to the message. :param str emailSubject: The email subject. :param str emailBody: The email subject. :param bool useSimplifiedRoles: A Boolean value indicating whether to use the SharePoint simplified roles (Edit, View) or not. """ result = SharingResult(context) payload = { "url": url, "groupId": groupId, "peoplePickerInput": peoplePickerInput, "roleValue": roleValue, "includeAnonymousLinkInEmail": includeAnonymousLinkInEmail, "propagateAcl": propagateAcl, "sendEmail": sendEmail, "emailSubject": emailSubject, "emailBody": emailBody, "useSimplifiedRoles": useSimplifiedRoles } qry = ServiceOperationQuery(context.web, "ShareObject", None, payload, None, result) qry.static = True context.add_query(qry) return result
def get_url_by_id(context, site_id, stop_redirect=False): """Gets Site Url By Id :type context: office365.sharepoint.client_context.ClientContext :type site_id: str :type stop_redirect: bool """ result = ClientResult(str) payload = { "id": site_id, "stopRedirect": stop_redirect } qry = ServiceOperationQuery(context.site, "GetUrlById", None, payload, None, result) qry.static = True context.add_query(qry) return result
def unshare_object(context, url): """ Removes Sharing permissions on an object. :param office365.sharepoint.client_context.ClientContext context: SharePoint context :param str url: A SharingResult object which contains status codes pertaining to the completion of the operation. :return: SharingResult """ result = SharingResult(context) payload = {"url": url} qry = ServiceOperationQuery(context.web, "UnshareObject", None, payload, None, result) qry.static = True context.add_query(qry) return result
def create_anonymous_link(context, url, is_edit_link): """Create an anonymous link which can be used to access a document without needing to authenticate. :param bool is_edit_link: If true, the link will allow the guest user edit privileges on the item. :param str url: The URL of the site, with the path of the object in SharePoint represented as query string parameters :param office365.sharepoint.client_context.ClientContext context: client context """ result = ClientResult(bool) payload = {"url": context.base_url + url, "isEditLink": is_edit_link} qry = ServiceOperationQuery(context.web, "CreateAnonymousLink", None, payload, None, result) qry.static = True context.add_query(qry) return result
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
def get_list_item_sharing_information(context, listID, itemID, excludeCurrentUser=True, excludeSiteAdmin=True, excludeSecurityGroups=True, retrieveAnonymousLinks=False, retrieveUserInfoDetails=False, checkForAccessRequests=False): """ Retrieves information about the sharing state for a given list. :param bool checkForAccessRequests: Specifies whether the returned sharing state information will contain a URL to a location which describes any access requests present in the site (2), if such a URL is available. :param bool retrieveUserInfoDetails: Specifies whether the returned sharing state information will contain basic or detailed information about the users with permissions to the list item. :param bool retrieveAnonymousLinks: Specifies whether the returned sharing state information will contain information about a URL that allows an anonymous user to access the list item. :param bool excludeSecurityGroups: Specifies whether the returned sharing state information will exclude information about security groups which have permissions to the list item. :param bool excludeSiteAdmin: Specifies whether the returned sharing state information will exclude information about users who are site collection administrators of the site collection which contains the list. :param bool excludeCurrentUser: Specifies whether the returned sharing state information will exclude information about the user making the request. :param int itemID: The list item identifier for the list item for which the sharing state is requested. :param str listID: The list identifier for the list which contains the list item for which the sharing state is requested. :param office365.sharepoint.client_context.ClientContext context: :return: ObjectSharingInformation """ result = ObjectSharingInformation(context) payload = { "listID": listID, "itemID": itemID, "excludeCurrentUser": excludeCurrentUser, "excludeSiteAdmin": excludeSiteAdmin, "excludeSecurityGroups": excludeSecurityGroups, "retrieveAnonymousLinks": retrieveAnonymousLinks, "retrieveUserInfoDetails": retrieveUserInfoDetails, "checkForAccessRequests": checkForAccessRequests } qry = ServiceOperationQuery(result, "GetListItemSharingInformation", None, payload, None, result) qry.static = True context.add_query(qry) return result
def client_people_picker_resolve_user(context, query_params, on_resolved=None): """ Resolves the principals to a string of JSON representing users in people picker format. :param (str) -> None on_resolved: resolved event :param ClientPeoplePickerQueryParameters query_params: Specifies the properties of a principal query. :param office365.sharepoint.client_context.ClientContext context: """ result = ClientResult(str) svc = ClientPeoplePickerWebServiceInterface(context) qry = ServiceOperationQuery(svc, "ClientPeoplePickerResolveUser", None, query_params, "queryParams", result) qry.static = True context.add_query(qry) def _process_result(resp): result.value = "[{0}]".format(result.value) if callable(on_resolved): on_resolved(result.value) context.after_execute(_process_result) return result