コード例 #1
0
class ContentTemplatesResource(Resource):
    schema = {
        'data': {
            'type': 'dict',
            'schema': metadata_schema,
        },
        'template_name': {
            'type': 'string',
            'iunique': True,
            'required': True,
        },
        'template_type': {
            'type': 'string',
            'required': True,
            'allowed': TemplateType.values(),
            'default': TemplateType.CREATE.value,
        },
        'template_desk': Resource.rel('desks', embeddable=False,
                                      nullable=True),
        'template_stage': Resource.rel('stages',
                                       embeddable=False,
                                       nullable=True),
        'schedule': {
            'type': 'dict',
            'schema': {
                'is_active': {
                    'type': 'boolean'
                },
                'create_at': {
                    'type': 'string'
                },
                'day_of_week': {
                    'type': 'list'
                },
            }
        },
        'last_run': {
            'type': 'datetime',
            'readonly': True
        },
        'next_run': {
            'type': 'datetime',
            'readonly': True
        },
        'user': Resource.rel('users'),
        'is_public': {
            'type': 'boolean',
            'default': False
        },
    }

    additional_lookup = {'url': 'regex("[\w]+")', 'field': 'template_name'}

    resource_methods = ['GET', 'POST']
    item_methods = ['GET', 'PATCH', 'DELETE']
    privileges = {
        'POST': CONTENT_TEMPLATE_PRIVILEGE,
        'PATCH': CONTENT_TEMPLATE_PRIVILEGE,
        'DELETE': CONTENT_TEMPLATE_PRIVILEGE
    }
コード例 #2
0
class AgendasResource(Resource):
    url = 'agenda'
    schema = {
        'name': {
            'type': 'string',
            'iunique': True,
            'required': True,
            'empty': False,
            'nullable': False
        },
        # Audit Information
        'original_creator': Resource.rel('users'),
        'version_creator': Resource.rel('users'),
        'is_enabled': {
            'type': 'boolean',
            'default': True
        },
    }

    resource_methods = ['GET', 'POST']
    item_methods = ['GET', 'PATCH', 'DELETE']

    privileges = {
        'POST': 'planning_agenda_management',
        'PATCH': 'planning_agenda_management',
        'DELETE': 'planning_agenda_management'
    }
コード例 #3
0
class ContentTemplatesResource(Resource):
    schema = {
        "data": {
            "type": "dict",
            "schema": get_schema(),
        },
        "template_name": {
            "type": "string",
            "unique_template": True,
            "required": True,
        },
        "template_type": {
            "type": "string",
            "required": True,
            "allowed": TemplateType.values(),
            "default": TemplateType.CREATE.value,
        },
        "template_desks": {
            "type": "list",
            "required": False,
            "nullable": True,
            "schema": Resource.rel("desks", embeddable=False, nullable=True),
        },
        "schedule_desk": Resource.rel("desks", embeddable=False, nullable=True),
        "schedule_stage": Resource.rel("stages", embeddable=False, nullable=True),
        "schedule_macro": {"type": "string", "nullable": True},
        "schedule": {
            "type": "dict",
            "schema": {
                "is_active": {"type": "boolean"},
                "create_at": {"type": "string"},
                # List of cron expressions that determine the times items should be created.
                "cron_list": {"type": "list", "required": False, "nullable": True, "schema": {"type": "string"}},
                "day_of_week": {"type": "list"},
                "time_zone": {"type": "string", "nullable": True},
            },
        },
        "last_run": {"type": "datetime", "readonly": True},
        "next_run": {"type": "datetime", "readonly": True},
        "user": Resource.rel("users"),
        "is_public": {"type": "boolean", "unique_template": True, "default": False},
        "item": {
            "type": "dict",
            "schema": {},
            "allow_unknown": True,
        },
    }

    additional_lookup = {"url": 'regex("[\w]+")', "field": "template_name"}

    resource_methods = ["GET", "POST"]
    item_methods = ["GET", "PATCH", "DELETE"]
    no_privileges = True

    merge_nested_documents = True

    mongo_indexes = {
        "user_1_template_name_1_is_public_1": ([("user", 1), ("template_name", 1), ("is_public", 1)], {"unique": True}),
    }
