indico-plugin-mcp 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- indico_mcp/__init__.py +8 -0
- indico_mcp/core.py +420 -0
- indico_mcp/core_abstracts.py +291 -0
- indico_mcp/core_account.py +169 -0
- indico_mcp/core_actions.py +12 -0
- indico_mcp/core_materials.py +235 -0
- indico_mcp/core_schedule.py +572 -0
- indico_mcp/core_surveys.py +335 -0
- indico_mcp/endpoint.py +151 -0
- indico_mcp/event_extensions.py +727 -0
- indico_mcp/navigation.py +41 -0
- indico_mcp/plugin.py +57 -0
- indico_mcp/protocol.py +121 -0
- indico_mcp/registrations.py +680 -0
- indico_mcp/registry.py +85 -0
- indico_mcp/room_booking.py +283 -0
- indico_mcp/stsa_extensions.py +506 -0
- indico_plugin_mcp-0.1.0.dist-info/METADATA +96 -0
- indico_plugin_mcp-0.1.0.dist-info/RECORD +21 -0
- indico_plugin_mcp-0.1.0.dist-info/WHEEL +4 -0
- indico_plugin_mcp-0.1.0.dist-info/entry_points.txt +2 -0
indico_mcp/__init__.py
ADDED
indico_mcp/core.py
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
"""Tools for browsing and managing Indico categories and events."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Annotated, Literal
|
|
5
|
+
|
|
6
|
+
from indico.core.config import config
|
|
7
|
+
from indico.core.db.sqlalchemy.protection import ProtectionMode
|
|
8
|
+
from indico.core.db.sqlalchemy.util.queries import get_n_matching
|
|
9
|
+
from indico.modules.categories import Category
|
|
10
|
+
from indico.modules.categories.operations import create_category, delete_category, move_category, update_category
|
|
11
|
+
from indico.modules.categories.util import can_create_unlisted_events
|
|
12
|
+
from indico.modules.events import Event
|
|
13
|
+
from indico.modules.events.features.util import (
|
|
14
|
+
get_disallowed_features,
|
|
15
|
+
get_enabled_features,
|
|
16
|
+
get_feature_definitions,
|
|
17
|
+
set_feature_enabled,
|
|
18
|
+
)
|
|
19
|
+
from indico.modules.events.models.events import EventType
|
|
20
|
+
from indico.modules.events.notifications import notify_event_creation, notify_move_request_creation
|
|
21
|
+
from indico.modules.events.operations import (
|
|
22
|
+
create_event,
|
|
23
|
+
create_event_request,
|
|
24
|
+
lock_event,
|
|
25
|
+
unlock_event,
|
|
26
|
+
update_event,
|
|
27
|
+
update_event_type,
|
|
28
|
+
)
|
|
29
|
+
from indico.modules.events.util import track_location_changes, track_time_changes
|
|
30
|
+
from indico.modules.logs.models.entries import EventLogRealm, LogKind
|
|
31
|
+
from indico.util.string import natural_sort_key, sanitize_html
|
|
32
|
+
from pydantic import Field, StringConstraints
|
|
33
|
+
from pytz import common_timezones_set, utc
|
|
34
|
+
from werkzeug.exceptions import BadRequest, Forbidden, NotFound
|
|
35
|
+
|
|
36
|
+
ObjectID = Annotated[int, Field(ge=1, le=2147483647)]
|
|
37
|
+
CategoryID = Annotated[int, Field(ge=0, le=2147483647)]
|
|
38
|
+
PageSize = Annotated[int, Field(ge=1, le=100)]
|
|
39
|
+
Title = Annotated[str, StringConstraints(strip_whitespace=True, min_length=1, max_length=500, pattern=r'^[^\x00]*$')]
|
|
40
|
+
Description = Annotated[str, StringConstraints(max_length=50000, pattern=r'^[^\x00]*$')]
|
|
41
|
+
ShortText = Annotated[str, StringConstraints(strip_whitespace=True, max_length=500, pattern=r'^[^\x00]*$')]
|
|
42
|
+
Timestamp = Annotated[str, Field(
|
|
43
|
+
pattern=(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,6})?)?'
|
|
44
|
+
r'(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$'),
|
|
45
|
+
description='ISO 8601 date and time with an explicit UTC offset.',
|
|
46
|
+
)]
|
|
47
|
+
EventKind = Literal['lecture', 'meeting', 'conference']
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def parse_timestamp(value):
|
|
51
|
+
try:
|
|
52
|
+
dt = datetime.fromisoformat(value)
|
|
53
|
+
if dt.utcoffset() is not None:
|
|
54
|
+
return dt.astimezone(utc)
|
|
55
|
+
except (ValueError, OverflowError):
|
|
56
|
+
pass
|
|
57
|
+
raise BadRequest('Use an ISO 8601 date and time with a UTC offset.')
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def get_category(category_id):
|
|
61
|
+
category = Category.get(category_id, is_deleted=False) if category_id else Category.get_root()
|
|
62
|
+
if category is None:
|
|
63
|
+
raise NotFound('The category does not exist.')
|
|
64
|
+
return category
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def get_event(event_id):
|
|
68
|
+
event = Event.get(event_id, is_deleted=False)
|
|
69
|
+
if event is None:
|
|
70
|
+
raise NotFound('The event does not exist.')
|
|
71
|
+
return event
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def require_access(obj, user):
|
|
75
|
+
if not obj.can_access(user):
|
|
76
|
+
raise Forbidden('You do not have access to this item.')
|
|
77
|
+
return obj
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def require_manage(obj, user, permission=None):
|
|
81
|
+
if not obj.can_manage(user, permission=permission):
|
|
82
|
+
raise Forbidden('You do not have permission to manage this item.')
|
|
83
|
+
return obj
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def require_unlocked(event):
|
|
87
|
+
if event.is_locked:
|
|
88
|
+
raise Forbidden('The event is locked.')
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def require_confirmation(confirm):
|
|
92
|
+
if not confirm:
|
|
93
|
+
raise BadRequest('Confirm this action by setting confirm to true.')
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def manage_event(event_id, user, permission=None):
|
|
97
|
+
event = require_manage(get_event(event_id), user, permission=permission)
|
|
98
|
+
require_unlocked(event)
|
|
99
|
+
return event
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def get_page(query, model, after_id, limit, visible, serialize):
|
|
103
|
+
query = query.filter(model.id > after_id).order_by(None).order_by(model.id)
|
|
104
|
+
matches = get_n_matching(query, limit + 1, visible, prefetch_factor=2)
|
|
105
|
+
return {
|
|
106
|
+
'items': [serialize(item) for item in matches[:limit]],
|
|
107
|
+
'next_after_id': matches[limit - 1].id if len(matches) > limit else None,
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def serialize_category(category, user, *, detail=False):
|
|
112
|
+
result = {
|
|
113
|
+
'id': category.id,
|
|
114
|
+
'title': category.title,
|
|
115
|
+
'url': category.external_url,
|
|
116
|
+
'can_manage': category.can_manage(user),
|
|
117
|
+
'can_create_events': bool(category.can_create_events(user)),
|
|
118
|
+
}
|
|
119
|
+
if detail:
|
|
120
|
+
parent = category.parent
|
|
121
|
+
result.update(
|
|
122
|
+
description=str(category.description),
|
|
123
|
+
timezone=category.timezone,
|
|
124
|
+
parent_id=parent.id if parent is not None and parent.can_access(user) else None,
|
|
125
|
+
)
|
|
126
|
+
return result
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def serialize_event(event, user, *, detail=False):
|
|
130
|
+
category = event.category
|
|
131
|
+
result = {
|
|
132
|
+
'id': event.id,
|
|
133
|
+
'title': event.title,
|
|
134
|
+
'type': event.type_.name,
|
|
135
|
+
'url': event.external_url,
|
|
136
|
+
'category_id': category.id if category is not None and category.can_access(user) else None,
|
|
137
|
+
'start_dt': event.start_dt.isoformat(),
|
|
138
|
+
'end_dt': event.end_dt.isoformat(),
|
|
139
|
+
'timezone': event.timezone,
|
|
140
|
+
'can_manage': event.can_manage(user),
|
|
141
|
+
'is_locked': event.is_locked,
|
|
142
|
+
}
|
|
143
|
+
if detail:
|
|
144
|
+
location = event.location_data
|
|
145
|
+
result.update(
|
|
146
|
+
description_html=sanitize_html(str(event.description)),
|
|
147
|
+
venue=location['venue_name'],
|
|
148
|
+
room=location['room_name'],
|
|
149
|
+
address=location['address'],
|
|
150
|
+
)
|
|
151
|
+
return result
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _validate_timezone(value):
|
|
155
|
+
if value not in common_timezones_set:
|
|
156
|
+
raise BadRequest('Choose a supported IANA timezone.')
|
|
157
|
+
return value
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _validate_dates(start, end):
|
|
161
|
+
if start >= end:
|
|
162
|
+
raise BadRequest('The end time must be later than the start time.')
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _update_dates(event, start_dt, end_dt, shift_timetable):
|
|
166
|
+
start = parse_timestamp(start_dt) if start_dt is not None else event.start_dt
|
|
167
|
+
end = parse_timestamp(end_dt) if end_dt is not None else event.end_dt
|
|
168
|
+
_validate_dates(start, end)
|
|
169
|
+
# Match the event date form's timetable boundary validation. Lectures
|
|
170
|
+
# also shift any timetable data retained from a previous event type.
|
|
171
|
+
shift_timetable = shift_timetable or event.type_ == EventType.lecture
|
|
172
|
+
for entry in event.timetable_entries.filter_by(parent_id=None):
|
|
173
|
+
if shift_timetable:
|
|
174
|
+
fits = event.start_dt <= entry.start_dt and entry.end_dt - event.start_dt <= end - start
|
|
175
|
+
else:
|
|
176
|
+
fits = start <= entry.start_dt and entry.end_dt <= end
|
|
177
|
+
if not fits:
|
|
178
|
+
raise BadRequest('The event dates must include all timetable entries.')
|
|
179
|
+
data = {}
|
|
180
|
+
if start_dt is not None and start != event.start_dt:
|
|
181
|
+
data['start_dt'] = start
|
|
182
|
+
if end_dt is not None and end != event.end_dt:
|
|
183
|
+
data['end_dt'] = end
|
|
184
|
+
return data
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def register_tools(registry):
|
|
188
|
+
@registry.tool()
|
|
189
|
+
def indico_list_categories(user, parent_id: CategoryID = 0, after_id: CategoryID = 0, limit: PageSize = 30):
|
|
190
|
+
"""List accessible immediate subcategories. Use parent_id 0 for the root and next_after_id for pagination."""
|
|
191
|
+
parent = require_access(get_category(parent_id), user)
|
|
192
|
+
query = Category.query.filter_by(parent_id=parent.id, is_deleted=False)
|
|
193
|
+
return get_page(query, Category, after_id, limit, lambda item: item.can_access(user),
|
|
194
|
+
lambda item: serialize_category(item, user))
|
|
195
|
+
|
|
196
|
+
@registry.tool()
|
|
197
|
+
def indico_get_category(user, category_id: CategoryID = 0):
|
|
198
|
+
"""Get an accessible category's title, description, timezone, and link."""
|
|
199
|
+
return serialize_category(require_access(get_category(category_id), user), user, detail=True)
|
|
200
|
+
|
|
201
|
+
@registry.tool(read_only=False)
|
|
202
|
+
def indico_create_category(user, parent_id: CategoryID, title: Title, description: Description = ''):
|
|
203
|
+
"""Create a subcategory in a category you manage. The description uses Markdown."""
|
|
204
|
+
parent = require_manage(get_category(parent_id), user)
|
|
205
|
+
|
|
206
|
+
def sort_key(category):
|
|
207
|
+
return natural_sort_key(category.title), category.id
|
|
208
|
+
|
|
209
|
+
previous = list(parent.children)
|
|
210
|
+
ascending = previous == sorted(previous, key=sort_key)
|
|
211
|
+
descending = not ascending and previous == sorted(previous, key=sort_key, reverse=True)
|
|
212
|
+
category = create_category(parent, {'title': title, 'description': description})
|
|
213
|
+
if ascending or descending:
|
|
214
|
+
siblings = sorted(parent.children, key=sort_key, reverse=descending)
|
|
215
|
+
for position, sibling in enumerate(siblings, start=1):
|
|
216
|
+
sibling.position = position
|
|
217
|
+
return serialize_category(category, user, detail=True)
|
|
218
|
+
|
|
219
|
+
@registry.tool(read_only=False, idempotent=True)
|
|
220
|
+
def indico_update_category(user, category_id: CategoryID, title: Title | None = None,
|
|
221
|
+
description: Description | None = None, timezone: ShortText | None = None):
|
|
222
|
+
"""Edit a category's title, Markdown description, or default timezone."""
|
|
223
|
+
category = require_manage(get_category(category_id), user)
|
|
224
|
+
data = {'title': title, 'description': description, 'timezone': timezone}
|
|
225
|
+
if timezone is not None:
|
|
226
|
+
data['timezone'] = _validate_timezone(timezone)
|
|
227
|
+
if data := {key: value for key, value in data.items() if value is not None}:
|
|
228
|
+
update_category(category, data)
|
|
229
|
+
return serialize_category(category, user, detail=True)
|
|
230
|
+
|
|
231
|
+
@registry.tool(read_only=False, idempotent=True)
|
|
232
|
+
def indico_move_category(user, category_id: CategoryID, target_parent_id: CategoryID):
|
|
233
|
+
"""Move a category under another category. Both categories require management permission."""
|
|
234
|
+
category = require_manage(get_category(category_id), user)
|
|
235
|
+
target = require_manage(get_category(target_parent_id), user)
|
|
236
|
+
if (category.is_root or category == target
|
|
237
|
+
or target.parent_chain_query.filter(Category.id == category.id).has_rows()):
|
|
238
|
+
raise BadRequest('The root cannot be moved, and a category cannot be moved into itself or a descendant.')
|
|
239
|
+
if category.parent != target:
|
|
240
|
+
move_category(category, target)
|
|
241
|
+
return serialize_category(category, user, detail=True)
|
|
242
|
+
|
|
243
|
+
@registry.tool(read_only=False, destructive=True)
|
|
244
|
+
def indico_delete_category(user, category_id: CategoryID, confirm: bool):
|
|
245
|
+
"""Delete an empty non-root category you manage."""
|
|
246
|
+
require_confirmation(confirm)
|
|
247
|
+
category = require_manage(get_category(category_id), user)
|
|
248
|
+
if category.is_root or not category.is_empty:
|
|
249
|
+
raise BadRequest('Only empty non-root categories can be deleted.')
|
|
250
|
+
delete_category(category)
|
|
251
|
+
return {'id': category.id, 'deleted': True}
|
|
252
|
+
|
|
253
|
+
@registry.tool()
|
|
254
|
+
def indico_list_events(user, category_id: CategoryID = 0, include_descendants: bool = False,
|
|
255
|
+
title_contains: Title | None = None, window_start: Timestamp | None = None,
|
|
256
|
+
window_end: Timestamp | None = None, after_id: CategoryID = 0, limit: PageSize = 30):
|
|
257
|
+
"""List accessible events in a category by ID. An optional time range filters for overlapping events."""
|
|
258
|
+
category = require_access(get_category(category_id), user)
|
|
259
|
+
query = Event.query.filter_by(is_deleted=False)
|
|
260
|
+
if include_descendants:
|
|
261
|
+
query = query.filter(Event.is_visible_in(category.id))
|
|
262
|
+
else:
|
|
263
|
+
query = query.filter_by(category_id=category.id)
|
|
264
|
+
if title_contains is not None:
|
|
265
|
+
escaped = title_contains.replace('\\', '\\\\').replace('%', '\\%').replace('_', '\\_')
|
|
266
|
+
query = query.filter(Event.title.ilike(f'%{escaped}%', escape='\\'))
|
|
267
|
+
start = parse_timestamp(window_start) if window_start is not None else None
|
|
268
|
+
end = parse_timestamp(window_end) if window_end is not None else None
|
|
269
|
+
if start is not None:
|
|
270
|
+
query = query.filter(Event.end_dt >= start)
|
|
271
|
+
if end is not None:
|
|
272
|
+
query = query.filter(Event.start_dt <= end)
|
|
273
|
+
if start is not None and end is not None:
|
|
274
|
+
_validate_dates(start, end)
|
|
275
|
+
|
|
276
|
+
def visible(event):
|
|
277
|
+
return (event.can_access(user) and event.can_display(user) and
|
|
278
|
+
(event.category == category or event.category.can_access(user)))
|
|
279
|
+
|
|
280
|
+
return get_page(query, Event, after_id, limit, visible, lambda item: serialize_event(item, user))
|
|
281
|
+
|
|
282
|
+
@registry.tool()
|
|
283
|
+
def indico_get_event(user, event_id: ObjectID):
|
|
284
|
+
"""Get an accessible event's type, title, dates, location, description, and link."""
|
|
285
|
+
return serialize_event(require_access(get_event(event_id), user), user, detail=True)
|
|
286
|
+
|
|
287
|
+
@registry.tool(read_only=False, open_world=True)
|
|
288
|
+
def indico_create_event(user, title: Title, event_type: EventKind, start_dt: Timestamp, end_dt: Timestamp,
|
|
289
|
+
category_id: CategoryID | None = None, timezone: ShortText | None = None,
|
|
290
|
+
description_html: Description = '',
|
|
291
|
+
protection: Literal['inheriting', 'protected', 'public'] = 'inheriting'):
|
|
292
|
+
"""Create an event and send configured category notifications. Omit category_id to create an unlisted event."""
|
|
293
|
+
category = get_category(category_id) if category_id is not None else None
|
|
294
|
+
if category is not None and not category.can_create_events(user):
|
|
295
|
+
raise Forbidden('You are not allowed to create events in this category.')
|
|
296
|
+
if category is None and not can_create_unlisted_events(user):
|
|
297
|
+
raise Forbidden('You are not allowed to create unlisted events.')
|
|
298
|
+
if category is None and protection != 'inheriting':
|
|
299
|
+
raise BadRequest('Unlisted events require inheriting protection.')
|
|
300
|
+
start, end = parse_timestamp(start_dt), parse_timestamp(end_dt)
|
|
301
|
+
_validate_dates(start, end)
|
|
302
|
+
tz = _validate_timezone(timezone) if timezone is not None else (
|
|
303
|
+
category.timezone if category is not None else config.DEFAULT_TIMEZONE)
|
|
304
|
+
event = create_event(category, EventType[event_type], {
|
|
305
|
+
'title': title, 'start_dt': start, 'end_dt': end, 'timezone': tz,
|
|
306
|
+
'description': sanitize_html(description_html), 'protection_mode': ProtectionMode[protection],
|
|
307
|
+
})
|
|
308
|
+
notify_event_creation(event)
|
|
309
|
+
return serialize_event(event, user, detail=True)
|
|
310
|
+
|
|
311
|
+
@registry.tool(read_only=False, idempotent=True)
|
|
312
|
+
def indico_update_event(user, event_id: ObjectID, title: Title | None = None,
|
|
313
|
+
description_html: Description | None = None, start_dt: Timestamp | None = None,
|
|
314
|
+
end_dt: Timestamp | None = None, timezone: ShortText | None = None,
|
|
315
|
+
shift_timetable: bool = True):
|
|
316
|
+
"""Update an unlocked event. By default, a changed start time shifts its timetable by the same amount."""
|
|
317
|
+
event = manage_event(event_id, user)
|
|
318
|
+
data = {}
|
|
319
|
+
if title is not None:
|
|
320
|
+
data['title'] = title
|
|
321
|
+
if description_html is not None:
|
|
322
|
+
data['description'] = sanitize_html(description_html)
|
|
323
|
+
if timezone is not None:
|
|
324
|
+
data['timezone'] = _validate_timezone(timezone)
|
|
325
|
+
if start_dt is not None or end_dt is not None:
|
|
326
|
+
data.update(_update_dates(event, start_dt, end_dt, shift_timetable))
|
|
327
|
+
if data:
|
|
328
|
+
with track_time_changes(user=user):
|
|
329
|
+
update_event(event, update_timetable=shift_timetable, **data)
|
|
330
|
+
return serialize_event(event, user, detail=True)
|
|
331
|
+
|
|
332
|
+
@registry.tool(read_only=False, idempotent=True)
|
|
333
|
+
def indico_update_event_location(user, event_id: ObjectID, venue: ShortText = '', room: ShortText = '',
|
|
334
|
+
address: Description = ''):
|
|
335
|
+
"""Replace an unlocked event's location with a free-text venue, room, and address. Omitted fields clear."""
|
|
336
|
+
event = manage_event(event_id, user)
|
|
337
|
+
with track_location_changes():
|
|
338
|
+
update_event(event, location_data={'inheriting': False, 'room_name': room, 'venue_name': venue,
|
|
339
|
+
'address': address})
|
|
340
|
+
return serialize_event(event, user, detail=True)
|
|
341
|
+
|
|
342
|
+
@registry.tool(read_only=False, idempotent=True)
|
|
343
|
+
def indico_set_event_type(user, event_id: ObjectID, event_type: EventKind):
|
|
344
|
+
"""Change an unlocked event's type to lecture, meeting, or conference."""
|
|
345
|
+
event = manage_event(event_id, user)
|
|
346
|
+
update_event_type(event, EventType[event_type])
|
|
347
|
+
return serialize_event(event, user)
|
|
348
|
+
|
|
349
|
+
@registry.tool()
|
|
350
|
+
def indico_list_event_features(user, event_id: ObjectID):
|
|
351
|
+
"""List the available core and plugin features for an event you manage."""
|
|
352
|
+
event = require_manage(get_event(event_id), user)
|
|
353
|
+
allowed = get_feature_definitions().keys() - get_disallowed_features(event)
|
|
354
|
+
enabled = get_enabled_features(event)
|
|
355
|
+
definitions = get_feature_definitions()
|
|
356
|
+
return {'items': [{'name': name, 'title': str(definitions[name].friendly_name), 'enabled': name in enabled}
|
|
357
|
+
for name in sorted(allowed)]}
|
|
358
|
+
|
|
359
|
+
@registry.tool(read_only=False, idempotent=True, destructive=True)
|
|
360
|
+
def indico_set_event_feature(user, event_id: ObjectID, name: ShortText, enabled: bool, confirm: bool = False):
|
|
361
|
+
"""Toggle an event feature and its native dependencies. Disabling requires confirmation."""
|
|
362
|
+
event = manage_event(event_id, user)
|
|
363
|
+
definitions = get_feature_definitions()
|
|
364
|
+
if name not in definitions:
|
|
365
|
+
raise NotFound('The event feature does not exist.')
|
|
366
|
+
if enabled and name in get_disallowed_features(event):
|
|
367
|
+
raise Forbidden('The feature is unavailable for this event.')
|
|
368
|
+
if not enabled:
|
|
369
|
+
require_confirmation(confirm)
|
|
370
|
+
before = get_enabled_features(event)
|
|
371
|
+
if set_feature_enabled(event, name, enabled):
|
|
372
|
+
action = 'Enabled' if enabled else 'Disabled'
|
|
373
|
+
kind = LogKind.positive if enabled else LogKind.negative
|
|
374
|
+
event.log(EventLogRealm.management, kind, 'Features', f'{action} {definitions[name].friendly_name}', user)
|
|
375
|
+
after = get_enabled_features(event)
|
|
376
|
+
return {'name': name, 'enabled': name in after, 'changed': sorted(before ^ after)}
|
|
377
|
+
|
|
378
|
+
@registry.tool(read_only=False, idempotent=True)
|
|
379
|
+
def indico_set_event_locked(user, event_id: ObjectID, locked: bool):
|
|
380
|
+
"""Lock an event against edits or unlock it. Requires Indico's separate lock permission."""
|
|
381
|
+
event = require_manage(get_event(event_id), user)
|
|
382
|
+
if not event.can_lock(user):
|
|
383
|
+
raise Forbidden('You do not have permission to lock or unlock this event.')
|
|
384
|
+
if locked != event.is_locked:
|
|
385
|
+
(lock_event if locked else unlock_event)(event)
|
|
386
|
+
return serialize_event(event, user)
|
|
387
|
+
|
|
388
|
+
@registry.tool(read_only=False, open_world=True)
|
|
389
|
+
def indico_move_event(user, event_id: ObjectID, target_category_id: CategoryID, comment: Description = ''):
|
|
390
|
+
"""Move an event. Destinations that require approval receive a native move request and notifications."""
|
|
391
|
+
event = manage_event(event_id, user)
|
|
392
|
+
target = get_category(target_category_id)
|
|
393
|
+
if not target.can_create_events(user) and not target.can_propose_events(user):
|
|
394
|
+
raise Forbidden('You do not have permission to move events into this category.')
|
|
395
|
+
if event.category == target:
|
|
396
|
+
return {'event_id': event.id, 'category_id': target.id, 'status': 'already_in_category'}
|
|
397
|
+
if target.can_create_events(user):
|
|
398
|
+
event.move(target)
|
|
399
|
+
return {'event_id': event.id, 'category_id': target.id, 'status': 'moved'}
|
|
400
|
+
move_request = create_event_request(event, target, comment)
|
|
401
|
+
notify_move_request_creation([event], target, comment)
|
|
402
|
+
return {'event_id': event.id, 'category_id': target.id, 'status': 'pending', 'request_id': move_request.id}
|
|
403
|
+
|
|
404
|
+
@registry.tool(read_only=False, destructive=True)
|
|
405
|
+
def indico_withdraw_event_move_request(user, event_id: ObjectID, confirm: bool):
|
|
406
|
+
"""Withdraw the pending move request for an unlocked event you manage."""
|
|
407
|
+
require_confirmation(confirm)
|
|
408
|
+
event = manage_event(event_id, user)
|
|
409
|
+
if event.pending_move_request is None:
|
|
410
|
+
raise NotFound('The event has no pending move request.')
|
|
411
|
+
event.pending_move_request.withdraw(user=user)
|
|
412
|
+
return {'event_id': event.id, 'status': 'withdrawn'}
|
|
413
|
+
|
|
414
|
+
@registry.tool(read_only=False, destructive=True)
|
|
415
|
+
def indico_delete_event(user, event_id: ObjectID, confirm: bool):
|
|
416
|
+
"""Delete an unlocked event you manage."""
|
|
417
|
+
require_confirmation(confirm)
|
|
418
|
+
event = manage_event(event_id, user)
|
|
419
|
+
event.delete('Deleted by user through MCP', user)
|
|
420
|
+
return {'id': event.id, 'deleted': True}
|