Пример #1
0
def source_set_approved(uuid):
    try:
        source = SourcesDeprecated.get_source_by_id(uuid=uuid)
        if not source:
            raise Exception('Source not found.')

        with source_manager_permission_factory({'uuid': uuid}).require():
            SourcesDeprecated.set_source_approved(source)

            notification = NotificationSchema()
            notification.classification = NotificationType.INFO
            notification.description = _(
                'El gestor ha aprobado para incluir en Sceiba la fuente: {0}.'.
                format(source.name))
            notification.emiter = _('Sistema')

            msg, users = SourcesDeprecated.get_user_ids_source_editor(
                source.uuid)
            if users:
                for user_id in users:
                    notification.receiver_id = user_id
                    Notifications.new_notification(notification)

            return iroko_json_response(
                IrokoResponseStatus.SUCCESS,
                'Source {0} approved.'.format(source.name), 'source',
                source_schema.dump(source))

    except PermissionDenied as err:
        msg = 'Permission denied for changing source'
        return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
    except Exception as e:
        return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None,
                                   None)
Пример #2
0
def source_new():
    try:
        if not request.is_json:
            raise Exception("No JSON data provided")

        input_data = request.json

        msg, source = SourcesDeprecated.insert_new_source(input_data)
        if not source:
            raise Exception(msg)

        notification = NotificationSchema()
        notification.classification = NotificationType.INFO
        notification.description = _(
            'Nueva fuente ingresada, requiere revisión de un gestor {0}'.
            format(source.name))
        notification.emiter = _('Sistema')

        msg, users = SourcesDeprecated.get_user_ids_source_managers(
            source.uuid)
        if users:
            for user_id in users:
                notification.receiver_id = user_id
                Notifications.new_notification(notification)

        return iroko_json_response(
            IrokoResponseStatus.SUCCESS, \
            'ok', 'source', \
            {'data': source_schema.dump(source), 'count': 1}
            )

    except Exception as e:
        return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None,
                                   None)
Пример #3
0
def source_edit_version(id):
    try:
        if not request.is_json:
            raise Exception("No JSON data provided")

        input_data = request.json

        version = SourcesDeprecated.get_source_version_by_id(id)
        if not version:
            raise Exception('Not version found')

        source = SourcesDeprecated.get_source_by_id(uuid=version.source.uuid)

        if not source:
            raise Exception('Not source found')

        with source_editor_permission_factory({'uuid': source.uuid}).require():
            msg, source, source_version = SourcesDeprecated.edit_source_version(
                input_data, version)
            if not source or not source_version:
                raise Exception('Not source for changing found')

            notification = NotificationSchema()
            notification.classification = NotificationType.INFO
            notification.description = _(
                'The edit has change data in version of source: {0}.'.format(
                    source.name))
            notification.emiter = _('System')

            msg, users = SourcesDeprecated.get_user_ids_source_managers(
                source.uuid)
            if users:
                for user_id in users:
                    notification.receiver_id = user_id
                    Notifications.new_notification(notification)

            return iroko_json_response(
                IrokoResponseStatus.SUCCESS, \
                'ok', 'source', \
                {
                    'data': source_schema_no_versions.dump(source),
                    'version': source_version_schema.dump(source_version),
                    'count': 1
                    }
                )

    except PermissionDenied as err:
        msg = 'Permission denied for changing source'
        return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
    except Exception as e:
        return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None,
                                   None)
Пример #4
0
def notification_get_receiver(id):
    try:
        user = None

        msg, notif = Notifications.get_notification_receiver(id)
        if not notif:
            raise Exception('Notification not found')

        return iroko_json_response(
            IrokoResponseStatus.SUCCESS, \
            msg, 'notification', \
            notification_schema_many.dump(notif)
            )
    except Exception as e:
        msg = str(e)
        return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