コード例 #4
0
class PlanningHistoryResource(Resource):
    """Resource for keeping track of the history of planning entries
    """

    endpoint_name = 'planning_history'
    resource_methods = ['GET']
    item_methods = ['GET']
    schema = {
        'planning_id': Resource.rel('planning', True),
        'user_id': Resource.rel('users', True),
        'operation': {'type': 'string'},
        'update': {'type': 'dict', 'nullable': True}
    }
コード例 #5
0
class SavedSearchesResource(Resource):
    endpoint_name = resource_title = 'saved_searches'
    schema = {
        'name': {
            'type': 'string',
            'required': True,
            'minlength': 1
        },
        'description': {
            'type': 'string'
        },
        'filter': {
            'type': 'dict',
            'required': True
        },
        'user': Resource.rel('users'),
        'is_global': {
            'type': 'boolean',
            'default': False
        }
    }

    url = 'users/<regex("[a-zA-Z0-9:\\-\\.]+"):user>/saved_searches'

    item_methods = ['GET', 'PATCH', 'DELETE']

    privileges = {
        'POST': 'saved_searches',
        'PATCH': 'saved_searches',
        'DELETE': 'saved_searches'
    }
コード例 #6
0
class ActivityReportResource(Resource):
    schema = {
        'users': Resource.rel('users'),
        'create_count': {
            'type': 'integer'
        },
        'submit_count': {
            'type': 'integer'
        },
        'publish_count': {
            'type': 'integer'
        },
        'update_count': {
            'type': 'integer'
        },
        'total_count': {
            'type': 'integer'
        },
        'activity_date': {
            'type': 'datetime'
        }
    }

    item_methods = []
    resource_methods = []
    internal_resource = True
コード例 #7
0
class EventsHistoryResource(Resource):
    endpoint_name = 'events_history'
    resource_methods = ['GET']
    item_methods = ['GET']
    schema = {
        'event_id': {'type': 'string'},
        'user_id': Resource.rel('users', True),
        'operation': {'type': 'string'},
        'update': {'type': 'dict', 'nullable': True}
    }
コード例 #8
0
class PlanningArticleExportResource(Resource):
    schema = get_schema(versioning=True)
    schema.update({
        'items': {
            'type': 'list',
            'required': True,
        },
        'desk':
        Resource.rel('desks', nullable=True),
        'template': {
            'type': 'string'
        },
        'type': {
            'type': 'string',
            'default': 'planning',
        },
        'article_template':
        Resource.rel('content_templates', nullable=True)
    })

    item_methods = []
    resource_methods = ['POST']
    privileges = {'POST': 'planning'}
コード例 #9
0
#
# 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

from superdesk import Resource
from superdesk.resource import not_analyzed
from superdesk.metadata.item import metadata_schema, ITEM_TYPE
from copy import deepcopy

from planning.common import WORKFLOW_STATE_SCHEMA, POST_STATE_SCHEMA, UPDATE_METHODS, \
    TO_BE_CONFIRMED_FIELD, TO_BE_CONFIRMED_FIELD_SCHEMA

event_type = deepcopy(Resource.rel('events', type='string'))
event_type['mapping'] = not_analyzed

planning_type = deepcopy(Resource.rel('planning', type='string'))
planning_type['mapping'] = not_analyzed
original_creator_schema = metadata_schema['original_creator']
original_creator_schema.update({'nullable': True})

