Example #1
0
def init_app(app):
    superdesk.register_resource('workspaces', WorkspaceResource, WorkspaceService,
                                privilege=['POST', 'PATCH'])
    superdesk.register_default_user_preference('workspace:active', {
        'type': 'string',
        'workspace': ''
    })
Example #2
0
def init_app(app):
    superdesk.register_resource('workspaces', WorkspaceResource, WorkspaceService,
                                privilege=['POST', 'PATCH', 'DELETE'])
    superdesk.register_default_user_preference('workspace:active', {
        'type': 'string',
        'workspace': ''
    })
def init_app(app):
    endpoint_name = 'vocabularies'
    service = VocabulariesService(endpoint_name, backend=superdesk.get_backend())
    VocabulariesResource(endpoint_name, app=app, service=service)

    superdesk.register_default_user_preference('cvs:preferred_items', {
        'value': {},
        'category': 'cvs',
        'label': 'Prefered CV items',
    })
Example #4
0
def init_app(app) -> None:
    superdesk.register_resource(
        "workspaces", WorkspaceResource, WorkspaceService, privilege=["POST", "PATCH", "DELETE"]
    )

    superdesk.register_default_user_preference("workspace:active", {"type": "string", "workspace": ""})

    superdesk.privilege(
        name="dashboard", label=lazy_gettext("Dashboard"), description=lazy_gettext("Can access dashboard.")
    )
Example #5
0
def init_app(app):
    endpoint_name = 'vocabularies'
    service = VocabulariesService(endpoint_name,
                                  backend=superdesk.get_backend())
    VocabulariesResource(endpoint_name, app=app, service=service)

    superdesk.register_default_user_preference('cvs:preferred_items', {
        'value': {},
        'category': 'cvs',
        'label': 'Prefered CV items',
    })
def init_app(app):
    superdesk.register_default_user_preference('monitoring:view', {
        'type': 'string',
        'allowed': ['list', 'swimlane'],
        'view': 'list',
        'default': 'list',
        'label': 'Monitoring view',
        'category': 'monitoring',
    })

    superdesk.register_default_session_preference('monitoring:view:session', None)
Example #7
0
def init_app(app):
    superdesk.register_default_user_preference(
        'monitoring:view', {
            'type': 'string',
            'allowed': ['list', 'swimlane'],
            'view': 'list',
            'default': 'list',
            'label': _('Monitoring view'),
            'category': _('monitoring'),
        })

    superdesk.register_default_session_preference('monitoring:view:session',
                                                  None)
Example #8
0
def init_app(app):
    endpoint_name = 'vocabularies'
    service = VocabulariesService(endpoint_name,
                                  backend=superdesk.get_backend())
    VocabulariesResource(endpoint_name, app=app, service=service)

    superdesk.register_default_user_preference('cvs:preferred_items', {
        'value': {},
        'category': _('cvs'),
        'label': _('Prefered CV items'),
    })

    item_published.connect(add_missing_keywords)
Example #9
0
class ActivityResource(Resource):
    endpoint_name = "activity"
    resource_methods = ["GET"]
    item_methods = ["GET", "PATCH"]
    schema = {
        "name": {"type": "string"},
        "message": {"type": "string"},
        "data": {"type": "dict", "schema": {}, "allow_unknown": True},
        "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"),
        "item_slugline": {"type": "string"},
        "user": Resource.rel("users"),
        "user_name": {"type": "string"},
        "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"),
        },
    )
    superdesk.register_default_user_preference(
        "desktop:notification",
        {
            "type": "bool",
            "enabled": True,
            "default": False,
            "label": _("Allow Desktop Notifications"),
            "category": _("notifications"),
        },
    )
Example #10
0
class PreferencesResource(Resource):
    datasource = {
        'source': 'auth',
        'projection': {
            'session_preferences': 1,
            'user': 1
        }
    }
    schema = {
        _session_preferences_key: {
            'type': 'dict',
            'required': True
        },
        _user_preferences_key: {
            'type': 'dict',
            'required': True
        },
        _privileges_key: {
            'type': 'dict'
        }
    }
    resource_methods = []
    item_methods = ['GET', 'PATCH']

    superdesk.register_default_user_preference(
        'feature:preview', {
            'type': 'bool',
            'enabled': False,
            'default': False,
            'label': 'Enable Feature Preview',
            'category': 'feature'
        })

    superdesk.register_default_user_preference(
        'archive:view', {
            'type': 'string',
            'allowed': ['mgrid', 'compact'],
            'view': 'mgrid',
            'default': 'mgrid',
            'label': 'Users archive view format',
            'category': 'archive'
        })

    superdesk.register_default_user_preference('workqueue:items',
                                               {'items': []})

    superdesk.register_default_session_preference('scratchpad:items', [])
    superdesk.register_default_session_preference('desk:items', [])
    superdesk.register_default_session_preference('stage:items', [])
    superdesk.register_default_session_preference('pinned:items', [])