Пример #5
0
def notification_viewed(id):
    # FIXME: get the user is trying to perform this action!!!!
    try:
        with notification_viewed_permission_factory({'id': id}).require():
            msg, notif = Notifications.viewed_notification(id)
            if not notif:
                raise Exception('Notifications not found')

            return iroko_json_response(
                IrokoResponseStatus.SUCCESS, \
                msg, 'notification', \
                notification_schema.dump(notif)
                )

    except Exception as e:
        msg = str(e)
        return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
Пример #6
0
def notification_edit(id):
    # FIXME: get the user is trying to perform this action!!!!
    try:
        user = None
        if not request.is_json:
            raise Exception('No JSON data provided')

        input_data = request.json

        msg, notif = Notifications.edit_notification(id, input_data)
        if not notif:
            raise Exception(msg)

        return iroko_json_response(
            IrokoResponseStatus.SUCCESS, \
            msg, 'notification', \
            notification_schema.dump(notif)
            )
    except Exception as e:
        msg = str(e)
        return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
Пример #7
0
def source_new_version(uuid):
    # inserta un nuevo sourceVersion de un source que ya existe
    # hay que comprobar que el usuario que inserta, es quien creo el source (el que tiene el
    # sourceversion mas antiguo) o un usuario con el role para crear cualquier tipo de versiones.
    # input_data = request.json
    # source = Sources.get_source_by_id(uuid=uuid)
    # Sources.insert_new_source_version(input_data, source, False)

    try:
        if not request.is_json:
            raise Exception("No JSON data provided")

        input_data = request.json

        comment = 'no comment'
        if 'comment' in input_data:
            comment = input_data['comment']
        source = SourcesDeprecated.get_source_by_id(uuid=uuid)

        if not source:
            raise Exception('Not source found')

        terms = ''
        for term in source.term_sources:
            terms = terms + str(term.term.uuid) + ','
        if terms:
            terms = terms[0:-1]

        try:
            with source_editor_permission_factory({'uuid': uuid}).require():
                # si no esta aprobada significa que siempre es la current.
                # si esta aprobada el proceso es otro
                # print(input_data)
                is_current = source.source_status is not SourceStatus.APPROVED
                msg, source, source_version = SourcesDeprecated.insert_new_source_version(
                    input_data, source.uuid, is_current, comment=comment)
                if not source or not source_version:
                    raise Exception('Not source for changing found')

                notification = NotificationSchema()
                notification.classification = NotificationType.INFO
                notification.description = _(
                    'Editor has change this source: {0}.'.format(source.name))
                notification.emiter = _('Sistema')

                msg, users = SourcesDeprecated.get_user_ids_source_managers(
                    source.uuid)
                if users:
                    for user_id in users:
                        notification.receiver_id = user_id
                        Notifications.new_notification(notification)

                return iroko_json_response(
                    IrokoResponseStatus.SUCCESS, \
                    'ok', 'source', \
                    source_schema.dump(source)
                    )
        except PermissionDenied as e:
            with source_term_manager_permission_factory({
                    'terms': terms,
                    'uuid': uuid
            }).require():
                msg, source, source_version = SourcesDeprecated.insert_new_source_version(
                    input_data, uuid, True, comment=comment)
                if not source or not source_version:
                    raise Exception('Not source for changing found')

                notification = NotificationSchema()
                notification.classification = NotificationType.INFO
                notification.description = _(
                    'Gestor has reviewed this source: {0}.'.format(
                        source.name))
                notification.emiter = _('Sistema')

                msg, users = SourcesDeprecated.get_user_ids_source_editor(
                    source.uuid)
                if users:
                    for user_id in users:
                        notification.receiver_id = user_id
                        Notifications.new_notification(notification)

                return iroko_json_response(
                    IrokoResponseStatus.SUCCESS, \
                    'ok', 'source', \
                    source_schema.dump(source)
                    )

    except PermissionDenied as err:
        msg = 'Permission denied for changing source'
        return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
    except Exception as e:
        return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None,
                                   None)