def __init__(self, endpoint_name, app, service, endpoint_schema=None): self.schema = { "name": {"type": "string", "required": True, "nullable": False, "empty": False, "iunique": True}, "source": required_string, "feeding_service": {"type": "string", "required": True, "allowed": allowed_feeding_services}, "feed_parser": {"type": "string", "nullable": True, "allowed": allowed_feed_parsers}, "content_types": {"type": "list", "default": content_type, "allowed": content_type}, "allow_remove_ingested": {"type": "boolean", "default": False}, "content_expiry": {"type": "integer", "default": app.config["INGEST_EXPIRY_MINUTES"]}, "config": {"type": "dict"}, "ingested_count": {"type": "integer"}, "accepted_count": {"type": "integer"}, "tokens": {"type": "dict"}, "is_closed": {"type": "boolean", "default": False}, "update_schedule": { "type": "dict", "schema": { "hours": {"type": "integer"}, "minutes": {"type": "integer", "default": 5}, "seconds": {"type": "integer"}, }, }, "idle_time": {"type": "dict", "schema": {"hours": {"type": "integer"}, "minutes": {"type": "integer"}}}, "last_updated": {"type": "datetime"}, "last_item_update": {"type": "datetime"}, "rule_set": Resource.rel("rule_sets", nullable=True), "notifications": { "type": "dict", "schema": { "on_update": {"type": "boolean", "default": True}, "on_close": {"type": "boolean", "default": True}, "on_open": {"type": "boolean", "default": True}, "on_error": {"type": "boolean", "default": True}, }, }, "routing_scheme": Resource.rel("routing_schemes", nullable=True), "last_closed": { "type": "dict", "schema": { "closed_at": {"type": "datetime"}, "closed_by": Resource.rel("users", nullable=True), "message": {"type": "string"}, }, }, "last_opened": { "type": "dict", "schema": {"opened_at": {"type": "datetime"}, "opened_by": Resource.rel("users", nullable=True)}, }, "critical_errors": {"type": "dict", "valueschema": {"type": "boolean"}}, } self.item_methods = ["GET", "PATCH", "DELETE"] self.privileges = {"POST": "ingest_providers", "PATCH": "ingest_providers", "DELETE": "ingest_providers"} self.etag_ignore_fields = ["last_updated", "last_item_update", "last_closed", "last_opened"] super().__init__(endpoint_name, app, service, endpoint_schema=endpoint_schema)
def __init__(self, endpoint_name, app, service, endpoint_schema=None): self.readonly = True if app.config.get("LDAP_SERVER", None) else False self.additional_lookup = {"url": 'regex("[\w]+")', "field": "username"} self.schema = { "username": {"type": "string", "unique": True, "required": True, "minlength": 1}, "password": {"type": "string", "minlength": 5, "readonly": self.readonly}, "first_name": {"type": "string", "readonly": self.readonly}, "last_name": {"type": "string", "readonly": self.readonly}, "display_name": {"type": "string", "readonly": self.readonly}, "email": {"unique": True, "type": "email", "required": True}, "phone": {"type": "phone_number", "readonly": self.readonly, "nullable": True}, "language": {"type": "string", "readonly": self.readonly, "nullable": True}, "user_info": {"type": "dict"}, "picture_url": {"type": "string", "nullable": True}, "avatar": Resource.rel("upload", embeddable=True, nullable=True), "role": Resource.rel("roles", True), "privileges": {"type": "dict"}, "workspace": {"type": "dict"}, "user_type": {"type": "string", "allowed": ["user", "administrator"], "default": "user"}, "is_active": {"type": "boolean", "default": True}, "is_enabled": {"type": "boolean", "default": True}, "needs_activation": {"type": "boolean", "default": True}, "desk": Resource.rel("desks"), # Default desk of the user, which would be selected when logged-in. SIGN_OFF: { # Used for putting a sign-off on the content when it's created/updated except kill "type": "string", "required": True, "regex": "^[a-zA-Z0-9]+$", }, BYLINE: {"type": "string", "required": False, "nullable": True}, } self.extra_response_fields = [ "display_name", "username", "email", "user_info", "picture_url", "avatar", "is_active", "is_enabled", "needs_activation", "desk", ] self.etag_ignore_fields = ["session_preferences", "_etag"] self.datasource = {"projection": {"password": 0}, "default_sort": [("username", 1)]} self.privileges = {"POST": "users", "DELETE": "users", "PATCH": "users"} super().__init__(endpoint_name, app=app, service=service, endpoint_schema=endpoint_schema)
def item_schema(extra=None): """Create schema for item. :param extra: extra fields to be added to schema """ schema = { 'old_version': { 'type': 'number', }, 'last_version': { 'type': 'number', }, 'task': {'type': 'dict'}, 'destination_groups': { 'type': 'list', 'schema': Resource.rel('destination_groups', True) }, 'publish_schedule': { 'type': 'datetime', 'nullable': True }, 'marked_for_not_publication': { 'type': 'boolean', 'default': False } } schema.update(metadata_schema) if extra: schema.update(extra) return schema
class DuplicateResource(Resource): endpoint_name = "duplicate" resource_title = endpoint_name schema = { "desk": Resource.rel("desks", False, required=True, nullable=True), "stage": Resource.rel("stages", False, required=False), "type": { "type": "string", "required": True }, "item_id": { "type": "string", "required": False }, } url = "archive/<{0}:guid>/duplicate".format(item_url) resource_methods = ["POST"] item_methods = [] privileges = {"POST": "duplicate"}
class ClientItemsResource(ItemsResource): datasource = { 'source': 'archive', 'elastic_filter': {'term': {'particular_type': 'item'}}, 'default_sort': [('order', -1)] } public_methods = ['GET', 'POST'] public_item_methods = ['GET', 'POST'] item_methods = ['GET'] resource_methods = ['GET', 'POST'] schema = { 'client_blog': Resource.rel('client_blogs', True) } schema.update(ItemsResource.schema)
class DuplicateResource(Resource): endpoint_name = 'duplicate' resource_title = endpoint_name schema = { 'desk': Resource.rel('desks', False, required=True), 'stage': Resource.rel('stages', False, required=False), 'type': { 'type': 'string', 'required': True }, 'item_id': { 'type': 'string', 'required': False } } url = 'archive/<{0}:guid>/duplicate'.format(item_url) resource_methods = ['POST'] item_methods = [] privileges = {'POST': 'duplicate'}
class AuthResource(Resource): schema = { "username": {"type": "string", "required": True}, "password": {"type": "string", "required": True}, "token": {"type": "string"}, "user": Resource.rel("users", True), } resource_methods = ["POST"] item_methods = ["GET", "DELETE"] public_methods = ["POST", "DELETE"] extra_response_fields = ["user", "token", "username"] datasource = {"source": "auth"} mongo_indexes = {"token": ([("token", 1)], {"background": True})}
class DuplicateResource(Resource): endpoint_name = 'duplicate' resource_title = endpoint_name schema = { 'desk': Resource.rel('desks', False, required=True) } url = 'archive/<{0}:guid>/duplicate'.format(item_url) resource_methods = ['POST'] item_methods = [] privileges = {'POST': 'duplicate'}
class DictionariesResource(Resource): """Dictionaries schema""" schema = { "name": { "type": "string", "required": True }, "language_id": { "type": "string", "required": True }, "content": { "type": "dict", "schema": {}, "allow_unknown": True, }, "content_list": { "type": "string", }, DICTIONARY_FILE: { "type": "file", }, "user": Resource.rel("users", nullable=True), "is_active": { "type": "string", "default": "true", }, "type": { "type": "string", "default": DictionaryType.DICTIONARY.value, "allowed": DictionaryType.values() }, "_file_id": { "type": "objectid", "nullable": True, "readonly": True }, "init_version": { "type": "integer" }, } item_methods = ["GET", "PATCH", "PUT", "DELETE"] resource_methods = ["GET", "POST", "DELETE"] privileges = { "POST": "dictionaries", "PATCH": "dictionaries", "DELETE": "dictionaries" } etag_ignore_fields = ["content", "content_list"]
class ActivityReportResource(Resource): """Activity Report schema """ schema = { 'operation': { 'type': 'string', 'required': True }, 'desk': Resource.rel('desks'), 'operation_start_date': { 'type': 'datetime', 'required': True }, 'operation_end_date': { 'type': 'datetime', 'required': True }, 'subject': metadata_schema['subject'], 'keywords': metadata_schema['keywords'], 'category': metadata_schema['anpa_category'], 'urgency_start': metadata_schema['urgency'], 'urgency_end': metadata_schema['urgency'], 'priority_start': metadata_schema['priority'], 'priority_end': metadata_schema['priority'], 'subscriber': { 'type': 'string' }, 'group_by': { 'type': 'list' }, 'report': { 'type': 'dict' }, 'timestamp': { 'type': 'datetime' }, 'force_regenerate': { 'type': 'boolean', 'default': False } } item_methods = ['GET', 'DELETE'] resource_methods = ['POST'] privileges = { 'POST': 'activity_report', 'DELETE': 'activity_report', 'GET': 'activity_report' }
class HighlightsResource(Resource): """Highlights schema""" schema = { "name": { "type": "string", "iunique": True, "required": True }, "template": Resource.rel("content_templates", nullable=True), "desks": { "type": "list", "schema": Resource.rel("desks", True) }, "auto_insert": { "type": "string", "allowed": allowed_times, "default": TODAY_DATE, }, "groups": { "type": "list", "schema": { "type": "string" } }, } privileges = { "POST": "highlights", "PATCH": "highlights", "DELETE": "highlights" } mongo_indexes = { "name_1": ([("name", 1)], { "unique": True }), }
class HighlightsResource(Resource): """Highlights schema""" schema = { 'name': { 'type': 'string', 'iunique': True, 'required': True }, 'template': Resource.rel('content_templates', nullable=True), 'desks': { 'type': 'list', 'schema': Resource.rel('desks', True) }, 'auto_insert': { 'type': 'string', 'allowed': allowed_times, 'default': TODAY_DATE, }, 'groups': { 'type': 'list', 'schema': { 'type': 'string' } } } privileges = { 'POST': 'highlights', 'PATCH': 'highlights', 'DELETE': 'highlights' } mongo_indexes = { 'name_1': ([('name', 1)], { 'unique': True }), }
class StagesResource(Resource): schema = { 'name': { 'type': 'string', 'required': True, 'minlength': 1, 'iunique_per_parent': 'desk' }, 'description': { 'type': 'string' }, 'working_stage': { 'type': 'boolean', 'default': False }, 'default_incoming': { 'type': 'boolean', 'default': False }, 'task_status': { 'type': 'string', 'allowed': task_statuses }, 'desk_order': { 'type': 'integer', 'readonly': True }, 'desk': Resource.rel('desks', embeddable=True, required=True), 'content_expiry': { 'type': 'integer' }, 'is_visible': { 'type': 'boolean', 'default': True }, 'incoming_macro': { 'type': 'string' }, 'outgoing_macro': { 'type': 'string' }, 'onstage_macro': { 'type': 'string' } } datasource = {'default_sort': [('desk_order', 1)]} privileges = {'POST': 'desks', 'DELETE': 'desks', 'PATCH': 'desks'}
class InternalDestinationsResource(Resource): schema = { 'name': { 'type': 'string', 'required': True }, 'is_active': { 'type': 'boolean', 'required': True }, 'filter': Resource.rel('content_filters', nullable=True), 'desk': Resource.rel('desks', nullable=False, required=True), 'stage': Resource.rel('stages', nullable=True), 'macro': { 'type': 'string', 'nullable': True }, } privileges = { 'POST': 'internal_destinations', 'PATCH': 'internal_destinations', 'DELETE': 'internal_destinations' }
class ActivityResource(Resource): endpoint_name = 'activity' resource_methods = ['GET'] item_methods = ['GET', 'PATCH'] schema = { 'name': {'type': 'string'}, 'message': {'type': 'string'}, 'data': {'type': 'dict'}, 'read': {'type': 'dict'}, 'item': Resource.rel('archive', type='string'), 'user': Resource.rel('users'), 'desk': Resource.rel('desks') } exclude = {endpoint_name, 'notification'} datasource = { 'default_sort': [('_created', -1)] } superdesk.register_default_user_preference('email:notification', { 'type': 'bool', 'enabled': True, 'default': True, 'label': 'Send notifications via email', 'category': 'notifications' })
class ActivityResource(Resource): endpoint_name = 'activity' resource_methods = ['GET'] item_methods = ['GET', 'PATCH'] schema = { 'name': {'type': 'string'}, 'message': {'type': 'string'}, 'data': {'type': 'dict'}, 'recipients': { 'type': 'list', 'schema': { 'type': 'dict', 'schema': { 'user_id': Resource.rel('users'), 'read': {'type': 'boolean', 'default': False}, 'desk_id': Resource.rel('desks') } } }, 'item': Resource.rel('archive', type='string'), 'user': Resource.rel('users'), 'desk': Resource.rel('desks'), 'resource': {'type': 'string'} } exclude = {endpoint_name, 'notification'} datasource = { 'default_sort': [('_created', -1)], 'filter': {'_created': {'$gte': utcnow() - datetime.timedelta(days=1)}} } superdesk.register_default_user_preference('email:notification', { 'type': 'bool', 'enabled': True, 'default': True, 'label': 'Send notifications via email', 'category': 'notifications', })
class PlanningPublishResource(PlanningResource): schema = { 'planning': Resource.rel('planning', type='string', required=True), 'etag': {'type': 'string', 'required': True}, 'pubstatus': { 'type': 'string', 'required': True, 'allowed': published_state }, } url = 'planning/publish' resource_title = endpoint_name = 'planning_publish' resource_methods = ['POST'] item_methods = []
class TranslateResource(Resource): endpoint_name = "translate" resource_title = endpoint_name schema = { "guid": {"type": "string", "required": True}, "language": {"type": "string", "required": True}, "desk": Resource.rel("desks", nullable=True), } url = "archive/translate" resource_methods = ["POST"] item_methods = [] privileges = {"POST": "translate"}
class DictionariesResource(Resource): """Dictionaries schema """ schema = { 'name': { 'type': 'string', 'required': True }, 'language_id': { 'type': 'string', 'required': True }, 'content': { 'type': 'dict', }, 'content_list': { 'type': 'string', }, DICTIONARY_FILE: { 'type': 'file', }, 'user': Resource.rel('users', nullable=True), 'is_active': { 'type': 'string', 'default': 'true', }, 'type': { 'type': 'string', 'default': DictionaryType.DICTIONARY.value, 'allowed': DictionaryType.values() }, '_file_id': { 'type': 'objectid', 'nullable': True, 'readonly': True }, } item_methods = ['GET', 'PATCH', 'PUT', 'DELETE'] resource_methods = ['GET', 'POST', 'DELETE'] privileges = { 'POST': 'dictionaries', 'PATCH': 'dictionaries', 'DELETE': 'dictionaries' } etag_ignore_fields = ['content', 'content_list']
class AuditResource(Resource): endpoint_name = 'audit' resource_methods = ['GET'] item_methods = ['GET'] schema = { 'resource': { 'type': 'string' }, 'action': { 'type': 'string' }, 'extra': { 'type': 'dict' }, 'user': Resource.rel('users', False) } exclude = {endpoint_name, 'activity', 'dictionaries'}
class OutputChannelsResource(Resource): schema = { 'name': { 'type': 'string', 'iunique': True, 'required': True, }, 'description': { 'type': 'string' }, 'format': { 'type': 'string' }, 'channel_type': { 'type': 'string' }, 'destinations': { 'type': 'list', 'schema': Resource.rel('subscribers', True) }, 'is_active': { 'type': 'boolean', 'default': True }, 'sequence_num_settings': { 'type': 'dict', 'schema': { 'min': { 'type': 'integer' }, 'max': { 'type': 'integer' }, 'start_from': { 'type': 'integer' } } } } datasource = {'default_sort': [('_created', -1)]} privileges = { 'POST': 'output_channels', 'DELETE': 'output_channels', 'PATCH': 'output_channels' }
class ArchiveHistoryResource(Resource): endpoint_name = 'archive_history' resource_methods = ['GET'] item_methods = ['GET'] schema = { 'item_id': {'type': 'string'}, 'user_id': Resource.rel('users', True), 'operation': {'type': 'string'}, 'update': {'type': 'dict', 'nullable': True}, 'version': {'type': 'integer'}, 'original_item_id': {'type': 'string'} } mongo_indexes = { 'item_id': ([('item_id', 1)], {'background': True}), '_id_document': ([('_id_document', 1)], {'background': True}), }
class AutoSaveResource(Resource): endpoint_name = 'archive_autosave' item_url = item_url schema = { '_id': { 'type': 'string' }, 'destination_groups': { 'type': 'list', 'schema': Resource.rel('destination_groups', True) } } schema.update(metadata_schema) resource_methods = ['POST'] item_methods = ['GET', 'PUT', 'PATCH'] resource_title = endpoint_name privileges = {'POST': 'archive', 'PATCH': 'archive', 'PUT': 'archive'}
class ItemsResource(ArchiveResource): datasource = { 'source': 'archive', 'elastic_filter': { 'term': { 'particular_type': 'item' } }, 'default_sort': [('_updated', -1)] } item_methods = ['GET', 'PATCH', 'PUT', 'DELETE'] schema = ArchiveResource.schema schema.update(schema) schema.update({ 'text': { 'type': 'string' }, 'blog': Resource.rel('blogs', True), 'particular_type': { 'type': 'string', 'allowed': ['post', 'item'], 'default': 'item' }, 'item_type': { 'type': 'string' }, 'meta': { 'type': 'dict' }, 'deleted': { 'type': 'string' }, 'commenter': { 'type': 'string', 'minlength': 1, 'maxlength': 30 } }) privileges = { 'GET': 'posts', 'POST': 'posts', 'PATCH': 'posts', 'DELETE': 'posts' }
class XMPPAuthResource(Resource): schema = { 'jid': { 'type': 'string', 'required': True }, 'transactionId': { 'type': 'string', 'required': True }, 'token': { 'type': 'string' }, 'user': Resource.rel('users', True) } resource_methods = ['POST'] public_methods = ['POST'] extra_response_fields = ['user', 'token', 'username']
class XMPPAuthResource(Resource): schema = { "jid": { "type": "string", "required": True }, "transactionId": { "type": "string", "required": True }, "token": { "type": "string" }, "user": Resource.rel("users", True), } resource_methods = ["POST"] public_methods = ["POST"] extra_response_fields = ["user", "token", "username"]
class EventsPublishResource(EventsResource): schema = { 'event': Resource.rel('events', type='string', required=True), 'etag': { 'type': 'string', 'required': True }, 'pubstatus': { 'type': 'string', 'required': True, 'allowed': published_state }, } url = 'events/publish' resource_title = endpoint_name = 'events_publish' resource_methods = ['POST'] item_methods = []
class ProductsResource(Resource): """Products schema""" schema = { 'name': { 'type': 'string', 'iunique': True, 'required': True }, 'description': { 'type': 'string' }, 'codes': { 'type': 'string' }, 'content_filter': { 'type': 'dict', 'schema': { 'filter_id': Resource.rel('content_filters', nullable=True), 'filter_type': { 'type': 'string', 'allowed': ['blocking', 'permitting'], 'default': 'blocking' } }, 'nullable': True }, 'geo_restrictions': { 'type': 'string', 'nullable': True }, 'product_type': { 'type': 'string', 'default': ProductTypes.BOTH.value, 'allowed': ProductTypes.values(), 'required': True } } privileges = { 'POST': 'products', 'PATCH': 'products', 'DELETE': 'products' }
class AuthResource(Resource): schema = { 'username': { 'type': 'string', 'required': True }, 'password': { 'type': 'string', 'required': True }, 'token': { 'type': 'string' }, 'user': Resource.rel('users', True) } resource_methods = ['POST'] item_methods = ['GET', 'DELETE'] public_methods = ['POST', 'DELETE'] extra_response_fields = ['user', 'token', 'username']
class HighlightsResource(Resource): ''' Highlights schema ''' schema = { 'name': { 'type': 'string', 'required': True }, 'desks': { 'type': 'list', 'schema': Resource.rel('desks', True) } } privileges = { 'POST': 'highlights', 'PATCH': 'highlights', 'DELETE': 'highlights' }
class FormattedItemResource(Resource): schema = { 'item_id': Resource.rel('archive', type='string'), 'item_version': { 'type': 'string', 'nullable': False, }, 'formatted_item': { 'type': 'string', 'nullable': False, }, 'format': { 'type': 'string', 'nullable': False, } } datasource = {'default_sort': [('_created', -1)]} privileges = {'POST': 'publish_queue', 'PATCH': 'publish_queue'}
class PlanningPostResource(PlanningResource): schema = { 'planning': Resource.rel('planning', type='string', required=True), 'etag': { 'type': 'string', 'required': True }, 'pubstatus': { 'type': 'string', 'required': True, 'allowed': post_state }, } url = 'planning/post' resource_title = endpoint_name = 'planning_post' resource_methods = ['POST'] privileges = {'POST': 'planning_planning_post'} item_methods = []
class EventsPostResource(EventsResource): schema = { 'event': Resource.rel('events', type='string', required=True), 'etag': {'type': 'string', 'required': True}, 'pubstatus': {'type': 'string', 'required': True, 'allowed': post_state}, # The update method used for recurring events 'update_method': { 'type': 'string', 'allowed': UPDATE_METHODS, 'mapping': not_analyzed, 'nullable': True }, } url = 'events/post' resource_title = endpoint_name = 'events_post' resource_methods = ['POST'] privileges = {'POST': 'planning_event_post'} item_methods = []
import superdesk from superdesk.resource import Resource from superdesk.notification import push_notification from apps.activity import add_activity from superdesk.services import BaseService comments_schema = { 'text': { 'type': 'string', 'minlength': 1, 'maxlength': 500, 'required': True, }, 'item': Resource.rel('archive', True, True, type='string'), 'user': Resource.rel('users', True), 'mentioned_users': { 'type': 'dict' } } def check_item_valid(item_id): item = app.data.find_one('archive', req=None, _id=item_id) if not item: msg = 'Invalid content item ID provided: %s' % item_id raise superdesk.SuperdeskError(payload=msg) def get_users_mentions(text):
import superdesk from superdesk.notification import push_notification from superdesk.activity import add_activity, ACTIVITY_UPDATE from superdesk.metadata.item import FAMILY_ID from eve.utils import ParsedRequest class DeskTypes(SuperdeskBaseEnum): authoring = "authoring" production = "production" desks_schema = { "name": {"type": "string", "required": True, "nullable": False, "empty": False, "iunique": True}, "description": {"type": "string"}, "members": {"type": "list", "schema": {"type": "dict", "schema": {"user": Resource.rel("users", True)}}}, "incoming_stage": Resource.rel("stages", True), "working_stage": Resource.rel("stages", True), "content_expiry": {"type": "integer"}, "source": {"type": "string"}, "monitoring_settings": { "type": "list", "schema": { "type": "dict", "schema": { "_id": {"type": "string", "required": True}, "type": {"type": "string", "allowed": ["search", "stage", "deskOutput", "personal"], "required": True}, "max_items": {"type": "integer", "required": True}, }, }, },
import superdesk from superdesk.users.services import is_admin from superdesk.errors import SuperdeskApiError import logging logger = logging.getLogger('superdesk') blogs_schema = { 'title': metadata_schema['headline'], 'description': metadata_schema['description'], 'picture_url': { 'type': 'string', 'nullable': True }, 'picture': Resource.rel('archive', embeddable=True, nullable=True, type='string'), 'original_creator': metadata_schema['original_creator'], 'version_creator': metadata_schema['version_creator'], 'versioncreated': metadata_schema['versioncreated'], 'posts_order_sequence': { 'type': 'number', 'default': 0 }, 'blog_status': { 'type': 'string', 'allowed': ['open', 'closed'], 'default': 'open' }, 'members': { 'type': 'list', 'schema': {
desks_schema = { 'name': { 'type': 'string', 'iunique': True, 'required': True, }, 'description': { 'type': 'string' }, 'members': { 'type': 'list', 'schema': { 'type': 'dict', 'schema': { 'user': Resource.rel('users', True) } } }, 'incoming_stage': Resource.rel('stages', True), 'published_stage': Resource.rel('stages', False), 'spike_expiry': { 'type': 'integer' } } def init_app(app): endpoint_name = 'desks' service = DesksService(endpoint_name, backend=superdesk.get_backend()) DesksResource(endpoint_name, app=app, service=service)
'mapping': not_analyzed }, 'version': { 'type': 'integer' }, 'ingest_id': { 'type': 'string', 'mapping': not_analyzed }, 'family_id': { 'type': 'string', 'mapping': not_analyzed }, # Audit Information 'original_creator': Resource.rel('users'), 'version_creator': Resource.rel('users'), 'firstcreated': { 'type': 'datetime' }, 'versioncreated': { 'type': 'datetime' }, # Ingest Details 'ingest_provider': Resource.rel('ingest_providers'), 'source': { # The value is copied from the ingest_providers vocabulary 'type': 'string', 'mapping': not_analyzed }, 'original_source': { # This value is extracted from the ingest
from superdesk.emails import send_email import liveblog.embed from bson.objectid import ObjectId import superdesk from superdesk.users.services import is_admin from superdesk.errors import SuperdeskApiError import logging logger = logging.getLogger("superdesk") blogs_schema = { "title": metadata_schema["headline"], "description": metadata_schema["description"], "picture_url": {"type": "string", "nullable": True}, "picture": Resource.rel("archive", embeddable=True, nullable=True, type="string"), "original_creator": metadata_schema["original_creator"], "version_creator": metadata_schema["version_creator"], "versioncreated": metadata_schema["versioncreated"], "posts_order_sequence": {"type": "number", "default": 0}, "blog_status": {"type": "string", "allowed": ["open", "closed"], "default": "open"}, "members": {"type": "list", "schema": {"type": "dict", "schema": {"user": Resource.rel("users", True)}}}, "blog_preferences": {"type": "dict"}, "public_url": {"type": "string"}, } class BlogsResource(Resource): datasource = {"source": "blogs", "search_backend": "elastic", "default_sort": [("_updated", -1)]} item_methods = ["GET", "PATCH", "PUT", "DELETE"]
def __init__(self, endpoint_name, app, service, endpoint_schema=None): self.schema = { 'name': { 'type': 'string', 'required': True, 'nullable': False, 'empty': False, 'iunique': True }, 'source': required_string, 'feeding_service': { 'type': 'string', 'required': True, 'allowed': allowed_feeding_services }, 'feed_parser': { 'type': 'string', 'nullable': True, 'allowed': allowed_feed_parsers }, 'content_types': { 'type': 'list', 'default': content_type, 'allowed': content_type }, 'allow_remove_ingested': { 'type': 'boolean', 'default': False }, 'content_expiry': { 'type': 'integer', 'default': app.config['INGEST_EXPIRY_MINUTES'] }, 'config': { 'type': 'dict' }, 'ingested_count': { 'type': 'integer' }, 'accepted_count': { 'type': 'integer' }, 'tokens': { 'type': 'dict' }, 'is_closed': { 'type': 'boolean', 'default': False }, 'update_schedule': { 'type': 'dict', 'schema': { 'hours': {'type': 'integer'}, 'minutes': {'type': 'integer', 'default': 5}, 'seconds': {'type': 'integer'}, } }, 'idle_time': { 'type': 'dict', 'schema': { 'hours': {'type': 'integer'}, 'minutes': {'type': 'integer'}, } }, 'last_updated': {'type': 'datetime'}, 'last_ingested_id': {'type': 'string'}, # this id is ingest provider internal value 'last_item_update': {'type': 'datetime'}, 'rule_set': Resource.rel('rule_sets', nullable=True), 'routing_scheme': Resource.rel('routing_schemes', nullable=True), 'notifications': { 'type': 'dict', 'schema': { 'on_update': {'type': 'boolean', 'default': True}, 'on_close': {'type': 'boolean', 'default': True}, 'on_open': {'type': 'boolean', 'default': True}, 'on_error': {'type': 'boolean', 'default': True} } }, 'last_closed': { 'type': 'dict', 'schema': { 'closed_at': {'type': 'datetime'}, 'closed_by': Resource.rel('users', nullable=True), 'message': {'type': 'string'} } }, 'last_opened': { 'type': 'dict', 'schema': { 'opened_at': {'type': 'datetime'}, 'opened_by': Resource.rel('users', nullable=True) } }, 'critical_errors': { 'type': 'dict', 'valueschema': { 'type': 'boolean' } }, } self.item_methods = ['GET', 'PATCH', 'DELETE'] self.privileges = {'POST': 'ingest_providers', 'PATCH': 'ingest_providers', 'DELETE': 'ingest_providers'} self.etag_ignore_fields = ['last_updated', 'last_item_update', 'last_closed', 'last_opened'] super().__init__(endpoint_name, app, service, endpoint_schema=endpoint_schema)
# # Copyright 2013, 2014 Sourcefabric z.u. and contributors. # # For the full copyright and license information, please see the # AUTHORS and LICENSE files distributed with this source code, or # at https://www.sourcefabric.org/superdesk/license import superdesk from superdesk.resource import Resource from superdesk.services import BaseService from apps.comments import CommentsService, CommentsResource, comments_schema from superdesk.errors import SuperdeskApiError comments_schema = dict(comments_schema) comments_schema.update({'item': Resource.rel('archive', True, True, type='string')}) class ItemCommentsResource(CommentsResource): schema = comments_schema resource_methods = ['GET', 'POST', 'DELETE'] datasource = {'default_sort': [('_created', -1)]} privileges = {'POST': 'archive', 'DELETE': 'archive'} class ItemCommentsService(CommentsService): notification_key = 'item:comment' class ItemCommentsSubResource(Resource): url = 'archive/<path:item>/comments'
}, 'ingest_id': { 'type': 'string', 'mapping': not_analyzed }, 'family_id': { 'type': 'string', 'mapping': not_analyzed }, 'related_to': { # this field keeps a reference to the related item from which metadata has been copied 'type': 'string', 'mapping': not_analyzed }, # Audit Information 'original_creator': Resource.rel('users'), 'version_creator': Resource.rel('users'), 'firstcreated': { 'type': 'datetime' }, 'versioncreated': { 'type': 'datetime' }, 'firstpublished': { 'type': 'datetime', 'required': False, 'nullable': True, }, # Ingest Details 'ingest_provider': Resource.rel('ingest_providers'),
def __init__(self, endpoint_name, app, service, endpoint_schema=None): self.readonly = True if app.config.get('LDAP_SERVER', None) else False self.additional_lookup = { 'url': r'regex("[\w]+")', 'field': 'username' } self.schema = { 'username': { 'type': 'string', 'unique': True, 'required': True, 'minlength': 1 }, 'password': { 'type': 'string', 'minlength': 5 }, 'password_changed_on': { 'type': 'datetime', 'nullable': True }, 'first_name': { 'type': 'string', 'readonly': self.readonly }, 'last_name': { 'type': 'string', 'readonly': self.readonly }, 'display_name': { 'type': 'string' }, 'email': { 'unique': True, 'type': 'email', 'required': True, 'coerce': lambda s: s.lower() }, 'phone': { 'type': 'string', 'nullable': True }, 'job_title': { 'type': 'string', 'required': False, }, 'biography': { 'type': 'string', 'required': False, 'nullable': True, }, 'facebook': { 'type': 'string', 'required': False, 'nullable': True, }, 'instagram': { 'type': 'string', 'required': False, 'nullable': True, }, 'twitter': { 'type': 'string', 'required': False, 'nullable': True, 'twitter': True, }, 'jid': { 'unique': True, 'type': 'string', 'required': False, }, 'language': { 'type': 'string', 'nullable': True }, 'user_info': { 'type': 'dict' }, 'picture_url': { 'type': 'string', 'nullable': True }, 'avatar': Resource.rel('upload', embeddable=True, nullable=True), 'avatar_renditions': {'type': 'dict'}, 'role': Resource.rel('roles', True), 'privileges': {'type': 'dict'}, 'workspace': { 'type': 'dict' }, 'user_type': { 'type': 'string', 'allowed': ['user', 'administrator'], 'default': 'user' }, 'is_support': { 'type': 'boolean', 'default': False }, 'is_author': { 'type': 'boolean', 'default': True }, 'is_active': { 'type': 'boolean', 'default': True }, 'is_enabled': { 'type': 'boolean', 'default': True }, 'needs_activation': { 'type': 'boolean', 'default': True }, # Default desk of the user, which would be selected when logged-in. 'desk': Resource.rel('desks', nullable=True), SIGN_OFF: { # Used for putting a sign-off on the content when it's created/updated except kill 'type': 'string', 'required': False, 'nullable': True, 'regex': '^[a-zA-Z0-9]+$' }, BYLINE: { 'type': 'string', 'required': False, 'nullable': True }, # list to hold invisible stages. # This field is updated under following scenario: # 1. stage visible flag is updated # 2. desk membership is modified # 3. new user is created 'invisible_stages': { 'type': 'list', 'required': False, 'nullable': True }, # If Slack notifications are configured and enabled for the user # the Slack username is stored here. 'slack_username': { 'type': 'string', 'required': False, 'nullable': True }, # The Slack user id is stored here, to avoid repeatedly having to look it up 'slack_user_id': { 'type': 'string', 'required': False, 'nullable': True } } self.extra_response_fields = [ 'display_name', 'username', 'email', 'user_info', 'picture_url', 'avatar', 'is_active', 'is_enabled', 'needs_activation', 'desk' ] self.etag_ignore_fields = ['session_preferences', '_etag', 'invisible_stages'] self.datasource = { 'projection': {'password': 0}, 'default_sort': [('username', 1)], } self.mongo_indexes = { 'username_1': ([('username', 1)], {'unique': True}), 'first_name_1_last_name_-1': [('first_name', 1), ('last_name', -1)], } self.privileges = {'POST': 'users', 'DELETE': 'users', 'PATCH': 'users'} super().__init__(endpoint_name, app=app, service=service, endpoint_schema=endpoint_schema)
from superdesk.services import BaseService from superdesk.notification import push_notification from superdesk.activity import add_activity, ACTIVITY_UPDATE from superdesk.metadata.item import FAMILY_ID from eve.utils import ParsedRequest class DeskTypes(SuperdeskBaseEnum): authoring = "authoring" production = "production" desks_schema = { "name": {"type": "string", "required": True, "nullable": False, "empty": False, "iunique": True}, "description": {"type": "string"}, "members": {"type": "list", "schema": {"type": "dict", "schema": {"user": Resource.rel("users", True)}}}, "incoming_stage": Resource.rel("stages", True), "working_stage": Resource.rel("stages", True), "content_expiry": {"type": "integer"}, "source": {"type": "string"}, "monitoring_settings": { "type": "list", "schema": { "type": "dict", "schema": { "_id": {"type": "string", "required": True}, "type": { "type": "string", "allowed": ["search", "stage", "scheduledDeskOutput", "deskOutput", "personal"], "required": True, },
from bson.objectid import ObjectId import flask import superdesk import eve.io.base blogs_schema = { 'guid': metadata_schema['guid'], 'title': metadata_schema['headline'], 'description': metadata_schema['description'], 'theme': { 'type': 'dict' }, 'picture_url': { 'type': 'string', }, 'picture': Resource.rel('upload', True), 'original_creator': metadata_schema['original_creator'], 'version_creator': metadata_schema['version_creator'], 'versioncreated': metadata_schema['versioncreated'], 'blog_status': { 'type': 'string', 'allowed': ['open', 'closed'], 'default': 'open' }, 'particular_type': { 'type': 'string', 'allowed': ['blog'], 'default': 'blog' }, 'members': { 'type': 'list',
blogs_schema = { 'title': { 'type': 'string', 'required': True, }, 'description': { 'type': 'string' }, 'language': { 'type': 'string' }, 'settings': { 'type': 'dict' }, 'original_creator': Resource.rel('users', True), 'version_creator': Resource.rel('users', True), 'state': { 'type': 'string', 'allowed': ['open', 'closed'], 'default': 'open' } } class BlogsResource(Resource): schema = blogs_schema datasource = { 'default_sort': [('_updated', -1)] }
}, 'ingest_id': { 'type': 'string', 'mapping': not_analyzed }, 'family_id': { 'type': 'string', 'mapping': not_analyzed }, 'related_to': { # this field keeps a reference to the related item from which metadata has been copied 'type': 'string', 'mapping': not_analyzed }, # Audit Information 'original_creator': Resource.rel('users'), 'version_creator': Resource.rel('users'), 'firstcreated': { 'type': 'datetime' }, 'versioncreated': { 'type': 'datetime' }, # Ingest Details 'ingest_provider': Resource.rel('ingest_providers'), 'source': { # The value is copied from the ingest_providers vocabulary 'type': 'string', 'mapping': not_analyzed }, 'original_source': { # This value is extracted from the ingest
'unique_name': { 'type': 'string', 'unique': True, 'mapping': not_analyzed }, 'parent_id': { 'type': 'string', 'unique': True, 'mapping': not_analyzed }, 'version': { 'type': 'integer' }, # Audit Information 'original_creator': Resource.rel('users'), 'version_creator': Resource.rel('users'), 'firstcreated': { 'type': 'datetime' }, 'versioncreated': { 'type': 'datetime' }, # Ingest Details 'ingest_provider': Resource.rel('ingest_providers'), 'source': { # The value is copied from the ingest_providers vocabulary 'type': 'string', 'mapping': not_analyzed }, 'original_source': { # This value is extracted from the ingest
def __init__(self, endpoint_name, app, service, endpoint_schema=None): self.readonly = True if app.config.get('LDAP_SERVER', None) else False self.additional_lookup = { 'url': 'regex("[\w]+")', 'field': 'username' } self.schema = { 'username': { 'type': 'string', 'unique': True, 'required': True, 'minlength': 1 }, 'password': { 'type': 'string', 'minlength': 5 }, 'first_name': { 'type': 'string', 'readonly': self.readonly }, 'last_name': { 'type': 'string', 'readonly': self.readonly }, 'display_name': { 'type': 'string' }, 'email': { 'unique': True, 'type': 'email', 'required': True }, 'phone': { 'type': 'string', 'nullable': True }, 'language': { 'type': 'string', 'nullable': True }, 'user_info': { 'type': 'dict' }, 'picture_url': { 'type': 'string', 'nullable': True }, 'avatar': Resource.rel('upload', embeddable=True, nullable=True), 'role': Resource.rel('roles', True), 'privileges': {'type': 'dict'}, 'workspace': { 'type': 'dict' }, 'user_type': { 'type': 'string', 'allowed': ['user', 'administrator'], 'default': 'user' }, 'is_active': { 'type': 'boolean', 'default': True }, 'is_enabled': { 'type': 'boolean', 'default': True }, 'needs_activation': { 'type': 'boolean', 'default': True }, 'desk': Resource.rel('desks'), # Default desk of the user, which would be selected when logged-in. SIGN_OFF: { # Used for putting a sign-off on the content when it's created/updated except kill 'type': 'string', 'required': False, 'regex': '^[a-zA-Z0-9]+$' }, BYLINE: { 'type': 'string', 'required': False, 'nullable': True } } self.extra_response_fields = [ 'display_name', 'username', 'email', 'user_info', 'picture_url', 'avatar', 'is_active', 'is_enabled', 'needs_activation', 'desk' ] self.etag_ignore_fields = ['session_preferences', '_etag'] self.datasource = { 'projection': {'password': 0}, 'default_sort': [('username', 1)], } self.privileges = {'POST': 'users', 'DELETE': 'users', 'PATCH': 'users'} super().__init__(endpoint_name, app=app, service=service, endpoint_schema=endpoint_schema)
'name': { 'type': 'string', 'required': True, 'nullable': False, 'empty': False, 'iunique': True }, 'description': { 'type': 'string' }, 'members': { 'type': 'list', 'schema': { 'type': 'dict', 'schema': { 'user': Resource.rel('users', True) } } }, 'incoming_stage': Resource.rel('stages', True), 'working_stage': Resource.rel('stages', True), 'content_expiry': { 'type': 'integer' }, 'source': { 'type': 'string' }, 'monitoring_settings': { 'type': 'list', 'schema': { 'type': 'dict',
import flask import superdesk import eve.io.base blogs_schema = { 'guid': metadata_schema['guid'], 'title': metadata_schema['headline'], 'description': metadata_schema['description'], 'theme': { 'type': 'dict' }, 'picture_url': { 'type': 'string', 'nullable': True }, 'picture': Resource.rel('upload', embeddable=True, nullable=True), 'original_creator': metadata_schema['original_creator'], 'version_creator': metadata_schema['version_creator'], 'versioncreated': metadata_schema['versioncreated'], 'blog_status': { 'type': 'string', 'allowed': ['open', 'closed'], 'default': 'open' }, 'particular_type': { 'type': 'string', 'allowed': ['blog'], 'default': 'blog' }, 'members': { 'type': 'list',
username = g.user.get('display_name') or g.user.get('username') url = '{}/#/liveblog/settings/{}'.format(origin, doc['_id']) title = blog['title'] admins = app.config['ADMINS'] app_name = app.config['APPLICATION_NAME'] subject = render_template("owner_email_subject.txt", app_name=app_name) text_body = render_template("owner_request.txt", app_name=app_name, link=url, name_of_user=username, title=title) html_body = render_template("owner_request.html", app_name=app_name, link=url, name_of_user=username, title=title) send_email.delay(subject=subject, sender=admins[0], recipients=recipients, text_body=text_body, html_body=html_body) request_schema = { 'blog': Resource.rel('blogs', True), 'original_creator': Resource.rel('users', True), 'message': { 'type': 'string' } } class MembershipResource(Resource): schema = request_schema datasource = { 'source': 'request_membership', 'default_sort': [('_updated', -1)] } resource_methods = ['POST', 'GET'] item_methods = ['GET', 'DELETE']
EMBARGO = "embargo" metadata_schema = { # Identifiers "guid": {"type": "string", "unique": True, "mapping": not_analyzed}, "unique_id": {"type": "integer", "unique": True}, "unique_name": {"type": "string", "unique": True, "mapping": not_analyzed}, "version": {"type": "integer"}, "ingest_id": {"type": "string", "mapping": not_analyzed}, "family_id": {"type": "string", "mapping": not_analyzed}, "related_to": { # this field keeps a reference to the related item from which metadata has been copied "type": "string", "mapping": not_analyzed, }, # Audit Information "original_creator": Resource.rel("users"), "version_creator": Resource.rel("users"), "firstcreated": {"type": "datetime"}, "versioncreated": {"type": "datetime"}, # Ingest Details "ingest_provider": Resource.rel("ingest_providers"), "source": {"type": "string", "mapping": not_analyzed}, # The value is copied from the ingest_providers vocabulary "original_source": {"type": "string", "mapping": not_analyzed}, # This value is extracted from the ingest "ingest_provider_sequence": {"type": "string", "mapping": not_analyzed}, # Copyright Information "usageterms": {"type": "string", "mapping": not_analyzed, "nullable": True}, # Category Details "anpa_category": { "type": "list", "nullable": True, "mapping": {"type": "object", "properties": {"qcode": not_analyzed, "name": not_analyzed}},
'urgency': { 'type': 'integer' }, 'groups': { 'type': 'list' }, 'keywords': { 'type': 'list' }, 'body_html': { 'type': 'string' }, 'creator': { 'type': 'dict', 'schema': { 'user': Resource.rel('users', True) } }, 'media_file': { 'type': 'string' }, 'contents': { 'type': 'list' }, 'media': { 'type': 'media' }, 'task_id': { 'type': 'string' }, 'lock_user': {