events_schema = {
    # Identifiers
    '_id': metadata_schema['_id'],
    'guid': metadata_schema['guid'],
    'unique_id': metadata_schema['unique_id'],
    'unique_name': metadata_schema['unique_name'],
    'version': metadata_schema['version'],
    'ingest_id': metadata_schema['ingest_id'],
コード例 #10
0
    # Identifier used to synchronise the posted planning item with an external system.
    'unique_id': {
        'type': 'string',
        'mapping': not_analyzed
    },
    'place': metadata_schema['place'],

    # Name used to identify the planning item
    'name': {
        'type': 'string'
    },
    'files': {
        'type': 'list',
        'nullable': True,
        'schema': Resource.rel('planning_files'),
        'mapping': not_analyzed,
    },
    # Reason (if any) for the current state (cancelled, postponed, rescheduled)
    'state_reason': {
        'type': 'string',
        'nullable': True
    }
}  # end planning_schema


class PlanningResource(superdesk.Resource):
    """Resource for planning data model

    See IPTC-G2-Implementation_Guide (version 2.21) Section 16.5 for schema details
    """
コード例 #11
0
class EventsTemplateResource(Resource):
    """
    Resource for events template
    """

    endpoint_name = 'events_template'
    resource_methods = ['GET', 'POST']
    item_methods = ['GET', 'DELETE', 'PATCH', 'PUT']
    privileges = {
        'GET': 'planning_event_management',
        'POST': 'planning_event_templates',
        'DELETE': 'planning_event_templates',
        'PATCH': 'planning_event_templates',
        'PUT': 'planning_event_templates'
    }
    _event_fields = {
        'slugline': {
            'type': 'string',
            'required': False,
            'readonly': True
        },
        'name': {
            'type': 'string',
            'required': False,
            'readonly': True
        },
        'definition_short': {
            'type': 'string',
            'required': False,
            'readonly': True
        },
        'definition_long': {
            'type': 'string',
            'required': False,
            'readonly': True
        },
        'internal_note': {
            'type': 'string',
            'required': False,
            'readonly': True
        },
        'ednote': {
            'type': 'string',
            'required': False,
            'readonly': True
        },
        'links': {
            'type': 'list',
            'readonly': True
        },
        'occur_status': {
            'type': 'dict',
            'schema': {
                'qcode': {
                    'type': 'string'
                },
                'name': {
                    'type': 'string'
                },
                'label': {
                    'type': 'string'
                },
            },
            'readonly': True
        },
        'files': {
            'type': 'list',
            'schema': Resource.rel('events_files'),
            'readonly': True
        },
        'calendars': {
            'type': 'list',
            'schema': {
                'type': 'dict',
                'schema': {
                    'qcode': {
                        'type': 'string'
                    },
                    'name': {
                        'type': 'string'
                    },
                    'is_active': {
                        'type': 'boolean'
                    }
                }
            },
            'readonly': True
        },
        'location': {
            'type': 'list',
            'schema': {
                'type': 'dict'
            },
            'readonly': True
        },
        'event_contact_info': {
            'type': 'list',
            'schema': Resource.rel('contacts'),
            'readonly': True
        },
        'subject': {
            'type': 'list',
            'schema': {
                'type': 'dict'
            },
            'readonly': True
        }
    }
    schema = {
        'template_name': {
            'type': 'string',
            'required': True,
            'empty': False,
            'unique': True
        },
        'based_on_event': Resource.rel(
            'events',
            type=metadata_schema[config.ID_FIELD]['type'],
            embeddable=False,
            required=True
        ),
        'data': {
            'type': 'dict',
            'schema': _event_fields
        }
    }
コード例 #12
0
# This file is part of Superdesk.
#
# 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

from superdesk import Resource
from superdesk.resource import not_analyzed
from superdesk.metadata.item import metadata_schema, ITEM_TYPE
from copy import deepcopy

from planning.common import WORKFLOW_STATE_SCHEMA, POST_STATE_SCHEMA, UPDATE_METHODS

event_type = deepcopy(Resource.rel('events', type='string'))
event_type['mapping'] = not_analyzed

planning_type = deepcopy(Resource.rel('planning', type='string'))
planning_type['mapping'] = not_analyzed
original_creator_schema = metadata_schema['original_creator']
original_creator_schema.update({'nullable': True})

