def undo_review(revision):
    _ensure_latest_revision_with_final_state(revision)
    latest_revision = revision.editable.revisions[-1]
    if revision != latest_revision:
        if revision.editable.revisions[-2:] != [revision, latest_revision]:
            raise InvalidEditableState
        _ensure_state(revision,
                      final=FinalRevisionState.needs_submitter_confirmation)
        _ensure_state(
            latest_revision,
            initial=InitialRevisionState.needs_submitter_confirmation,
            final=FinalRevisionState.none)
        db.session.delete(latest_revision)
    if (revision.initial_state
            == InitialRevisionState.needs_submitter_confirmation
            and revision.final_state == FinalRevisionState.accepted
            and revision.editor is not None):
        revision = revision.editable.revisions[-2]
        revision.editable.published_revision = None
        db.session.delete(latest_revision)
    elif revision.final_state == FinalRevisionState.accepted:
        revision.editable.published_revision = None
    db.session.flush()
    revision.final_state = FinalRevisionState.none
    revision.comment = ''
    db.session.flush()
    logger.info('Revision %r review undone', revision)
def update_revision_comment(comment, updates):
    ensure_latest_revision(comment.revision)
    comment.populate_from_dict(updates)
    comment.modified_dt = now_utc()
    db.session.flush()
    logger.info('Comment on revision %r updated: %r', comment.revision,
                comment)
示例#3
0
def create_revision_comment(revision, user, text, internal=False):
    _ensure_latest_revision(revision)
    comment = EditingRevisionComment(user=user, text=text, internal=internal)
    revision.comments.append(comment)
    db.session.flush()
    logger.info('Comment on revision %r created by %r: %r', revision, user,
                comment)
def create_new_file_type(event, editable_type, **data):
    file_type = EditingFileType(event=event, type=editable_type)
    file_type.populate_from_dict(data, keys=FILE_TYPE_ATTRS)
    db.session.flush()
    logger.info('File type %r for %s created by %r', file_type,
                editable_type.name, session.user)
    return file_type
示例#5
0
def update_file_type(file_type, **data):
    file_type.populate_from_dict(data,
                                 keys=('name', 'extensions',
                                       'allow_multiple_files', 'required',
                                       'publishable'))
    db.session.flush()
    logger.info('File type %r updated by %r', file_type, session.user)
def create_new_review_condition(event, editable_type, file_types):
    review_condition = EditingReviewCondition(event=event,
                                              type=editable_type,
                                              file_types=file_types)
    db.session.flush()
    logger.info('Review condition %r created by %r', review_condition,
                session.user)
    return review_condition
def create_new_tag(event, code, title, color, system=False):
    tag = EditingTag(code=code,
                     title=title,
                     color=color,
                     system=system,
                     event=event)
    db.session.flush()
    logger.info('Tag %r created by %r', tag, session.user)
    return tag
def update_tag(tag, code=None, title=None, color=None):
    if code:
        tag.code = code
    if title:
        tag.title = title
    if color:
        tag.color = color
    db.session.flush()
    logger.info('Tag %r updated by %r', tag, session.user)
示例#9
0
def create_new_editable(contrib, type_, submitter, files):
    editable = Editable(contribution=contrib, type=type_)
    revision = EditingRevision(submitter=submitter,
                               initial_state=InitialRevisionState.ready_for_review,
                               files=_make_editable_files(editable, files))
    editable.revisions.append(revision)
    db.session.flush()
    logger.info('Editable [%s] created by %s for %s', type_.name, submitter, contrib)
    return editable
示例#10
0
def create_submitter_revision(prev_revision, user, files):
    _ensure_latest_revision(prev_revision)
    _ensure_state(prev_revision, final=FinalRevisionState.needs_submitter_changes)
    new_revision = EditingRevision(submitter=user,
                                   initial_state=InitialRevisionState.ready_for_review,
                                   files=_make_editable_files(prev_revision.editable, files),
                                   tags=prev_revision.tags)
    prev_revision.editable.revisions.append(new_revision)
    db.session.flush()
    logger.info('Revision %r created by submitter %s', new_revision, user)
