Skip to content

Commit

Permalink
#693 support for folder coloring methods
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Feb 29, 2024
1 parent bcd5c76 commit 639007b
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 22 deletions.
8 changes: 5 additions & 3 deletions examples/outlook/events/create.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""
Create an event in the current user's default calendar
https://learn.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0&tabs=http
https://learn.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0
"""

from datetime import datetime, timedelta

from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_username_password
from tests import test_client_id, test_password, test_tenant, test_username

when = datetime.utcnow() + timedelta(days=1)
client = GraphClient(acquire_token_by_username_password)
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
new_event = client.me.calendar.events.add(
subject="Let's go for lunch",
body="Does mid month work for you?",
Expand Down
15 changes: 15 additions & 0 deletions examples/sharepoint/folders/create_with_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Demonstrates how to create a folder with a color
"""
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.folders.coloring_information import FolderColors
from tests import test_team_site_url, test_user_credentials

ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)


root_folder = ctx.web.default_document_library().root_folder
folder = root_folder.folders.add(
"Report123", color_hex=FolderColors.DarkGreen
).execute_query()
print("Folder : {0} has been created".format(folder.serverRelativeUrl))
14 changes: 14 additions & 0 deletions examples/sharepoint/listitems/system_update2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys

from office365.sharepoint.client_context import ClientContext
from tests import test_client_credentials, test_site_url

ctx = ClientContext(test_site_url).with_credentials(test_client_credentials)

target_list = ctx.web.lists.get_by_title("Documents")
items = target_list.items.get().top(1).execute_query()
if len(items) == 0:
sys.exit("No items were found")

item = items[0]
item.system_update().execute_query()
22 changes: 22 additions & 0 deletions examples/sharepoint/lists/get_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Gets site changes
"""
from office365.sharepoint.changes.query import ChangeQuery
from office365.sharepoint.client_context import ClientContext
from tests import test_client_credentials, test_team_site_url

client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
query = ChangeQuery(
item=True,
add=False,
update=False,
system_update=False,
delete_object=True,
role_assignment_add=False,
role_assignment_delete=False,
)

list_title = "Documents"
result = client.web.lists.get_by_title(list_title).get_changes(query).execute_query()
for change in result:
print(change.properties)
14 changes: 14 additions & 0 deletions examples/sharepoint/sharing/create_anon_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Demonstrates creating an anonymous sharing link for a file
"""
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.sharing.links.kind import SharingLinkKind
from tests import test_team_site_url, test_user_credentials

ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)

remote_file = ctx.web.get_file_by_server_relative_url(
"Shared Documents/Financial Sample.xlsx"
)
result = remote_file.share_link(SharingLinkKind.AnonymousView).execute_query()
print(result.value)
2 changes: 1 addition & 1 deletion office365/sharepoint/activities/facets/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def __init__(self, name=None):

@property
def entity_type_name(self):
return "Microsoft.SharePoint.Activities.CreateFacet"
return "Microsoft.SharePoint.Activities.DeleteFacet"
5 changes: 2 additions & 3 deletions office365/sharepoint/activities/tracked_item_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
from office365.sharepoint.activities.tracked_item_updates_request import (
TrackedItemUpdatesRequest,
)
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.entity import Entity


