示例#1
0
    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
示例#2
0
    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
示例#4
0
    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
示例#5
0
    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
示例#6
0
    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
示例#7
0
    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 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
示例#9
0
 def ensure_site_pages_library(self):
     """Gets a list that is the default location for wiki pages."""
     target_list = List(self.context)
     self.add_child(target_list)
     qry = ServiceOperationQuery(self, "ensureSitePagesLibrary", None, None, None, target_list)
     self.context.add_query(qry)
     return target_list
 def suggest(self, query_text):
     result = QuerySuggestionResults()
     payload = {"querytext": query_text}
     qry = ServiceOperationQuery(self, "suggest", None, payload, None,
                                 result)
     self.context.add_query(qry)
     return result
 def validate_update_list_item(self, form_values, new_document_update):
     """Validates and sets the values of the specified collection of fields for the list item."""
     qry = ServiceOperationQuery(self, "validateUpdateListItem", None, {
         "formValues": form_values,
         "bNewDocumentUpdate": new_document_update,
     })
     self.context.add_query(qry)
示例#12
0
    def add_item(self, list_item_creation_information):
        """The recommended way to add a list item is to send a POST request to the ListItemCollection resource endpoint,
         as shown in ListItemCollection request examples.

         :type list_item_creation_information: ListItemCreationInformation or dict"""
        item = ListItem(self.context)
        if isinstance(list_item_creation_information, dict):
            for k, v in list_item_creation_information.items():
                item.set_property(k, v, True)
            self.items.add_child(item)
            item.ensure_type_name(self)
            qry = ServiceOperationQuery(self, "items", None, item, None, item)
            self.context.add_query(qry)
        else:

            def _resolve_folder_url():
                list_item_creation_information.FolderUrl = self.context.base_url + self.rootFolder.serverRelativeUrl
                add_item_qry = ServiceOperationQuery(
                    self, "addItem", None, list_item_creation_information,
                    "parameters", item)
                self.context.add_query(add_item_qry)

            self.rootFolder.ensure_property("ServerRelativeUrl",
                                            _resolve_folder_url)
        return item
示例#13
0
    def deny(self, comment):
        """Denies approval for a file that was submitted for content approval.

        :type comment: str
        """
        qry = ServiceOperationQuery(self, "deny", {"comment": comment})
        self.context.add_query(qry)
示例#14
0
    def approve(self, comment):
        """Approves the file submitted for content approval with the specified comment.

        :type comment: str
        """
        qry = ServiceOperationQuery(self, "approve", {"comment": comment})
        self.context.add_query(qry)
示例#15
0
 def checkout(self):
     """Checks out the file from a document library based on the check-out type."""
     qry = ServiceOperationQuery(
         self,
         "checkout",
     )
     self.context.add_query(qry)
    def break_role_inheritance(self,
                               copyRoleAssignments=True,
                               clearSubscopes=True):
        """Creates unique role assignments for the securable object. If the securable object already has
        unique role assignments, the protocol server MUST NOT alter any role assignments.

        :param bool clearSubscopes:  If the securable object is a site (2), and the clearSubscopes parameter is "true",
        the role assignments for all child securable objects in the current site (2) and in the sites (2) that inherit
        role assignments from the current site (2) MUST be cleared and those securable objects inherit role assignments
        from the current site (2) after this call. If the securable object is a site (2), and the clearSubscopes
        parameter is "false", the role assignments for all child securable objects that do not inherit role assignments
        from their parent object (1) MUST remain unchanged. If the securable object is not a site (2), and the
        clearSubscopes parameter is "true", the role assignments for all child securable objects MUST be cleared and
        those securable objects inherit role assignments from the current securable object after this call. If the
        securable object is not a site (2), and the clearSubscopes parameter is "false", the role assignments for all
        child securable objects that do not inherit role assignments from their parent object (1) MUST remain unchanged.
        :param bool copyRoleAssignments: Specifies whether to copy the role assignments from
        the parent securable object.If the value is "false", the collection of role assignments MUST contain
        only 1 role assignment containing the current user after the operation.

        """
        payload = {
            "copyRoleAssignments": copyRoleAssignments,
            "clearSubscopes": clearSubscopes
        }
        qry = ServiceOperationQuery(self, "breakRoleInheritance", None,
                                    payload, None, None)
        self.context.add_query(qry)
 def create(self, request):
     """Create a modern site"""
     response = SPSiteCreationResponse()
     qry = ServiceOperationQuery(self, "Create", None, request, "request",
                                 response)
     self.context.add_query(qry)
     return response