events_schema = {
    # Identifiers
    '_id': metadata_schema['_id'],
    'guid': metadata_schema['guid'],
    'unique_id': metadata_schema['unique_id'],
    'unique_name': metadata_schema['unique_name'],
    'version': metadata_schema['version'],
    'ingest_id': metadata_schema['ingest_id'],
コード例 #13
0

filters_schema = {
    'name': {
        'type': 'string',
        'iunique': True,
        'required': True
    },
    'item_type': {
        'type': 'string',
        'allowed': tuple(ITEM_TYPES),
        'default': ITEM_TYPES.COMBINED,
        'nullable': False,
    },
    # Audit Information
    'original_creator': Resource.rel('users'),
    'version_creator': Resource.rel('users'),
    'params': {
        'type': 'dict',
        'schema': {
            # Common Fields
            'item_ids':
            list_strings(),
            'name':
            string(),
            'tz_offset':
            string(),
            'full_text':
            string(),
            'anpa_category':
            list_cvs(),
コード例 #14
0
endpoint = 'events_planning_filters'

filters_schema = {
    'name': {
        'type': 'string',
        'iunique': True,
        'required': True
    },
    'agendas': {
        'type': 'list',
    },
    'calendars': {
        'type': 'list',
    },
    # Audit Information
    'original_creator': Resource.rel('users'),
    'version_creator': Resource.rel('users')
}


class EventPlanningFiltersResource(superdesk.Resource):
    """Resource for Event and Planning Filters"""

    endpoint_name = endpoint
    url = endpoint
    schema = filters_schema
    resource_methods = ['GET', 'POST']
    item_methods = ['GET', 'PATCH', 'PUT', 'DELETE']
    privileges = {'POST': 'planning_eventsplanning_filters_management',
                  'PATCH': 'planning_eventsplanning_filters_management',
                  'DELETE': 'planning_eventsplanning_filters_management'}
コード例 #15
0
def list_rel(resource, id_type='objectid'):
    return {
        'type': 'list',
        'nullable': True,
        'schema': Resource.rel(resource, type=id_type)
    }
コード例 #16
0
class ContentTemplatesResource(Resource):
    schema = {
        'data': {
            'type': 'dict',
            'schema': get_schema(),
        },

        'template_name': {
            'type': 'string',
            'unique_template': True,
            'required': True,
        },

        'template_type': {
            'type': 'string',
            'required': True,
            'allowed': TemplateType.values(),
            'default': TemplateType.CREATE.value,
        },

        'template_desks': {
            'type': 'list',
            'required': False,
            'nullable': True,
            'schema': Resource.rel('desks', embeddable=False, nullable=True)
        },

        'schedule_desk': Resource.rel('desks', embeddable=False, nullable=True),

        'schedule_stage': Resource.rel('stages', embeddable=False, nullable=True),

        'schedule': {'type': 'dict', 'schema': {
            'is_active': {'type': 'boolean'},
            'create_at': {'type': 'string'},
            # List of cron expressions that determine the times items should be created.
            'cron_list': {'type': 'list', 'required': False, 'nullable': True,
                          'schema': {'type': 'string'}},
            'day_of_week': {'type': 'list'},
            'time_zone': {
                'type': 'string',
                'nullable': True
            }
        }},

        'last_run': {'type': 'datetime', 'readonly': True},
        'next_run': {'type': 'datetime', 'readonly': True},

        'user': Resource.rel('users'),
        'is_public': {'type': 'boolean', 'unique_template': True, 'default': False},

        'item': {
            'type': 'dict',
            'schema': {},
            'allow_unknown': True,
        },
    }

    additional_lookup = {
        'url': 'regex("[\w]+")',
        'field': 'template_name'
    }

    resource_methods = ['GET', 'POST']
    item_methods = ['GET', 'PATCH', 'DELETE']
    privileges = {'POST': CONTENT_TEMPLATE_PRIVILEGE,
                  'PATCH': CONTENT_TEMPLATE_PRIVILEGE,
                  'DELETE': CONTENT_TEMPLATE_PRIVILEGE}

    merge_nested_documents = True

    mongo_indexes = {
        'user_1_template_name_1': ([('user', 1), ('template_name', 1)], {'unique': True}),
    }
コード例 #17
0
    },
    'unique_name': {
        'type': 'string',
        'unique': True,
        'mapping': not_analyzed
    },
    'version': {
        'type': 'integer'
    },
    'ingest_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
コード例 #18
0
class SavedSearchesResource(Resource):
    endpoint_name = resource_title = 'saved_searches'
    schema = {
        'name': {
            'type': 'string',
            'required': True,
            'minlength': 1
        },
        'description': {
            'type': 'string'
        },
        'filter': {
            'type': 'dict',
            'schema': {},
            'required': True,
            'allow_unknown': True,
        },
        'user': Resource.rel('users', nullable=True),
        'is_global': {
            'type': 'boolean',
            'default': False
        },
        'shortcut': {
            'type': 'boolean',
            'default': False,
        },
        'subscribers': {
            'type': 'dict',
            'schema': {
                'user_subscriptions': {
                    'type': 'list',
                    'schema': {
                        'type': 'dict',
                        'schema': {
                            'user': Resource.rel('users', True),
                            'scheduling': {
                                'type': 'string',
                                'required': True
                            },
                            'last_report': {
                                'type': 'datetime',
                                'nullable': True,
                                'readonly': True
                            },
                            'next_report': {
                                'type': 'datetime',
                                'readonly': True
                            }
                        }
                    }
                },
                'desk_subscriptions': {
                    'type': 'list',
                    'schema': {
                        'type': 'dict',
                        'schema': {
                            'desk': Resource.rel('desks', True),
                            'scheduling': {
                                'type': 'string'
                            },
                            'last_report': {
                                'type': 'datetime',
                                'nullable': True,
                                'readonly': True
                            },
                            'next_report': {
                                'type': 'datetime',
                                'readonly': True
                            }
                        }
                    }
                },
            }
        },
    }

    url = 'saved_searches'

    item_methods = ['GET', 'PATCH', 'DELETE']

    privileges = {
        'POST': 'saved_searches',
        'PATCH': 'saved_searches',
        'DELETE': 'saved_searches'
    }
コード例 #19
0
class SavedSearchesResource(Resource):
    endpoint_name = resource_title = "saved_searches"
    schema = {
        "name": {
            "type": "string",
            "required": True,
            "minlength": 1
        },
        "description": {
            "type": "string"
        },
        "filter": {
            "type": "dict",
            "schema": {},
            "required": True,
            "allow_unknown": True,
        },
        "user": Resource.rel("users", nullable=True),
        "is_global": {
            "type": "boolean",
            "default": False
        },
        "shortcut": {
            "type": "boolean",
            "default": False,
        },
        "subscribers": {
            "type": "dict",
            "schema": {
                "user_subscriptions": {
                    "type": "list",
                    "schema": {
                        "type": "dict",
                        "schema": {
                            "user": Resource.rel("users", True),
                            "scheduling": {
                                "type": "string",
                                "required": True
                            },
                            "last_report": {
                                "type": "datetime",
                                "nullable": True,
                                "readonly": True
                            },
                            "next_report": {
                                "type": "datetime",
                                "readonly": True
                            },
                        },
                    },
                },
                "desk_subscriptions": {
                    "type": "list",
                    "schema": {
                        "type": "dict",
                        "schema": {
                            "desk": Resource.rel("desks", True),
                            "scheduling": {
                                "type": "string"
                            },
                            "last_report": {
                                "type": "datetime",
                                "nullable": True,
                                "readonly": True
                            },
                            "next_report": {
                                "type": "datetime",
                                "readonly": True
                            },
                        },
                    },
                },
            },
        },
    }

    url = "saved_searches"

    item_methods = ["GET", "PATCH", "DELETE"]

    privileges = {
        "POST": "saved_searches",
        "PATCH": "saved_searches",
        "DELETE": "saved_searches"
    }