示例#11
0
def review_editable_revision(revision,
                             editor,
                             action,
                             comment,
                             tags,
                             files=None):
    _ensure_latest_revision(revision)
    _ensure_state(revision,
                  initial=InitialRevisionState.ready_for_review,
                  final=FinalRevisionState.none)
    revision.editor = editor
    revision.comment = comment
    revision.tags = tags
    revision.final_state = {
        EditingReviewAction.accept:
        FinalRevisionState.accepted,
        EditingReviewAction.reject:
        FinalRevisionState.rejected,
        EditingReviewAction.update:
        FinalRevisionState.needs_submitter_confirmation,
        EditingReviewAction.update_accept:
        FinalRevisionState.needs_submitter_confirmation,
        EditingReviewAction.request_update:
        FinalRevisionState.needs_submitter_changes,
    }[action]

    db.session.flush()
    if action == EditingReviewAction.accept:
        _ensure_publishable_files(revision)
        publish_editable_revision(revision)
    elif action in (EditingReviewAction.update,
                    EditingReviewAction.update_accept):
        final_state = FinalRevisionState.none
        editable_editor = None
        if action == EditingReviewAction.update_accept:
            final_state = FinalRevisionState.accepted
            editable_editor = editor
        new_revision = EditingRevision(
            submitter=editor,
            editor=editable_editor,
            initial_state=InitialRevisionState.needs_submitter_confirmation,
            final_state=final_state,
            files=_make_editable_files(revision.editable, files),
            tags=revision.tags)
        _ensure_publishable_files(new_revision)
        revision.editable.revisions.append(new_revision)
        if action == EditingReviewAction.update_accept:
            db.session.flush()
            publish_editable_revision(new_revision)
    db.session.flush()
    notify_editor_judgment(revision, session.user)
    logger.info('Revision %r reviewed by %s [%s]', revision, editor,
                action.name)
示例#12
0
def replace_revision(revision, user, comment, files):
    _ensure_latest_revision(revision)
    _ensure_state(revision,
                  initial=(InitialRevisionState.new, InitialRevisionState.ready_for_review),
                  final=FinalRevisionState.none)
    revision.comment = comment
    revision.final_state = FinalRevisionState.replaced
    new_revision = EditingRevision(submitter=user,
                                   initial_state=revision.initial_state,
                                   files=_make_editable_files(revision.editable, files))
    revision.editable.revisions.append(new_revision)
    db.session.flush()
    logger.info('Revision %r replaced by %s', revision, user)
示例#13
0
def unassign_editor(editable):
    editor = editable.editor
    editable.editor = None
    logger.info('Editor %r has been unassigned from %r', editor, editable)
    log_data = {
        'Editor': editor.full_name,
        'Editable type': orig_string(editable.type.title),
        'Editable': editable.contribution.title
    }
    log_msg = '"{}" ({}) unassigned from {}'.format(editable.contribution.title,
                                                    orig_string(editable.type.title),
                                                    editor.full_name)
    editable.log(EventLogRealm.management, EventLogKind.negative, 'Editing', log_msg, session.user, data=log_data)
    db.session.flush()
示例#14
0
def confirm_editable_changes(revision, submitter, action, comment):
    _ensure_latest_revision(revision)
    _ensure_state(revision, initial=InitialRevisionState.needs_submitter_confirmation, final=FinalRevisionState.none)
    revision.final_state = {
        EditingConfirmationAction.accept: FinalRevisionState.accepted,
        EditingConfirmationAction.reject: FinalRevisionState.needs_submitter_changes,
    }[action]
    if comment:
        create_revision_comment(revision, submitter, comment)
    db.session.flush()
    if action == EditingConfirmationAction.accept:
        publish_editable_revision(revision)
    db.session.flush()
    logger.info('Revision %r confirmed by %s [%s]', revision, submitter, action.name)