Example #11
0
def init_app(app):
    superdesk.register_resource('workspaces',
                                WorkspaceResource,
                                WorkspaceService,
                                privilege=['POST', 'PATCH', 'DELETE'])

    superdesk.register_default_user_preference('workspace:active', {
        'type': 'string',
        'workspace': ''
    })

    superdesk.privilege(name='dashboard',
                        label='Dashboard',
                        description='Can access dashboard.')
Example #12
0
def init_app(app) -> None:
    superdesk.register_default_user_preference(
        "monitoring:view",
        {
            "type": "string",
            "allowed": ["list", "swimlane"],
            "view": "list",
            "default": "list",
        },
        label=lazy_gettext("Monitoring view"),
        category=lazy_gettext("monitoring"),
    )

    superdesk.register_default_session_preference("monitoring:view:session",
                                                  None)
Example #13
0
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'),
        'resource': {
            'type': 'string'
        }
    }
    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',
        })
Example #14
0
def init_app(app):
    endpoint_name = "vocabularies"
    service = VocabulariesService(endpoint_name,
                                  backend=superdesk.get_backend())
    VocabulariesResource(endpoint_name, app=app, service=service)

    superdesk.register_default_user_preference(
        "cvs:preferred_items",
        {
            "value": {},
            "category": _("cvs"),
            "label": _("Prefered CV items"),
        },
    )

    item_published.connect(add_missing_keywords)
Example #15
0
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'),
        'item_slugline': {
            'type': 'string'
        },
        'user': Resource.rel('users'),
        'user_name': {
            'type': 'string'
        },
        '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',
        })
Example #16
0
class PreferencesResource(Resource):
    datasource = {
        'source': 'users',
        'projection': {
            _session_preferences_key: 1,
            _user_preferences_key: 1,
            _privileges_key: 1,
            _action_key: 1,
            '_etag': 1
        }
    }
    schema = {
        _session_preferences_key: {'type': 'dict', 'required': True},
        _user_preferences_key: {'type': 'dict', 'required': True},
        _privileges_key: {'type': 'dict'},
        _action_key: {'type': 'list'}
    }
    resource_methods = []
    item_methods = ['GET', 'PATCH']

    superdesk.register_default_user_preference('feature:preview', {
        'type': 'bool',
        'enabled': False,
        'default': False,
        'label': 'Enable Feature Preview',
        'category': 'feature'
    })

    superdesk.register_default_user_preference('archive:view', {
        'type': 'string',
        'allowed': ['mgrid', 'compact'],
        'view': 'mgrid',
        'default': 'mgrid',
        'label': 'Users archive view format',
        'category': 'archive'
    })

    superdesk.register_default_user_preference('editor:theme', {
        'type': 'string',
        'theme': '',
    })

    superdesk.register_default_user_preference('workqueue:items', {
        'items': []
    })

    superdesk.register_default_user_preference('dashboard:ingest', {
        'providers': []
    })

    superdesk.register_default_user_preference('agg:view', {
        'active': {},
    })

    superdesk.register_default_user_preference('templates:recent', {})

    superdesk.register_default_user_preference('dateline:located', {
        'type': 'dict',
        'label': 'Located',
        'category': 'dateline'
    })

    superdesk.register_default_user_preference('categories:preferred', {
        'type': 'dict',
        'category': 'categories',
        'label': 'Preferred Categories',
        'selected': {},
    })

    superdesk.register_default_session_preference('scratchpad:items', [])
    superdesk.register_default_session_preference('desk:last_worked', '')
    superdesk.register_default_session_preference('desk:items', [])
    superdesk.register_default_session_preference('stage:items', [])
    superdesk.register_default_session_preference('pinned:items', [])