class TrackedItemService(Entity):
@staticmethod
def get_tracked_item_updates_for_user(context):
"""
:type context: office365.sharepoint.client_context.ClientContext
"""
# type: (ClientContext) -> ClientResult[str]
return_type = ClientResult(context)
payload = {"request": TrackedItemUpdatesRequest()}
qry = ServiceOperationQuery(
Expand Down
27 changes: 22 additions & 5 deletions office365/sharepoint/folders/collection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os

from office365.runtime.paths.service_operation import ServiceOperationPath
from office365.runtime.paths.v3.entity import EntityPath
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity_collection import EntityCollection
from office365.sharepoint.folders.coloring_information import FolderColoringInformation
from office365.sharepoint.folders.folder import Folder
from office365.sharepoint.types.resource_path import ResourcePath as SPResPath

Expand Down Expand Up @@ -42,14 +45,28 @@ def ensure_path(self, path):
folder = folder.add(name)
return folder

def add(self, name):
def add(self, name, color_hex=None):
"""Adds the folder that is located at the specified URL to the collection.
:param str name: Specifies the Name of the folder.
:param str name: Specifies the Name or Path of the folder.
:param str color_hex: Specifies the color of the folder.
"""
return_type = Folder(self.context, EntityPath(name, self.resource_path))
self.add_child(return_type)
qry = ServiceOperationQuery(self, "Add", [name], None, None, return_type)
self.context.add_query(qry)
if color_hex:

def _add_coloring():
path = os.path.join(
self.parent.properties.get("ServerRelativeUrl"), name
)
coloring_info = FolderColoringInformation(color_hex=color_hex)
self.context.folder_coloring.create_folder(
path, coloring_info, return_type=return_type
)

self.parent.ensure_property("ServerRelativeUrl", _add_coloring)
else:
self.add_child(return_type)
qry = ServiceOperationQuery(self, "Add", [name], None, None, return_type)
self.context.add_query(qry)
return return_type

def get_by_url(self, url):
Expand Down
16 changes: 7 additions & 9 deletions office365/sharepoint/folders/coloring.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from office365.sharepoint.entity import Entity
from office365.sharepoint.folders.coloring_information import FolderColoringInformation
from office365.sharepoint.folders.folder import Folder
from office365.sharepoint.types.resource_path import ResourcePath as SPResPath


class FolderColoring(Entity):
Expand All @@ -12,22 +13,19 @@ class FolderColoring(Entity):
def create_folder(
self,
decoded_url,
ensure_unique_file_name=True,
overwrite=True,
coloring_information=None,
coloring_information=FolderColoringInformation(color_hex="1"),
return_type=None,
):
"""
:param str decoded_url:
:param bool ensure_unique_file_name:
:param bool overwrite:
:param FolderColoringInformation coloring_information:
:param Folder return_type: Return type
"""
return_type = Folder(self.context)
if return_type is None:
return_type = Folder(self.context)

payload = {
"DecodedUrl": decoded_url,
"EnsureUniqueFileName": ensure_unique_file_name,
"Overwrite": overwrite,
"path": SPResPath(decoded_url),
"coloringInformation": coloring_information,
}
qry = ServiceOperationQuery(
Expand Down
38 changes: 38 additions & 0 deletions office365/sharepoint/folders/coloring_information.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
from office365.runtime.client_value import ClientValue


class FolderColors(object):
Yellow = "#FFCE3C"

Grey = "#B0B7BA"

DarkRed = "#E73E29"

LightRed = "#FFBCB2"

DarkOrange = "#EE7110"

LightOrange = "#FFBF84"

DarkGreen = "#3F9F4A"

LightGreen = "#8ED290"

DarkTeal = "#27938E"

LightTeal = "#7AD1CD"

DarkBlue = "#1E84D0"

LightBlue = "#86C8F7"

DarkPurple = "#9A61C7"

LightPurple = "#D4AFF6"

DarkPink = "#CC53B4"

LightPink = "#F7AAE7"


class FolderColoringInformation(ClientValue):
""""""

Expand All @@ -13,3 +47,7 @@ def __init__(self, color_hex=None, color_tag=None, emoji=None):
self.ColorHex = color_hex
self.ColorTag = color_tag
self.Emoji = emoji

@property
def entity_type_name(self):
return "SP.FolderColoringInformation"
4 changes: 3 additions & 1 deletion office365/sharepoint/folders/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ def folders(self):

return self.properties.get(
"Folders",
FolderCollection(self.context, ResourcePath("Folders", self.resource_path)),
FolderCollection(
self.context, ResourcePath("Folders", self.resource_path), self
),
)

@property
Expand Down
6 changes: 6 additions & 0 deletions office365/sharepoint/lists/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,12 @@ def disable_grid_editing(self):
# type: () -> Optional[bool]
return self.properties.get("DisableGridEditing", None)

@property
def document_template_url(self):
# type: () -> Optional[str]
"""Specifies the URL of the document template assigned to the list."""
return self.properties.get("DocumentTemplateUrl", None)

@property
def effective_base_permissions(self):
"""
Expand Down
11 changes: 11 additions & 0 deletions office365/sharepoint/tenant/insights/report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from office365.sharepoint.tenant.insights.report_metadata import (
SPTenantIBInsightsReportMetadata,
)


class SPTenantIBInsightsReport(SPTenantIBInsightsReportMetadata):
""" """

@property
def entity_type_name(self):
return "Microsoft.SharePoint.Insights.SPTenantIBInsightsReport"
5 changes: 5 additions & 0 deletions office365/sharepoint/tenant/insights/report_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.sharepoint.entity import Entity


class SPTenantIBInsightsReportManager(Entity):
""" """
5 changes: 5 additions & 0 deletions office365/sharepoint/tenant/insights/report_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.sharepoint.entity import Entity


class SPTenantIBInsightsReportMetadata(Entity):
""" """

0 comments on commit 639007b

Please sign in to comment.