mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Check google calendar API scope to determine if write access is enabled (#84749)
* Check google calendar API scope to determine if write access is enabled * Add API scope for calendar service for creating events
This commit is contained in:
parent
bd9f03010f
commit
2049993941
@ -63,6 +63,7 @@ from . import (
|
|||||||
load_config,
|
load_config,
|
||||||
update_config,
|
update_config,
|
||||||
)
|
)
|
||||||
|
from .api import get_feature_access
|
||||||
from .const import (
|
from .const import (
|
||||||
DATA_SERVICE,
|
DATA_SERVICE,
|
||||||
DATA_STORE,
|
DATA_STORE,
|
||||||
@ -74,6 +75,7 @@ from .const import (
|
|||||||
EVENT_START_DATE,
|
EVENT_START_DATE,
|
||||||
EVENT_START_DATETIME,
|
EVENT_START_DATETIME,
|
||||||
EVENT_TYPES_CONF,
|
EVENT_TYPES_CONF,
|
||||||
|
FeatureAccess,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -213,7 +215,10 @@ async def async_setup_entry(
|
|||||||
# Prefer calendar sync down of resources when possible. However, sync does not work
|
# Prefer calendar sync down of resources when possible. However, sync does not work
|
||||||
# for search. Also free-busy calendars denormalize recurring events as individual
|
# for search. Also free-busy calendars denormalize recurring events as individual
|
||||||
# events which is not efficient for sync
|
# events which is not efficient for sync
|
||||||
support_write = calendar_item.access_role.is_writer
|
support_write = (
|
||||||
|
calendar_item.access_role.is_writer
|
||||||
|
and get_feature_access(hass, config_entry) is FeatureAccess.read_write
|
||||||
|
)
|
||||||
if (
|
if (
|
||||||
search := data.get(CONF_SEARCH)
|
search := data.get(CONF_SEARCH)
|
||||||
or calendar_item.access_role == AccessRole.FREE_BUSY_READER
|
or calendar_item.access_role == AccessRole.FREE_BUSY_READER
|
||||||
@ -265,7 +270,10 @@ async def async_setup_entry(
|
|||||||
await hass.async_add_executor_job(append_calendars_to_config)
|
await hass.async_add_executor_job(append_calendars_to_config)
|
||||||
|
|
||||||
platform = entity_platform.async_get_current_platform()
|
platform = entity_platform.async_get_current_platform()
|
||||||
if any(calendar_item.access_role.is_writer for calendar_item in result.items):
|
if (
|
||||||
|
any(calendar_item.access_role.is_writer for calendar_item in result.items)
|
||||||
|
and get_feature_access(hass, config_entry) is FeatureAccess.read_write
|
||||||
|
):
|
||||||
platform.async_register_entity_service(
|
platform.async_register_entity_service(
|
||||||
SERVICE_CREATE_EVENT,
|
SERVICE_CREATE_EVENT,
|
||||||
CREATE_EVENT_SCHEMA,
|
CREATE_EVENT_SCHEMA,
|
||||||
|
@ -14,7 +14,7 @@ from aiohttp.client_exceptions import ClientError
|
|||||||
from gcal_sync.auth import API_BASE_URL
|
from gcal_sync.auth import API_BASE_URL
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.google.const import DOMAIN
|
from homeassistant.components.google.const import CONF_CALENDAR_ACCESS, DOMAIN
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON, Platform
|
from homeassistant.const import STATE_OFF, STATE_ON, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
@ -1054,8 +1054,24 @@ async def test_websocket_delete_recurring_event_instance(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"calendar_access_role",
|
"calendar_access_role,token_scopes,config_entry_options",
|
||||||
["reader"],
|
[
|
||||||
|
(
|
||||||
|
"reader",
|
||||||
|
["https://www.googleapis.com/auth/calendar"],
|
||||||
|
{CONF_CALENDAR_ACCESS: "read_write"},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"reader",
|
||||||
|
["https://www.googleapis.com/auth/calendar.readonly"],
|
||||||
|
{CONF_CALENDAR_ACCESS: "read_only"},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"owner",
|
||||||
|
["https://www.googleapis.com/auth/calendar.readonly"],
|
||||||
|
{CONF_CALENDAR_ACCESS: "read_only"},
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
async def test_readonly_websocket_create(
|
async def test_readonly_websocket_create(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user