Example #17
0
class PreferencesResource(Resource):
    datasource = {
        'source': 'users',
        'projection': {
            _session_preferences_key: 1,
            _user_preferences_key: 1,
            _privileges_key: 1,
            _action_key: 1,
            '_etag': 1,

            'role': 1,
            'user_type': 1,
            'privileges': 1,
        }
    }
    schema = {
        _session_preferences_key: {'type': 'dict', 'required': True, 'allow_unknown': True},
        _user_preferences_key: {'type': 'dict', 'required': True, 'allow_unknown': True},
        _privileges_key: {'type': 'dict', 'allow_unknown': True},
        _action_key: {'type': 'list'},

        # we need these to get user/role info
        'role': {'type': 'string'},
        'user_type': {'type': 'string'},
        'privileges': {'type': 'dict'},
    }
    allow_unknown = True
    resource_methods = []
    item_methods = ['GET', 'PATCH']
    merge_nested_documents = True

    superdesk.register_default_user_preference('feature:preview', {
        'type': 'bool',
        'enabled': False,
        'default': False,
        'label': _('Enable Feature Preview'),
        'category': _('feature'),
        'privileges': ['feature_preview']
    })

    superdesk.register_default_user_preference('archive:view', {
        'type': 'string',
        'allowed': ['mgrid', 'compact'],
        'view': 'mgrid',
        'default': 'mgrid',
        'label': _('Users archive view format'),
        'category': _('archive')
    })

    superdesk.register_default_user_preference('singleline:view', {
        'type': 'bool',
        'enabled': None,
        'default': False,
        'label': _('Enable Single Line View'),
        'category': _('rows')
    })

    superdesk.register_default_user_preference('editor:theme', {
        'type': 'string',
        'theme': '',
    })

    superdesk.register_default_user_preference('workqueue:items', {
        'items': []
    })

    superdesk.register_default_user_preference('dashboard:ingest', {
        'providers': []
    })

    superdesk.register_default_user_preference('agg:view', {
        'active': {},
    })

    superdesk.register_default_user_preference('templates:recent', {})

    superdesk.register_default_user_preference('dateline:located', {
        'type': 'dict',
        'label': _('Located'),
        'category': _('article_defaults')
    })

    superdesk.register_default_user_preference('categories:preferred', {
        'type': 'dict',
        'category': _('categories'),
        'label': _('Preferred Categories'),
        'selected': {},
    })

    superdesk.register_default_user_preference('desks:preferred', {
        'type': 'dict',
        'category': _('desks'),
        'label': _('Preferred Desks'),
        'selected': {},
    })

    superdesk.register_default_user_preference('article:default:place', {
        'type': 'list',
        'label': _('Place'),
        'category': _('article_defaults'),
        'place': []
    })

    superdesk.register_default_user_preference('spellchecker:status', {
        'type': 'bool',
        'enabled': True,
        'default': True
    })

    superdesk.register_default_user_preference('contacts:view', {
        'type': 'string',
        'allowed': ['mgrid', 'compact'],
        'view': 'mgrid',
        'default': 'mgrid',
        'label': _('Users contacts view format'),
        'category': _('contacts')
    })

    superdesk.register_default_user_preference('destination:active', {})

    superdesk.register_default_session_preference('scratchpad:items', [])
    superdesk.register_default_session_preference('desk:last_worked', '')
    superdesk.register_default_session_preference('desk:items', [])
    superdesk.register_default_session_preference('stage:items', [])
    superdesk.register_default_session_preference('pinned:items', [])
Example #18
0
def init_app(app):
    """Initialize planning plugin.

    :param app: superdesk app
    """
    agendas_service = AgendasService('agenda', backend=superdesk.get_backend())
    AgendasResource('agenda', app=app, service=agendas_service)

    locations_search_service = LocationsService('locations', backend=superdesk.get_backend())
    LocationsResource('locations', app=app, service=locations_search_service)

    register_component(LockService(app))

    init_events_app(app)
    init_planning_app(app)
    init_assignments_app(app)
    init_search_app(app)
    init_validator_app(app)

    endpoint_name = 'published_planning'
    planning_published_service = PublishedPlanningService(endpoint_name, backend=superdesk.get_backend())
    PublishedPlanningResource(endpoint_name, app=app, service=planning_published_service)

    superdesk.privilege(
        name='planning',
        label='Planning',
        description='Create, update, and delete  events, planning items, and coverages'
    )

    superdesk.privilege(
        name='planning_agenda_management',
        label='Planning - Agenda Management',
        description='Ability to create and modify Agendas'
    )

    superdesk.privilege(
        name='planning_agenda_delete',
        label='Planning - Delete Agendas',
        description='Ability to delete an Agenda'
    )

    superdesk.privilege(
        name='planning_edit_expired',
        label='Planning - Edit Expired Items',
        description='Ability to edit expired Event and Planning items'
    )

    superdesk.privilege(
        name='planning_create_past',
        label='Planning - Create Event/Planning in the past',
        description='Ability to create an Event or Planning item in the past'
    )

    app.on_update_users += PlanningNotifications().user_update

    superdesk.register_default_user_preference('slack:notification', {
        'type': 'bool',
        'enabled': True,
        'default': False,
        'label': 'Allow Notifications To Slack',
        'category': 'notifications'
    })

    superdesk.register_default_user_preference('planning:calendar', {
        'type': 'dict',
        'label': 'Default Calendar',
        'category': 'planning',
        'calendar': {}
    })

    superdesk.register_default_user_preference('planning:agenda', {
        'type': 'dict',
        'label': 'Default Agenda',
        'category': 'planning',
        'agenda': {},
        'default': None
    })

    app.client_config['max_recurrent_events'] = get_max_recurrent_events(app)
    app.client_config['street_map_url'] = get_street_map_url(app)
    app.client_config['max_multi_day_event_duration'] = get_event_max_multi_day_duration(app)