示例#18
0
    def invite(self, recipients, message, require_sign_in=True, send_invitation=True, roles=None):
        """Sends a sharing invitation for a driveItem. A sharing invitation provides permissions to the recipients
        and optionally sends them an email with a sharing link.

        :param list[DriveRecipient] recipients: A collection of recipients who will receive access and the sharing
        invitation.
        :param str message: A plain text formatted message that is included in the sharing invitation.
        Maximum length 2000 characters.
        :param bool require_sign_in: Specifies whether the recipient of the invitation is required to sign-in to view
        the shared item.
        :param bool send_invitation: If true, a sharing link is sent to the recipient. Otherwise, a permission is
        granted directly without sending a notification.
        :param list[str] roles: Specify the roles that are to be granted to the recipients of the sharing invitation.
        """
        if roles is None:
            roles = ["read"]
        permissions = PermissionCollection(self.context)
        payload = {
            "requireSignIn": require_sign_in,
            "sendInvitation": send_invitation,
            "roles": roles,
            "recipients": recipients,
            "message": message
        }
        qry = ServiceOperationQuery(self, "invite", payload, None, None, permissions)
        self.context.add_query(qry)
        return permissions
    def set_show_in_display_form(self, flag):
        """Sets the value of the ShowInDisplayForm property for this fields.

        :type flag: bool
        """
        qry = ServiceOperationQuery(self, "setShowInDisplayForm", [flag])
        self.context.add_query(qry)
 def add(self, user_id):
     """Add a user to the group."""
     payload = {
         "@odata.id":
         "https://graph.microsoft.com/v1.0/users/{0}".format(user_id)
     }
     qry = ServiceOperationQuery(self, "$ref", None, payload)
     self.context.add_query(qry)
示例#21
0
 def ensure_site_assets_library(self):
     """Gets a list that is the default asset location for images or other files, which the users
     upload to their wiki pages."""
     target_list = List(self.context)
     self.add_child(target_list)
     qry = ServiceOperationQuery(self, "ensureSiteAssetsLibrary", None, None, None, target_list)
     self.context.add_query(qry)
     return target_list
    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
示例#23
0
 def unpublish(self, comment):
     """Removes the file from content approval or unpublish a major version.
     :type comment: str
     """
     qry = ServiceOperationQuery(self, "unpublish", {
         "comment": comment,
     })
     self.context.add_query(qry)
示例#24
0
 def publish(self, comment):
     """Submits the file for content approval with the specified comment.
     :type comment: str
     """
     qry = ServiceOperationQuery(self, "publish", {
         "comment": comment,
     })
     self.context.add_query(qry)
 def search_center_url(self):
     """The operation is used to get the URI address of the search center by using the HTTP protocol
     with the GET method. The operation returns the URI of the of the search center."""
     result = ClientResult(None)
     qry = ServiceOperationQuery(self, "searchCenterUrl", None, None, None,
                                 result)
     self.context.add_query(qry)
     return result
 def add(self, web_creation_information):
     target_web = Web(self.context)
     self.add_child(target_web)
     qry = ServiceOperationQuery(self, "add", None,
                                 web_creation_information, "parameters",
                                 target_web)
     self.context.add_query(qry)
     return target_web
示例#27
0
 def does_user_have_permissions(self, permission_mask):
     """Returns whether the current user has the given set of permissions.
     :type permission_mask: BasePermissions
     """
     result = ClientResult(bool)
     qry = ServiceOperationQuery(self, "doesUserHavePermissions",
                                 permission_mask, None, None, result)
     self.context.add_query(qry)
     return result
示例#28
0
 def get_user_effective_permissions(self, user_name):
     """Gets the effective permissions that the specified user has within the current application scope.
     :type user_name: str
     """
     result = ClientResult(BasePermissions())
     qry = ServiceOperationQuery(self, "GetUserEffectivePermissions",
                                 [user_name], None, None, result)
     self.context.add_query(qry)
     return result
示例#29
0
    def delete(self, site_url):
        """
        Deletes a SharePoint Team site

        :type site_url: str
        """
        payload = {"siteUrl": site_url}
        qry = ServiceOperationQuery(self, "Delete", None, payload)
        self.context.add_query(qry)
    def remove_site(self, site_url):
        """Deletes the site with the specified URL

        :param str site_url: A string representing the URL of the site.
        """
        result = SpoOperation(self.context)
        qry = ServiceOperationQuery(self, "removeSite", [site_url], None, None,
                                    result)
        self.context.add_query(qry)
        return result