Skip to content

Commit

Permalink
Add permission granularity for ToDO Tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Apr 3, 2023
1 parent 822c7ab commit 73cd260
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
11 changes: 7 additions & 4 deletions custom_components/o365/classes/taskssensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ def __init__(
super().__init__(coordinator, name, entity_id, SENSOR_TODO, unique_id)
self.todo = todo
self._show_completed = show_completed
if show_completed:
self.query = self.todo.new_query("status")
else:
self.query = self.todo.new_query("status").unequal("completed")
self.query = self.todo.new_query()
if not show_completed:
self.query = self.query.on_attribute("status").unequal("completed")

# self.query.chain("and").on_attribute("duedatetime").less_equal(
# datetime.now(timezone.utc)
# )
self._config = config
self.task_last_created = dt.utcnow() - timedelta(minutes=5)
self.task_last_completed = dt.utcnow() - timedelta(minutes=5)
Expand Down
9 changes: 6 additions & 3 deletions custom_components/o365/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
)
from homeassistant.const import CONF_ENABLED, CONF_NAME

from O365.calendar import AttendeeType # pylint: disable=no-name-in-module
from O365.calendar import EventSensitivity # pylint: disable=no-name-in-module
from O365.calendar import EventShowAs # pylint: disable=no-name-in-module
from O365.calendar import (
AttendeeType, # pylint: disable=no-name-in-module
EventSensitivity, # pylint: disable=no-name-in-module
EventShowAs, # pylint: disable=no-name-in-module
)
from O365.mailbox import ExternalAudience # pylint: disable=no-name-in-module
from O365.utils import ImportanceLevel # pylint: disable=no-name-in-module

Expand Down Expand Up @@ -132,6 +134,7 @@
{
vol.Required(CONF_ENABLED, default=False): bool,
vol.Optional(CONF_TRACK_NEW, default=True): bool,
vol.Optional(CONF_ENABLE_UPDATE, default=False): bool,
}
)

Expand Down
9 changes: 5 additions & 4 deletions custom_components/o365/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,12 @@ async def _async_setup_register_services(hass, config):


async def _async_setup_task_services(hass, config):
if not config.get(CONF_ENABLE_UPDATE):
return

todo_sensors = config.get(CONF_TODO_SENSORS)
if not todo_sensors or not todo_sensors.get(CONF_ENABLED):
if (
not todo_sensors
or not todo_sensors.get(CONF_ENABLED)
or not todo_sensors.get(CONF_ENABLE_UPDATE)
):
return

sensor_services = SensorServices(hass)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/o365/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def build_requested_permissions(config):
if len(chat_sensors) > 0:
scope.append(PERM_CHAT_READ)
if todo_sensors and todo_sensors.get(CONF_ENABLED, False):
if enable_update:
if todo_sensors[CONF_ENABLE_UPDATE]:
scope.append(PERM_TASKS_READWRITE)
else:
scope.append(PERM_TASKS_READ)
Expand Down
3 changes: 2 additions & 1 deletion docs/installation_and_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ o365:
client_id: "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
client_secret: "xx.xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
alt_auth_method: False
enable_update: True
enable_update: False
email_sensor:
- name: inbox
max_items: 2
Expand Down Expand Up @@ -163,6 +163,7 @@ Key | Type | Required | Description
Key | Type | Required | Description
-- | -- | -- | --
`enabled` | `boolean` | `True` | True=Enables To-Do sensors, **False**=Disables To-Do sensors.
`enable_update` | `boolean` | `False` | If True (**default is False**), this will enable the services to create/update/delete tasks

#### auto_reply_sensors

Expand Down
2 changes: 1 addition & 1 deletion docs/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Under "API Permissions" click Add a permission, then Microsoft Graph, then Deleg
* Group Calendar - For a manually added Group calendar
* AutoReply - For Auto reply/Out of Office message configuration

If you intend to use update functionality, then set [enable_update](./installation_and_configuration.md#configuration_variables) to `true`. Then for any sensor type, add the relevant `ReadWrite` permission as denoted by a `Y` in the update column.
If you intend to send emails use calendar update functionality, then set [enable_update](./installation_and_configuration.md#configuration_variables) at the top level to `true`. For Todo sensors set [enable_update](installation_and_configuration.md#todo_sensors) to true. Then for any sensor type, add the relevant `ReadWrite` permission as denoted by a `Y` in the update column.


| Feature | Permissions | Update | O365 Description | Notes |
Expand Down

0 comments on commit 73cd260

Please sign in to comment.