def __init__(self, body, subject, to, from_address=None, cc=None, bcc=None, additional_headers=None): """ Specifies the definition of the email to send which includes both the message fields and body :param str body: Specifies the message body to send. :param str subject: Specifies the Subject field of the e-mail. :param list[str] to: Specifies the To field of the email. :param str or None from_address: Specifies the From field of the email. :param list[str] or None cc: Specifies the carbon copy (cc) recipients of the email. :param list[str] or None bcc: Specifies the blind carbon copy (bcc) recipients of the email :param dict or None additional_headers: """ super(EmailProperties, self).__init__() self.Body = body self.Subject = subject self.From = from_address self.To = ClientValueCollection(str, to) self.CC = ClientValueCollection(str, cc) self.BCC = ClientValueCollection(str, bcc) self.AdditionalHeaders = additional_headers
def bulk_validate_update_list_items(self, item_ids, form_values, new_document_update=True, checkin_comment=None, folder_path=None): """ Validate and update multiple list items. :param list[int] item_ids: A collection of item Ids that need to be updated with the same formValues. :param dict form_values: A collection of field internal names and values for the given field. If the collection is empty, no update will take place. :param bool new_document_update: Indicates whether the list item is a document being updated after upload. A value of "true" means yes. :param str checkin_comment: The comment of check in if any. It's only applicable when the item is checked out. :param str folder_path: Decoded path of the folder where the items belong to. If not provided, the server will try to find items to update under root folder. """ result = ClientValueCollection(ListItemFormUpdateValue) params = { "itemIds": item_ids, "formValues": ClientValueCollection(ListItemFormUpdateValue, form_values), "bNewDocumentUpdate": new_document_update, "checkInComment": checkin_comment, "folderPath": folder_path } qry = ServiceOperationQuery(self, "BulkValidateUpdateListItems", None, params, None, result) self.context.add_query(qry) return result
def bulk_validate_update_list_items(self, item_ids, form_values, new_document_update=True, checkin_comment=None, folder_path=None): """ :param list[int] item_ids: :param dict form_values: :param bool new_document_update: :param str checkin_comment: :param str folder_path: """ result = ClientValueCollection(ListItemFormUpdateValue) params = { "itemIds": item_ids, "formValues": ClientValueCollection(ListItemFormUpdateValue, form_values), "bNewDocumentUpdate": new_document_update, "checkInComment": checkin_comment, "folderPath": folder_path } qry = ServiceOperationQuery(self, "BulkValidateUpdateListItems", None, params, None, result) self.context.add_query(qry) return result
def add(self, name, parent_group=None): """Create a new set object. :param office365.onedrive.termstore.group.Group parent_group: The parent group that contains the set. :param str name: Default name (in en-US localization). """ return_type = Set(self.context) self.add_child(return_type) def _group_loaded(set_create_info): qry = CreateEntityQuery(self, set_create_info, return_type) self.context.add_query(qry) if self._parent_group is not None: props = { "localizedNames": ClientValueCollection(LocalizedName, [LocalizedName(name)]) } self._parent_group.ensure_property("id", _group_loaded, props) elif parent_group is not None: props = { "parentGroup": { "id": parent_group.id }, "localizedNames": ClientValueCollection(LocalizedName, [LocalizedName(name)]) } parent_group.ensure_property("id", _group_loaded, props) else: raise TypeError("Parameter 'parent_group' is not set") return return_type
def update_document_sharing_info( self, resource_address, user_role_assignments, validate_existing_permissions, additive_mode, send_server_managed_notification, custom_message, include_anonymous_links_in_notification, propagate_acl): """ This method allows a caller with the 'ManagePermission' permission to update sharing information about a document to enable document sharing with a set of users. It returns an array of UserSharingResult (section 3.2.5.190) elements where each element contains the sharing status for each user. :param str resource_address: A URL that points to a securable object, which can be a document, folder or the root folder of a document library. :param list[UserRoleAssignment] user_role_assignments:An array of recipients and assigned roles on the securable object pointed to by the resourceAddress parameter. :param bool validate_existing_permissions: A Boolean flag indicating how to honor a requested permission for a user. If this value is "true", the protocol server will not grant the requested permission if a user already has sufficient permissions, and if this value is "false", the protocol server will grant the requested permission whether or not a user already has the same or more permissions. This parameter is applicable only when the parameter additiveMode is set to true. :param bool additive_mode: A Boolean flag indicating whether the permission setting uses the additive or strict mode. If this value is "true", the permission setting uses the additive mode, which means that the specified permission will be added to the user's current list of permissions if it is not there already, and if this value is "false", the permission setting uses the strict mode, which means that the specified permission will replace the user's current permissions. :param bool send_server_managed_notification: A Boolean flag to indicate whether or not to generate an email notification to each recipient in the "userRoleAssignments" array after the document update is completed successfully. If this value is "true", the protocol server will send an email notification if an email server is configured, and if the value is "false", no email notification will be sent. :param str custom_message: A custom message to be included in the email notification. :param bool include_anonymous_links_in_notification: A Boolean flag that indicates whether or not to include anonymous access links in the email notification to each recipient in the userRoleAssignments array after the document update is completed successfully. If the value is "true", the protocol server will include an anonymous access link in the email notification, and if the value is "false", no link will be included. :param bool propagate_acl: A flag to determine if permissions SHOULD be pushed to items with unique permission. """ result = ClientResult(self.context, ClientValueCollection(UserSharingResult)) payload = { "resourceAddress": resource_address, "userRoleAssignments": ClientValueCollection(UserRoleAssignment, user_role_assignments), "validateExistingPermissions": validate_existing_permissions, "additiveMode": additive_mode, "sendServerManagedNotification": send_server_managed_notification, "customMessage": custom_message, "includeAnonymousLinksInNotification": include_anonymous_links_in_notification, "propagateAcl": propagate_acl } qry = ServiceOperationQuery(self, "UpdateDocumentSharingInfo", None, payload, None, result) qry.static = True self.context.add_query(qry) return result
def __init__(self, body, subject, to, from_address=None, cc=None, bcc=None, additional_headers=None): """ :param str body: :param str subject: :param list[str] to: :param str or None from_address: :param list[str] or None cc: :param list[str] or None bcc: :param dict or None additional_headers: """ super(EmailProperties, self).__init__() self.Body = body self.Subject = subject self.From = from_address self.To = ClientValueCollection(str, to) self.CC = ClientValueCollection(str, cc) self.BCC = ClientValueCollection(str, bcc) self.AdditionalHeaders = additional_headers
def __init__(self, people_names=None): """ :param list[str] people_names: People names suggested for the user query. MUST be null if ShowPeopleNameSuggestions in properties input element is set to false. """ self.PeopleNames = StringCollection(people_names) self.PersonalResults = ClientValueCollection(PersonalResultSuggestion) self.PopularResults = ClientValueCollection(PersonalResultSuggestion) self.Queries = ClientValueCollection(QuerySuggestionQuery)
def __init__(self, site_id, emails=None, names=None): """ :type emails: List[str] or None :type names: List[str] or None :type site_id: str or None """ super().__init__() self.secondaryAdministratorEmails = ClientValueCollection(str, emails) self.secondaryAdministratorLoginNames = ClientValueCollection(str, names) self.siteId = site_id
def test_14_get_entity_type_name(self): str_col = ClientValueCollection(str, []) self.assertEqual(str_col.entity_type_name, "Collection(Edm.String)") type_item = SecondaryAdministratorsFieldsData(None, []) self.assertEqual(type_item.entity_type_name, "Microsoft.Online.SharePoint.TenantAdministration.SecondaryAdministratorsFieldsData") type_col = ClientValueCollection(SecondaryAdministratorsFieldsData) expected_type = "Collection(Microsoft.Online.SharePoint.TenantAdministration.SecondaryAdministratorsFieldsData)" self.assertEqual(type_col.entity_type_name, expected_type)
class GroupCreationParams(ClientValue): def __init__(self, classification="", description=""): super(GroupCreationParams, self).__init__() self.Classification = classification self.Description = description self.CreationOptions = ClientValueCollection(str) self.CreationOptions.add("SPSiteLanguage:1033") @property def entity_type_name(self): return "Microsoft.SharePoint.Portal.GroupCreationParams"
def to_json(self): payload_orig = super(ListItem, self).to_json() payload = {} for k, v in payload_orig.items(): if isinstance(v, FieldMultiLookupValue): collection = ClientValueCollection(int) [collection.add(lv.LookupId) for lv in v] payload["{name}Id".format(name=k)] = collection elif isinstance(v, FieldLookupValue): payload["{name}Id".format(name=k)] = v.LookupId else: payload[k] = v return payload
def assign_license(self, add_licenses, remove_licenses): """ Add or remove licenses on the user. :param list[str] remove_licenses: A collection of skuIds that identify the licenses to remove. :param list[AssignedLicense] add_licenses: A collection of assignedLicense objects that specify the licenses to add. """ params = { "addLicenses": ClientValueCollection(AssignedLicense, add_licenses), "removeLicenses": ClientValueCollection(str, remove_licenses) } qry = ServiceOperationQuery(self, "assignLicense", None, params, None, self) self.context.add_query(qry) return self
def get_all_rules(self): return_type = ClientResult(self.context, ClientValueCollection(SPListRule)) qry = ServiceOperationQuery(self, "GetAllRules", None, None, None, return_type) self.context.add_query(qry) return return_type
def query(self, query_string, entity_types=None): """ Runs the query specified in the request body. Search results are provided in the response. :param str query_string: Contains the query terms. :param list[str] entity_types: One or more types of resources expected in the response. Possible values are: list, site, listItem, message, event, drive, driveItem, externalItem. """ search_request = SearchRequest(query=SearchQuery(query_string), entity_types=entity_types) payload = { "requests": ClientValueCollection(SearchRequest, [search_request]) } return_type = ClientResult(self.context, ClientValueCollection(SearchResponse)) qry = ServiceOperationQuery(self, "query", None, payload, None, return_type) self.context.add_query(qry) return return_type
def roles(self, value): """ Sets the type of permission :type value: list[str] """ self.set_property("roles", ClientValueCollection(str, value))
def grant(self, recipients, roles): """ Grant users access to a link represented by a permission. :param list[str] recipients: A collection of recipients who will receive access. :param list[str] roles: If the link is an "existing access" link, specifies roles to be granted to the users. Otherwise must match the role of the link. """ payload = { "recipients": ClientValueCollection(DriveRecipient, [DriveRecipient.from_email(r) for r in recipients]), "roles": ClientValueCollection(str, roles) } return_type = EntityCollection(self.context, Permission, ResourcePath("permissions", self.resource_path)) qry = ServiceOperationQuery(self, "grant", None, payload, None, return_type) self.context.add_query(qry) return return_type
def update_document_sharing_info( self, resourceAddress, userRoleAssignments, validateExistingPermissions, additiveMode, sendServerManagedNotification, customMessage, includeAnonymousLinksInNotification, propagateAcl): """ :param str resourceAddress: :param ClientValueCollection userRoleAssignments: :param bool validateExistingPermissions: :param bool additiveMode: :param bool sendServerManagedNotification: :param str customMessage: :param bool includeAnonymousLinksInNotification: :param bool propagateAcl: """ result = ClientResult(self.context, ClientValueCollection(UserSharingResult)) payload = { "resourceAddress": resourceAddress, "userRoleAssignments": userRoleAssignments, "validateExistingPermissions": validateExistingPermissions, "additiveMode": additiveMode, "sendServerManagedNotification": sendServerManagedNotification, "customMessage": customMessage, "includeAnonymousLinksInNotification": includeAnonymousLinksInNotification, "propagateAcl": propagateAcl } qry = ServiceOperationQuery(self, "UpdateDocumentSharingInfo", None, payload, None, result) qry.static = True self.context.add_query(qry) return result
def validate_update_list_item(self, form_values, new_document_update=False, checkin_comment=None, dates_in_utc=None): """Validates and sets the values of the specified collection of fields for the list item. :param dict form_values: Specifies a collection of field internal names and values for the given field :param dict new_document_update: Specifies whether the list item is a document being updated after upload. :param str checkin_comment: Check-in comment, if any. This parameter is only applicable when the list item is checked out. :param bool or None dates_in_utc: """ normalized_form_values = [ ListItemFormUpdateValue(k, v) for k, v in form_values.items() ] payload = { "formValues": normalized_form_values, "bNewDocumentUpdate": new_document_update, "checkInComment": checkin_comment, "datesInUTC": dates_in_utc } result = ClientResult(self.context, ClientValueCollection(ListItemFormUpdateValue)) qry = ServiceOperationQuery(self, "ValidateUpdateListItem", None, payload, None, result) self.context.add_query(qry) return result
def get_home_sites_details(self): return_type = ClientResult(self.context, ClientValueCollection(HomeSitesDetails)) qry = ServiceOperationQuery(self, "GetHomeSitesDetails", None, None, None, return_type) self.context.add_query(qry) return return_type
def search_principals_using_context_web(context, s_input, sources, scopes, maxCount, groupName=None): """ :type s_input: str :type sources: int :type scopes: int :type maxCount: int :type groupName: str or None :type context: office365.sharepoint.client_context.ClientContext """ result = ClientResult(ClientValueCollection(str)) utility = Utility(context) params = { "input": s_input, "sources": sources, "scopes": scopes, "maxCount": maxCount, "groupName": groupName } qry = ServiceOperationQuery(utility, "SearchPrincipalsUsingContextWeb", params, None, None, result) qry.static = True context.add_query(qry) return result
def get_schedule(self, schedules, startTime=None, endTime=None, availabilityViewInterval=30): """ Get the free/busy availability information for a collection of users, distributions lists, or resources (rooms or equipment) for a specified time period. :param datetime.datetime endTime: The date, time, and time zone that the period ends. :param int availabilityViewInterval: Represents the duration of a time slot in an availabilityView in the response. The default is 30 minutes, minimum is 5, maximum is 1440. Optional. :param datetime.datetime startTime: The date, time, and time zone that the period starts. :param list[str] schedules: A collection of SMTP addresses of users, distribution lists, or resources to get availability information for. """ payload = { "schedules": schedules, "startTime": DateTimeTimeZone.parse(startTime), "endTime": DateTimeTimeZone.parse(endTime), "availabilityViewInterval": availabilityViewInterval } result = ClientValueCollection(ScheduleInformation) qry = ServiceOperationQuery(self, "getSchedule", None, payload, None, result) self.context.add_query(qry) return result
def __init__(self, hits=None, more_results_available=None, total=None): super(SearchHitsContainer, self).__init__() if hits is None: hits = ClientValueCollection(SearchHit) self.hits = hits self.moreResultsAvailable = more_results_available self.total = total
def get_client_side_web_parts(self, project, includeErrors=False): result = ClientValueCollection(SPClientSideComponentQueryResult) params = {"includeErrors": includeErrors, "project": project} qry = ServiceOperationQuery(self, "getClientSideWebParts", None, params, None, result) self.context.add_query(qry) return result
def users_added_to_group(self): """ Gets the list of users being added to the SharePoint permissions group. :rtype: ClientValueCollection """ return self.properties.get("UsersAddedToGroup", ClientValueCollection(UserSharingResult))
def identifier_uris(self): """ The URIs that identify the application within its Azure AD tenant, or within a verified custom domain if the application is multi-tenant. For more information see Application Objects and Service Principal Objects. The any operator is required for filter expressions on multi-valued properties. """ return self.properties.get('identifierUris', ClientValueCollection(str))
def find_meeting_times(self, attendees=None, location_constraint=None): """ Suggest meeting times and locations based on organizer and attendee availability, and time or location constraints specified as parameters. If findMeetingTimes cannot return any meeting suggestions, the response would indicate a reason in the emptySuggestionsReason property. Based on this value, you can better adjust the parameters and call findMeetingTimes again. The algorithm used to suggest meeting times and locations undergoes fine-tuning from time to time. In scenarios like test environments where the input parameters and calendar data remain static, expect that the suggested results may differ over time. :param list[AttendeeBase] or None attendees: A collection of attendees or resources for the meeting. Since findMeetingTimes assumes that any attendee who is a person is always required, specify required for a person and resource for a resource in the corresponding type property. An empty collection causes findMeetingTimes to look for free time slots for only the organizer. Optional. :param office365.outlook.calendar.location_constraint.LocationConstraint or None location_constraint: The organizer's requirements about the meeting location, such as whether a suggestion for a meeting location is required, or there are specific locations only where the meeting can take place. Optional. """ payload = { "attendees": ClientValueCollection(AttendeeBase, attendees), "locationConstraint": location_constraint } result = ClientResult(self.context, MeetingTimeSuggestionsResult()) qry = ServiceOperationQuery(self, "findMeetingTimes", None, payload, None, result) self.context.add_query(qry) return result
def __init__(self, query, entity_types=None, fields=None, search_from=None, sort_properties=None, content_sources=None): """ :param office365.search.query.SearchQuery query: Contains the query terms. :param list[str] entity_types: One or more types of resources expected in the response. Possible values are: list, site, listItem, message, event, drive, driveItem, externalItem. See known limitations for those combinations of two or more entity types that are supported in the same search request. :param list[str] fields: Contains the fields to be returned for each resource object specified in entityTypes, allowing customization of the fields returned by default; otherwise, including additional fields such as custom managed properties from SharePoint and OneDrive, or custom fields in externalItem from the content that Microsoft Graph connectors bring in. The fields property can use the semantic labels applied to properties. For example, if a property is labeled as title, you can retrieve it using the following syntax: label_title. :param int search_from: Specifies the offset for the search results. Offset 0 returns the very first result. :param list[SortProperty] sort_properties: Contains the ordered collection of fields and direction to sort results. There can be at most 5 sort properties in the collection. :param list[str] content_sources: Contains the connection to be targeted. """ super(SearchRequest, self).__init__() self.query = query self.entityTypes = entity_types self.fields = fields self.search_from = search_from self.sortProperties = ClientValueCollection(SortProperty, sort_properties) self.contentSources = StringCollection(content_sources)
def __init__(self, title, field_type_kind, description=None, lookup_list_id=None, lookup_field_name=None, lookup_web_id=None, required=False): """ Represents metadata about fields creation. :type lookup_web_id: str :type required: bool :type lookup_field_name: str :type lookup_list_id: str :type title: str :type field_type_kind: int :type description: str or None """ super(FieldCreationInformation, self).__init__() self.Title = title self.FieldTypeKind = field_type_kind self.Description = description self.Choices = ClientValueCollection(str) \ if field_type_kind == FieldType.MultiChoice or field_type_kind == FieldType.Choice else None self.LookupListId = lookup_list_id self.LookupFieldName = lookup_field_name self.LookupWebId = lookup_web_id self.Required = required
def set_property(self, name, value, persist_changes=True): if persist_changes: if isinstance(value, TaxonomyFieldValueCollection): self._set_taxonomy_field_value(name, value) elif isinstance(value, FieldMultiLookupValue): collection = ClientValueCollection(int, [v.LookupId for v in value]) super(ListItem, self).set_property("{name}Id".format(name=name), collection) super(ListItem, self).set_property(name, value, False) elif isinstance(value, FieldLookupValue): super(ListItem, self).set_property("{name}Id".format(name=name), value.LookupId) super(ListItem, self).set_property(name, value, False) else: super(ListItem, self).set_property(name, value, persist_changes) else: super(ListItem, self).set_property(name, value, persist_changes) # fallback: create a new resource path if self._resource_path is None: if name == "Id" and self._parent_collection is not None: self._resource_path = ResourcePathServiceOperation( "getItemById", [value], self._parent_collection.resource_path.parent) return self
def test_14_get_entity_type_name(self): type_name = ODataType.resolve_type([""]) self.assertEqual(type_name, "Collection(Edm.String)") guid_coll = GuidCollection() self.assertEqual(guid_coll.entity_type_name, "Collection(Edm.Guid)") custom_type_name = ODataType.resolve_type( SecondaryAdministratorsFieldsData()) self.assertEqual( custom_type_name, "Microsoft.Online.SharePoint.TenantAdministration.SecondaryAdministratorsFieldsData" ) str_type_name = ODataType.resolve_type(StringCollection()) self.assertEqual(str_type_name, "Collection(Edm.String)") str_col = StringCollection() self.assertEqual(str_col.entity_type_name, "Collection(Edm.String)") type_item = SecondaryAdministratorsFieldsData() self.assertEqual( type_item.entity_type_name, "Microsoft.Online.SharePoint.TenantAdministration.SecondaryAdministratorsFieldsData" ) type_col = ClientValueCollection(SecondaryAdministratorsFieldsData) expected_type = "Collection(Microsoft.Online.SharePoint.TenantAdministration.SecondaryAdministratorsFieldsData)" self.assertEqual(type_col.entity_type_name, expected_type)