示例#15
0
def assign_editor(editable, editor):
    old_editor = editable.editor
    editable.editor = editor
    logger.info('Editable %r assigned to editor %r', editable, editor)
    log_data = {
        'Editor': editor.full_name,
        'Editable type': orig_string(editable.type.title),
        'Editable': editable.contribution.title
    }
    if old_editor:
        log_data['Previous editor'] = old_editor.full_name
    log_msg = '"{}" ({}) assigned to {}'.format(editable.contribution.title,
                                                orig_string(editable.type.title),
                                                editor.full_name)
    editable.log(EventLogRealm.management, EventLogKind.positive, 'Editing', log_msg, session.user, data=log_data)
    db.session.flush()
示例#16
0
def replace_revision(revision, user, comment, files, tags, initial_state=None):
    ensure_latest_revision(revision)
    _ensure_state(revision,
                  initial=(InitialRevisionState.new,
                           InitialRevisionState.ready_for_review),
                  final=FinalRevisionState.none)
    revision.comment = comment
    revision.reviewed_dt = now_utc()
    revision.tags = tags
    revision.final_state = FinalRevisionState.replaced
    revision.editor = user
    new_revision = EditingRevision(submitter=revision.submitter,
                                   initial_state=(initial_state
                                                  or revision.initial_state),
                                   files=_make_editable_files(
                                       revision.editable, files))
    revision.editable.revisions.append(new_revision)
    db.session.flush()
    logger.info('Revision %r replaced by %s', revision, user)
示例#17
0
def create_submitter_revision(prev_revision, user, files):
    ensure_latest_revision(prev_revision)
    try:
        _ensure_state(prev_revision,
                      initial=InitialRevisionState.ready_for_review,
                      final=FinalRevisionState.none)
        if prev_revision.editable.editor:
            raise InvalidEditableState
    except InvalidEditableState:
        _ensure_state(prev_revision,
                      final=FinalRevisionState.needs_submitter_changes)
    new_revision = EditingRevision(
        submitter=user,
        initial_state=InitialRevisionState.ready_for_review,
        files=_make_editable_files(prev_revision.editable, files),
        tags=prev_revision.tags)
    prev_revision.editable.revisions.append(new_revision)
    db.session.flush()
    notify_submitter_upload(new_revision)
    logger.info('Revision %r created by submitter %s', new_revision, user)
    return new_revision
示例#18
0
def confirm_editable_changes(revision, submitter, action, comment):
    ensure_latest_revision(revision)
    _ensure_state(revision,
                  initial=InitialRevisionState.needs_submitter_confirmation,
                  final=FinalRevisionState.none)
    revision.final_state = {
        EditingConfirmationAction.accept:
        FinalRevisionState.accepted,
        EditingConfirmationAction.reject:
        FinalRevisionState.needs_submitter_changes,
    }[action]
    if comment:
        revision.comment = comment
    revision.reviewed_dt = now_utc()
    db.session.flush()
    if action == EditingConfirmationAction.accept:
        _ensure_publishable_files(revision)
    db.session.flush()
    notify_submitter_confirmation(revision, submitter, action)
    logger.info('Revision %r confirmed by %s [%s]', revision, submitter,
                action.name)
def delete_file_type(file_type):
    logger.info('File type %r deleted by %r', file_type, session.user)
    db.session.delete(file_type)
def update_file_type(file_type, **data):
    file_type.populate_from_dict(data, keys=FILE_TYPE_ATTRS)
    db.session.flush()
    logger.info('File type %r updated by %r', file_type, session.user)
def delete_tag(tag):
    logger.info('Tag %r deleted by %r', tag, session.user)
    db.session.delete(tag)
def update_review_condition(condition, file_types):
    condition.file_types = file_types
    db.session.flush()
    logger.info('Review condition %r updated by %r', condition, session.user)
def delete_revision_comment(comment):
    ensure_latest_revision(comment.revision)
    comment.is_deleted = True
    db.session.flush()
    logger.info('Comment on revision %r deleted: %r', comment.revision,
                comment)
def delete_review_condition(condition):
    logger.info('Review condition %r deleted by %r', condition, session.user)
    db.session.delete(condition)
def publish_editable_revision(revision):
    ensure_latest_revision(revision)
    revision.editable.published_revision = revision
    db.session.flush()
    logger.info('Revision %r marked as published', revision)