def put(self, worklist_id, filter_id, filter): """Update a filter on the worklist. Example:: TODO :param worklist_id: The ID of the worklist. :param filter_id: The ID of the filter to be updated. :param filter: The new contents of the filter. """ worklist = worklists_api.get(worklist_id) user_id = request.current_user_id if not worklists_api.editable(worklist, user_id): raise exc.NotFound(_("Worklist %s not found") % worklist_id) old = serialize_filter(worklists_api.get_filter(filter_id)) update_dict = filter.as_dict(omit_unset=True) updated = worklists_api.update_filter(filter_id, update_dict) changes = { "old": old, "new": serialize_filter(updated) } events_api.worklist_filters_changed_event(worklist_id, user_id, updated=changes) updated_model = wmodels.WorklistFilter.from_db_model(updated) updated_model.resolve_criteria(updated) return updated_model
def put(self, id, worklist): """Modify this worklist. :param id: The ID of the worklist. :param worklist: A worklist within the request body. """ user_id = request.current_user_id if not worklists_api.editable(worklists_api.get(id), user_id): raise exc.NotFound(_("Worklist %s not found") % id) # We don't use this endpoint to update the worklist's contents if worklist.items != wtypes.Unset: del worklist.items # We don't use this endpoint to update the worklist's filters either if worklist.filters != wtypes.Unset: del worklist.filters worklist_dict = worklist.as_dict(omit_unset=True) updated_worklist = worklists_api.update(id, worklist_dict) if worklists_api.visible(updated_worklist, user_id): worklist_model = wmodels.Worklist.from_db_model(updated_worklist) worklist_model.resolve_items(updated_worklist) worklist_model.resolve_permissions(updated_worklist) return worklist_model else: raise exc.NotFound(_("Worklist %s not found"))
def post(self, worklist_id, filter): """Create a new filter for the worklist. Example:: TODO :param worklist_id: The ID of the worklist to set the filter on. :param filter: The filter to set. """ worklist = worklists_api.get(worklist_id) user_id = request.current_user_id if not worklists_api.editable(worklist, user_id): raise exc.NotFound(_("Worklist %s not found") % worklist_id) created = worklists_api.create_filter(worklist_id, filter.as_dict()) added = serialize_filter(created) events_api.worklist_filters_changed_event(worklist_id, user_id, added=added) model = wmodels.WorklistFilter.from_db_model(created) model.resolve_criteria(created) return model
def put(self, worklist_id, filter_id, filter): """Update a filter on the worklist. Example:: TODO :param worklist_id: The ID of the worklist. :param filter_id: The ID of the filter to be updated. :param filter: The new contents of the filter. """ worklist = worklists_api.get(worklist_id) user_id = request.current_user_id if not worklists_api.editable(worklist, user_id): raise exc.NotFound(_("Worklist %s not found") % worklist_id) old = serialize_filter(worklists_api.get_filter(filter_id)) update_dict = filter.as_dict(omit_unset=True) updated = worklists_api.update_filter(filter_id, update_dict) changes = {"old": old, "new": serialize_filter(updated)} events_api.worklist_filters_changed_event(worklist_id, user_id, updated=changes) updated_model = wmodels.WorklistFilter.from_db_model(updated) updated_model.resolve_criteria(updated) return updated_model
def post(self, worklist_id, permission): """Add a new permission to the worklist. Example:: TODO :param worklist_id: The ID of the worklist. :param permission: The dict to use to create the permission. """ user_id = request.current_user_id if worklists_api.editable(worklists_api.get(worklist_id), user_id): created = worklists_api.create_permission(worklist_id, permission) users = [{user.id: user.full_name} for user in created.users] events_api.worklist_permission_created_event(worklist_id, user_id, created.id, created.codename, users) return created.codename else: raise exc.NotFound(_("Worklist %s not found") % worklist_id)
def put(self, worklist_id, permission): """Update a permission of the worklist. Example:: TODO This takes a dict in the form:: { "codename": "my-permission", "users": [ 1, 2, 3 ] } The given codename must match an existing permission's codename. :param worklist_id: The ID of the worklist. :param permission: The new contents of the permission. """ user_id = request.current_user_id worklist = worklists_api.get(worklist_id) old = None for perm in worklist.permissions: if perm.codename == permission['codename']: old = perm if old is None: raise exc.NotFound( _("Permission with codename %s not found") % permission['codename']) old_users = {user.id: user.full_name for user in old.users} if worklists_api.editable(worklist, user_id): updated = worklists_api.update_permission(worklist_id, permission) new_users = {user.id: user.full_name for user in updated.users} added = [{ id: name } for id, name in six.iteritems(new_users) if id not in old_users] removed = [{ id: name } for id, name in six.iteritems(old_users) if id not in new_users] if added or removed: events_api.worklist_permissions_changed_event( worklist_id, user_id, updated.id, updated.codename, added, removed) return updated.codename else: raise exc.NotFound(_("Worklist %s not found") % worklist_id)
def put(self, worklist_id, permission): """Update a permission of the worklist. :param worklist_id: The ID of the worklist. :param permission: The new contents of the permission. """ if worklists_api.editable(worklists_api.get(worklist_id), request.current_user_id): return worklists_api.update_permission(worklist_id, permission).codename else: raise exc.NotFound(_("Worklist %s not found") % worklist_id)
def post(self, worklist_id, permission): """Add a new permission to the worklist. :param worklist_id: The ID of the worklist. :param permission: The dict to use to create the permission. """ if worklists_api.editable(worklists_api.get(worklist_id), request.current_user_id): return worklists_api.create_permission(worklist_id) else: raise exc.NotFound(_("Worklist %s not found") % worklist_id)
def delete(self, worklist_id): """Archive this worklist. :param worklist_id: The ID of the worklist to be archived. """ worklist = worklists_api.get(worklist_id) user_id = request.current_user_id if not worklists_api.editable(worklist, user_id): raise exc.NotFound(_("Worklist %s not found") % worklist_id) worklists_api.update(worklist_id, {"archived": True})
def delete(self, worklist_id, filter_id): """Delete a filter from a worklist. :param worklist_id: The ID of the worklist. :param filter_id: The ID of the filter to be deleted. """ worklist = worklists_api.get(worklist_id) user_id = request.current_user_id if not worklists_api.editable(worklist, user_id): raise exc.NotFound(_("Worklist %s not found") % worklist_id) worklists_api.delete_filter(filter_id)
def put(self, worklist_id, permission): """Update a permission of the worklist. :param worklist_id: The ID of the worklist. :param permission: The new contents of the permission. """ if worklists_api.editable(worklists_api.get(worklist_id), request.current_user_id): return worklists_api.update_permission( worklist_id, permission).codename else: raise exc.NotFound(_("Worklist %s not found") % worklist_id)
def put(self, id, worklist): """Modify this worklist. Example:: TODO :param id: The ID of the worklist. :param worklist: A worklist within the request body. """ user_id = request.current_user_id if not worklists_api.editable(worklists_api.get(id), user_id): raise exc.NotFound(_("Worklist %s not found") % id) story_cache = { story.id: story for story in stories_api.story_get_all(worklist_id=id, current_user=user_id) } task_cache = { task.id: task for task in tasks_api.task_get_all(worklist_id=id, current_user=user_id) } # We don't use this endpoint to update the worklist's contents if worklist.items != wtypes.Unset: del worklist.items # We don't use this endpoint to update the worklist's filters either if worklist.filters != wtypes.Unset: del worklist.filters worklist_dict = worklist.as_dict(omit_unset=True) original = copy.deepcopy(worklists_api.get(id)) updated_worklist = worklists_api.update(id, worklist_dict) post_timeline_events(original, updated_worklist) if worklists_api.visible(updated_worklist, user_id): worklist_model = wmodels.Worklist.from_db_model(updated_worklist) worklist_model.resolve_items(updated_worklist, story_cache, task_cache) worklist_model.resolve_permissions(updated_worklist) return worklist_model else: raise exc.NotFound(_("Worklist %s not found"))
def put(self, worklist_id, filter_id, filter): """Update a filter on the worklist. :param worklist_id: The ID of the worklist. :param filter_id: The ID of the filter to be updated. :param filter: The new contents of the filter. """ worklist = worklists_api.get(worklist_id) user_id = request.current_user_id if not worklists_api.editable(worklist, user_id): raise exc.NotFound(_("Worklist %s not found") % worklist_id) update_dict = filter.as_dict(omit_unset=True) updated = worklists_api.update_filter(filter_id, update_dict) return wmodels.WorklistFilter.from_db_model(updated)
def put(self, id, worklist): """Modify this worklist. Example:: TODO :param id: The ID of the worklist. :param worklist: A worklist within the request body. """ user_id = request.current_user_id if not worklists_api.editable(worklists_api.get(id), user_id): raise exc.NotFound(_("Worklist %s not found") % id) story_cache = {story.id: story for story in stories_api.story_get_all( worklist_id=id, current_user=user_id)} task_cache = {task.id: task for task in tasks_api.task_get_all( worklist_id=id, current_user=user_id)} # We don't use this endpoint to update the worklist's contents if worklist.items != wtypes.Unset: del worklist.items # We don't use this endpoint to update the worklist's filters either if worklist.filters != wtypes.Unset: del worklist.filters worklist_dict = worklist.as_dict(omit_unset=True) original = copy.deepcopy(worklists_api.get(id)) updated_worklist = worklists_api.update(id, worklist_dict) post_timeline_events(original, updated_worklist) if worklists_api.visible(updated_worklist, user_id): worklist_model = wmodels.Worklist.from_db_model(updated_worklist) worklist_model.resolve_items( updated_worklist, story_cache, task_cache) worklist_model.resolve_permissions(updated_worklist) return worklist_model else: raise exc.NotFound(_("Worklist %s not found"))
def post(self, worklist_id, permission): """Add a new permission to the worklist. Example:: TODO :param worklist_id: The ID of the worklist. :param permission: The dict to use to create the permission. """ user_id = request.current_user_id if worklists_api.editable(worklists_api.get(worklist_id), user_id): created = worklists_api.create_permission(worklist_id, permission) users = [{user.id: user.full_name} for user in created.users] events_api.worklist_permission_created_event( worklist_id, user_id, created.id, created.codename, users) return created.codename else: raise exc.NotFound(_("Worklist %s not found") % worklist_id)
def delete(self, worklist_id): """Archive this worklist. Though this uses the DELETE command, the worklist is not deleted. Archived worklists remain viewable at the designated URL, but are not returned in search results nor appear on your dashboard. Example:: curl https://my.example.org/api/v1/worklists/30 -X DELETE \\ -H 'Authorization: Bearer MY_ACCESS_TOKEN' :param worklist_id: The ID of the worklist to be archived. """ worklist = worklists_api.get(worklist_id) original = copy.deepcopy(worklist) user_id = request.current_user_id if not worklists_api.editable(worklist, user_id): raise exc.NotFound(_("Worklist %s not found") % worklist_id) updated = worklists_api.update(worklist_id, {"archived": True}) post_timeline_events(original, updated)
def delete(self, worklist_id, filter_id): """Delete a filter from a worklist. Example:: TODO :param worklist_id: The ID of the worklist. :param filter_id: The ID of the filter to be deleted. """ worklist = worklists_api.get(worklist_id) user_id = request.current_user_id if not worklists_api.editable(worklist, user_id): raise exc.NotFound(_("Worklist %s not found") % worklist_id) filter = serialize_filter(worklists_api.get_filter(filter_id)) events_api.worklist_filters_changed_event(worklist_id, user_id, removed=filter) worklists_api.delete_filter(filter_id)
def put(self, worklist_id, permission): """Update a permission of the worklist. Example:: TODO This takes a dict in the form:: { "codename": "my-permission", "users": [ 1, 2, 3 ] } The given codename must match an existing permission's codename. :param worklist_id: The ID of the worklist. :param permission: The new contents of the permission. """ user_id = request.current_user_id worklist = worklists_api.get(worklist_id) old = None for perm in worklist.permissions: if perm.codename == permission['codename']: old = perm if old is None: raise exc.NotFound(_("Permission with codename %s not found") % permission['codename']) old_users = {user.id: user.full_name for user in old.users} if worklists_api.editable(worklist, user_id): updated = worklists_api.update_permission( worklist_id, permission) new_users = {user.id: user.full_name for user in updated.users} added = [{id: name} for id, name in six.iteritems(new_users) if id not in old_users] removed = [{id: name} for id, name in six.iteritems(old_users) if id not in new_users] if added or removed: events_api.worklist_permissions_changed_event( worklist_id, user_id, updated.id, updated.codename, added, removed) return updated.codename else: raise exc.NotFound(_("Worklist %s not found") % worklist_id)