Example #19
0
def init_app(app):
    """Initialize planning plugin.

    :param app: superdesk app
    """
    agendas_service = AgendasService('agenda', backend=superdesk.get_backend())
    AgendasResource('agenda', app=app, service=agendas_service)

    locations_search_service = LocationsService(
        'locations', backend=superdesk.get_backend())
    LocationsResource('locations', app=app, service=locations_search_service)

    register_component(LockService(app))

    init_events_app(app)
    init_planning_app(app)
    init_assignments_app(app)
    init_search_app(app)
    init_validator_app(app)

    endpoint_name = 'published_planning'
    planning_published_service = PublishedPlanningService(
        endpoint_name, backend=superdesk.get_backend())
    PublishedPlanningResource(endpoint_name,
                              app=app,
                              service=planning_published_service)

    superdesk.privilege(
        name='planning',
        label='Planning',
        description=
        'Create, update, and delete  events, planning items, and coverages')

    superdesk.privilege(name='planning_agenda_management',
                        label='Planning - Agenda Management',
                        description='Ability to create and modify Agendas')

    superdesk.privilege(name='planning_agenda_delete',
                        label='Planning - Delete Agendas',
                        description='Ability to delete an Agenda')

    superdesk.privilege(
        name='planning_edit_expired',
        label='Planning - Edit Expired Items',
        description='Ability to edit expired Event and Planning items')

    superdesk.privilege(
        name='planning_create_past',
        label='Planning - Create Event/Planning in the past',
        description='Ability to create an Event or Planning item in the past')

    app.on_update_users += PlanningNotifications().user_update

    superdesk.register_default_user_preference(
        'slack:notification', {
            'type': 'bool',
            'enabled': True,
            'default': False,
            'label': 'Allow Notifications To Slack',
            'category': 'notifications'
        })

    superdesk.register_default_user_preference(
        'planning:calendar', {
            'type': 'dict',
            'label': 'Default Calendar',
            'category': 'planning',
            'calendar': {}
        })

    superdesk.register_default_user_preference(
        'planning:agenda', {
            'type': 'dict',
            'label': 'Default Agenda',
            'category': 'planning',
            'agenda': {},
            'default': None
        })

    superdesk.register_default_user_preference(
        'planning:default_coverage_desks', {
            'type': 'dict',
            'label': 'Default desk for coverage types',
            'category': 'planning',
            'desks': {},
            'default': None
        })

    app.client_config['max_recurrent_events'] = get_max_recurrent_events(app)
    app.client_config['street_map_url'] = get_street_map_url(app)
    app.client_config[
        'max_multi_day_event_duration'] = get_event_max_multi_day_duration(app)

    # Set up Celery task options
    if not app.config.get('CELERY_TASK_ROUTES'):
        app.config['CELERY_TASK_ROUTES'] = CTR

    if not app.config.get('CELERY_TASK_ROUTES').get('planning.flag_expired'):
        app.config['CELERY_TASK_ROUTES']['planning.flag_expired'] = {
            'queue': celery_queue('expiry'),
            'routing_key': 'expiry.planning'
        }

    if not app.config.get('CELERY_TASK_ROUTES').get('planning.delete_spiked'):
        app.config['CELERY_TASK_ROUTES']['planning.delete_spiked'] = {
            'queue': celery_queue('expiry'),
            'routing_key': 'expiry.delete'
        }

    if not app.config.get('CELERY_BEAT_SCHEDULE'):
        app.config['CELERY_BEAT_SCHEDULE'] = CBS

    if app.config.get('PLANNING_EXPIRY_MINUTES', 0) != 0 and \
            not app.config.get('CELERY_BEAT_SCHEDULE').get('planning:expiry'):
        app.config['CELERY_BEAT_SCHEDULE']['planning:expiry'] = {
            'task': 'planning.flag_expired',
            'schedule': crontab(minute='0')  # Runs once every hour
        }

    if app.config.get('PLANNING_DELETE_SPIKED_MINUTES', 0) != 0 and \
            not app.config.get('CELERY_BEAT_SCHEDULE').get('planning:delete'):
        app.config['CELERY_BEAT_SCHEDULE']['planning:delete'] = {
            'task': 'planning.delete_spiked',
            'schedule': crontab(minute='0')  # Runs once every hour
        }

    # Create 'type' required for planning module if not already preset
    with app.app_context():
        vocabulary_service = superdesk.get_resource_service('vocabularies')
        types = vocabulary_service.find_one(req=None, _id='type')
        if types:
            items = types.get('items') or []
            added_types = []
            type_names = [t['qcode'] for t in items]

            planning_type_list = [{
                "is_active": True,
                "name": "Planning item",
                "qcode": "planning"
            }, {
                "is_active": True,
                "name": "Event",
                "qcode": "event"
            }, {
                "is_active": True,
                "name": "Featured Stories",
                "qcode": "planning_featured"
            }]

            for item in planning_type_list:
                if item['qcode'] not in type_names:
                    added_types.append(item)

            if len(added_types) > 0:
                vocabulary_service.patch(types.get(config.ID_FIELD),
                                         {"items": (items + added_types)})
Example #20
0
def init_app(app):
    """Initialize planning plugin.

    :param app: superdesk app
    """
    agendas_service = AgendasService('agenda', backend=superdesk.get_backend())
    AgendasResource('agenda', app=app, service=agendas_service)

    locations_search_service = LocationsService('locations', backend=superdesk.get_backend())
    LocationsResource('locations', app=app, service=locations_search_service)

    export_template_service = PlanningExportTemplatesService(PlanningExportTemplatesResource.endpoint_name,
                                                             backend=superdesk.get_backend())
    PlanningExportTemplatesResource(PlanningExportTemplatesResource.endpoint_name,
                                    app=app,
                                    service=export_template_service)

    register_component(LockService(app))

    init_events_app(app)
    init_planning_app(app)
    init_assignments_app(app)
    init_search_app(app)
    init_validator_app(app)
    init_planning_download_app(app)

    superdesk.register_resource(
        'planning_article_export',
        PlanningArticleExportResource,
        PlanningArticleExportService,
        privilege='planning',
        _app=app
    )

    endpoint_name = 'published_planning'
    planning_published_service = PublishedPlanningService(endpoint_name, backend=superdesk.get_backend())
    PublishedPlanningResource(endpoint_name, app=app, service=planning_published_service)

    superdesk.privilege(
        name='planning',
        label='Planning',
        description='Create, update, and delete  events, planning items, and coverages'
    )

    superdesk.privilege(
        name='planning_agenda_management',
        label='Planning - Agenda Management',
        description='Ability to create and modify Agendas'
    )

    superdesk.privilege(
        name='planning_agenda_delete',
        label='Planning - Delete Agendas',
        description='Ability to delete an Agenda'
    )

    superdesk.privilege(
        name='planning_edit_expired',
        label='Planning - Edit Expired Items',
        description='Ability to edit expired Event and Planning items'
    )

    superdesk.privilege(
        name='planning_create_past',
        label='Planning - Create Event/Planning in the past',
        description='Ability to create an Event or Planning item in the past'
    )

    superdesk.privilege(
        name='planning_locations_management',
        label='Planning - Manage locations',
        decsription='Ability to create, edit and delete locations'
    )

    superdesk.privilege(
        name='planning_assignments_view',
        label='Planning - Assignments view',
        decsription='Ability to access assignments view'
    )

    app.on_update_users += PlanningNotifications().user_update

    superdesk.register_default_user_preference('slack:notification', {
        'type': 'bool',
        'enabled': True,
        'default': False,
        'label': 'Allow Notifications To Slack',
        'category': 'notifications'
    })

    superdesk.register_default_user_preference('planning:calendar', {
        'type': 'dict',
        'label': 'Default Calendar',
        'category': 'planning',
        'calendar': {}
    })

    superdesk.register_default_user_preference('planning:agenda', {
        'type': 'dict',
        'label': 'Default Agenda',
        'category': 'planning',
        'agenda': {},
        'default': None
    })

    superdesk.register_default_user_preference('planning:events_planning_filter', {
        'type': 'dict',
        'label': 'Default Events Planning Filter',
        'category': 'planning',
        'filter': {},
        'default': None
    })

    superdesk.register_default_user_preference('planning:default_coverage_desks', {
        'type': 'dict',
        'label': 'Default desk for coverage types',
        'category': 'planning',
        'desks': {},
        'default': None
    })

    superdesk.register_default_user_preference('planning:add_coverage_advanced_mode', {
        'type': 'bool',
        'enabled': False,
        'default': False,
        'label': 'Open advanced mode when adding coverages',
        'category': 'planning',
    })

    app.client_config['max_recurrent_events'] = get_max_recurrent_events(app)
    app.client_config['street_map_url'] = get_street_map_url(app)
    app.client_config['max_multi_day_event_duration'] = get_event_max_multi_day_duration(app)
    app.client_config['planning_auto_assign_to_workflow'] = planning_auto_assign_to_workflow(app)
    app.client_config['long_event_duration_threshold'] = get_long_event_duration_threshold(app)
    app.client_config['event_templates_enabled'] = event_templates_enabled(app)
    app.client_config['planning_allow_scheduled_updates'] = get_planning_allow_scheduled_updates(app)
    app.client_config['planning_link_updates_to_coverage'] = planning_link_updates_to_coverage(app)
    app.client_config['planning_use_xmp_for_pic_assignments'] = get_planning_use_xmp_for_pic_assignments(app)
    app.client_config['planning_use_xmp_for_pic_slugline'] = get_planning_use_xmp_for_pic_slugline(app)

    # Set up Celery task options
    if not app.config.get('CELERY_TASK_ROUTES'):
        app.config['CELERY_TASK_ROUTES'] = CTR

    if not app.config.get('CELERY_TASK_ROUTES').get('planning.flag_expired'):
        app.config['CELERY_TASK_ROUTES']['planning.flag_expired'] = {
            'queue': celery_queue('expiry'),
            'routing_key': 'expiry.planning'
        }

    if not app.config.get('CELERY_TASK_ROUTES').get('planning.delete_spiked'):
        app.config['CELERY_TASK_ROUTES']['planning.delete_spiked'] = {
            'queue': celery_queue('expiry'),
            'routing_key': 'expiry.delete'
        }

    if not app.config.get('CELERY_TASK_ROUTES').get('planning.delete_assignments'):
        app.config['CELERY_TASK_ROUTES']['planning.delete_assignments'] = {
            'queue': celery_queue('expiry'),
            'routing_key': 'expiry.delete_assignments'
        }

    if not app.config.get('CELERY_BEAT_SCHEDULE'):
        app.config['CELERY_BEAT_SCHEDULE'] = CBS

    if app.config.get('PLANNING_EXPIRY_MINUTES', 0) != 0 and \
            not app.config.get('CELERY_BEAT_SCHEDULE').get('planning:expiry'):
        app.config['CELERY_BEAT_SCHEDULE']['planning:expiry'] = {
            'task': 'planning.flag_expired',
            'schedule': crontab(minute='0')  # Runs once every hour
        }

    if app.config.get('PLANNING_DELETE_SPIKED_MINUTES', 0) != 0 and \
            not app.config.get('CELERY_BEAT_SCHEDULE').get('planning:delete'):
        app.config['CELERY_BEAT_SCHEDULE']['planning:delete'] = {
            'task': 'planning.delete_spiked',
            'schedule': crontab(minute='0')  # Runs once every hour
        }

    if not app.config['CELERY_BEAT_SCHEDULE'].get('planning:delete_assignments'):
        app.config['CELERY_BEAT_SCHEDULE']['planning:delete_assignments'] = {
            'task': 'planning.delete_assignments',
            'schedule': timedelta(seconds=60)  # Runs once every minute
        }

    # Create 'type' required for planning module if not already preset
    with app.app_context():
        vocabulary_service = superdesk.get_resource_service('vocabularies')
        types = vocabulary_service.find_one(req=None, _id='type')
        if types:
            items = types.get('items') or []
            added_types = []
            type_names = [t['qcode'] for t in items]

            planning_type_list = [
                {"is_active": True, "name": "Planning item", "qcode": "planning"},
                {"is_active": True, "name": "Event", "qcode": "event"},
                {"is_active": True, "name": "Featured Stories", "qcode": "planning_featured"}
            ]

            for item in planning_type_list:
                if item['qcode'] not in type_names:
                    added_types.append(item)

            if len(added_types) > 0:
                vocabulary_service.patch(types.get(config.ID_FIELD), {
                    "items": (items + added_types)
                })

        custom_loaders = jinja2.ChoiceLoader(app.jinja_loader.loaders + [jinja2.FileSystemLoader(
            os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates'))])
        app.jinja_loader = custom_loaders

        register_jinja_filter('formatted_address', get_formatted_address)
Example #21
0
def init_app(app):
    superdesk.register_resource(
        "workspaces", WorkspaceResource, WorkspaceService, privilege=["POST", "PATCH", "DELETE"]
    )
    superdesk.register_default_user_preference("workspace:active", {"type": "string", "workspace": ""})
Example #22
0
def init_app(app):
    """Initialize assignments

    :param app: superdesk app
    """

    assignments_lock_service = AssignmentsLockService(
        AssignmentsLockResource.endpoint_name, backend=superdesk.get_backend())
    AssignmentsLockResource(AssignmentsLockResource.endpoint_name,
                            app=app,
                            service=assignments_lock_service)

    assignments_unlock_service = AssignmentsUnlockService(
        AssignmentsUnlockResource.endpoint_name,
        backend=superdesk.get_backend())
    AssignmentsUnlockResource(AssignmentsUnlockResource.endpoint_name,
                              app=app,
                              service=assignments_unlock_service)

    assignments_publish_service = AssignmentsService(
        'assignments', backend=superdesk.get_backend())
    AssignmentsResource('assignments',
                        app=app,
                        service=assignments_publish_service)

    assignments_content_service = AssignmentsContentService(
        'assignments_content', backend=superdesk.get_backend())
    AssignmentsContentResource('assignments_content',
                               app=app,
                               service=assignments_content_service)

    assignments_link_service = AssignmentsLinkService(
        'assignments_link', backend=superdesk.get_backend())
    AssignmentsLinkResource('assignments_link',
                            app=app,
                            service=assignments_link_service)

    assignments_unlink_service = AssignmentsUnlinkService(
        'assignments_unlink', backend=superdesk.get_backend())
    AssignmentsUnlinkResource('assignments_unlink',
                              app=app,
                              service=assignments_unlink_service)

    assignments_complete_service = AssignmentsCompleteService(
        AssignmentsCompleteResource.endpoint_name,
        backend=superdesk.get_backend())
    AssignmentsCompleteResource(AssignmentsCompleteResource.endpoint_name,
                                app=app,
                                service=assignments_complete_service)

    assignments_revert_service = AssignmentsRevertService(
        AssignmentsRevertResource.endpoint_name,
        backend=superdesk.get_backend())
    AssignmentsRevertResource(AssignmentsRevertResource.endpoint_name,
                              app=app,
                              service=assignments_revert_service)

    assignments_history_service = AssignmentsHistoryService(
        'assignments_history', backend=superdesk.get_backend())
    AssignmentsHistoryResource('assignments_history',
                               app=app,
                               service=assignments_history_service)
    app.on_updated_assignments += assignments_history_service.on_item_updated
    app.on_deleted_item_assignments += assignments_history_service.on_item_deleted

    delivery_service = BaseService('delivery', backend=superdesk.get_backend())
    DeliveryResource('delivery', app=app, service=delivery_service)

    # Updating data/lock on assignments based on content item updates from authoring
    app.on_updated_archive += assignments_publish_service.update_assignment_on_archive_update
    app.on_archive_item_updated += assignments_publish_service.update_assignment_on_archive_operation
    app.on_item_lock += assignments_publish_service.validate_assignment_lock
    app.on_item_locked += assignments_publish_service.sync_assignment_lock
    app.on_item_unlocked += assignments_publish_service.sync_assignment_unlock
    app.on_updated_events += assignments_publish_service.on_events_updated

    # Track updates for an assignment if it's news story was updated
    if app.config.get('PLANNING_LINK_UPDATES_TO_COVERAGES', True):
        app.on_inserted_archive_rewrite += assignments_publish_service.create_delivery_for_content_update

        # Remove Assignment and Coverage upon deleting an Archive Rewrite
        app.on_deleted_resource_archive_rewrite +=\
            assignments_publish_service.unlink_assignment_on_delete_archive_rewrite

    app.client_config['planning_check_for_assignment_on_publish'] = \
        app.config.get('PLANNING_CHECK_FOR_ASSIGNMENT_ON_PUBLISH', False)

    if len(app.config.get('PLANNING_FULFIL_ON_PUBLISH_FOR_DESKS', '')) == 0:
        app.client_config['planning_fulfil_on_publish_for_desks'] = []
    else:
        app.client_config['planning_fulfil_on_publish_for_desks'] = \
            app.config.get('PLANNING_FULFIL_ON_PUBLISH_FOR_DESKS', '').split(',')

    # Enhance the archive/published item resources with assigned desk/user information
    app.on_fetched_resource_archive += assignments_publish_service.on_fetched_resource_archive
    app.on_fetched_item_archive += assignments_publish_service.on_fetched_item_archive
    app.on_fetched_resource_published += assignments_publish_service.on_fetched_resource_archive
    app.on_fetched_item_published += assignments_publish_service.on_fetched_resource_archive
    app.on_updated_archive_spike += assignments_unlink_service.on_spike_item

    # Privileges
    superdesk.intrinsic_privilege(AssignmentsUnlockResource.endpoint_name,
                                  method=['POST'])

    # User Preferences
    superdesk.register_default_user_preference(
        'assignments:default_sort', {
            'type': 'dict',
            'label': 'Default sort preferences for Assignment lists',
            'category': 'assignments',
            'sort': {},
            'default': None
        })
Example #23
0
class PreferencesResource(Resource):
    datasource = {
        "source": "users",
        "projection": {
            _session_preferences_key: 1,
            _user_preferences_key: 1,
            _privileges_key: 1,
            _action_key: 1,
            "_etag": 1,
            "role": 1,
            "user_type": 1,
            "privileges": 1,
        },
    }
    schema = {
        _session_preferences_key: {
            "type": "dict",
            "required": True,
            "allow_unknown": True
        },
        _user_preferences_key: {
            "type": "dict",
            "required": True,
            "allow_unknown": True
        },
        _privileges_key: {
            "type": "dict",
            "allow_unknown": True
        },
        _action_key: {
            "type": "list"
        },
        # we need these to get user/role info
        "role": {
            "type": "string"
        },
        "user_type": {
            "type": "string"
        },
        "privileges": {
            "type": "dict"
        },
    }
    allow_unknown = True
    resource_methods = []
    item_methods = ["GET", "PATCH"]
    merge_nested_documents = True

    superdesk.register_default_user_preference(
        "feature:preview",
        {
            "type": "bool",
            "enabled": False,
            "default": False,
            "privileges": ["feature_preview"],
        },
        label=lazy_gettext("Enable Feature Preview"),
        category=lazy_gettext("feature"),
    )

    superdesk.register_default_user_preference(
        "archive:view",
        {
            "type": "string",
            "allowed": ["mgrid", "compact"],
            "view": "mgrid",
            "default": "mgrid",
        },
        label=lazy_gettext("Users archive view format"),
        category=lazy_gettext("archive"),
    )

    superdesk.register_default_user_preference(
        "singleline:view",
        {
            "type": "bool",
            "enabled": None,
            "default": False,
        },
        label=lazy_gettext("Enable Single Line View"),
        category=lazy_gettext("rows"),
    )

    superdesk.register_default_user_preference(
        "editor:theme",
        {
            "type": "string",
            "theme": "",
        },
    )

    superdesk.register_default_user_preference("workqueue:items",
                                               {"items": []})

    superdesk.register_default_user_preference("dashboard:ingest",
                                               {"providers": []})

    superdesk.register_default_user_preference(
        "agg:view",
        {
            "active": {},
        },
    )

    superdesk.register_default_user_preference("templates:recent", {})

    superdesk.register_default_user_preference(
        "dateline:located",
        {
            "type": "dict",
        },
        label=lazy_gettext("Located"),
        category=lazy_gettext("article_defaults"),
    )

    superdesk.register_default_user_preference(
        "categories:preferred",
        {
            "type": "dict",
            "selected": {},
        },
        label=lazy_gettext("Preferred Categories"),
        category=lazy_gettext("categories"),
    )

    superdesk.register_default_user_preference(
        "desks:preferred",
        {
            "type": "dict",
            "selected": {},
        },
        label=lazy_gettext("Preferred Desks"),
        category=lazy_gettext("desks"),
    )

    superdesk.register_default_user_preference(
        "article:default:place",
        {
            "type": "list",
            "place": []
        },
        label=lazy_gettext("Place"),
        category=lazy_gettext("article_defaults"),
    )

    superdesk.register_default_user_preference("spellchecker:status", {
        "type": "bool",
        "enabled": True,
        "default": True
    })

    superdesk.register_default_user_preference(
        "contacts:view",
        {
            "type": "string",
            "allowed": ["mgrid", "compact"],
            "view": "mgrid",
            "default": "mgrid",
        },
        label=lazy_gettext("Users contacts view format"),
        category=lazy_gettext("contacts"),
    )

    superdesk.register_default_user_preference("destination:active", {})

    superdesk.register_default_user_preference("extensions", {})

    superdesk.register_default_user_preference("search:filters_panel_open", {
        "type": "bool",
        "enabled": True,
        "default": True
    })

    superdesk.register_default_user_preference("masterdesk:desks", {})

    superdesk.register_default_user_preference("editor:char_limit_ui", {})
    superdesk.register_default_user_preference("editor:pinned_widget", {})

    superdesk.register_default_session_preference("scratchpad:items", [])
    superdesk.register_default_session_preference("desk:last_worked", "")
    superdesk.register_default_session_preference("desk:items", [])
    superdesk.register_default_session_preference("stage:items", [])
    superdesk.register_default_session_preference("pinned:items", [])