Ejemplo n.º 1
0
def addTag_impl(user, tag, category, language):
    ret, sanitized_tag = verifyAndSanitizeTagOrAlias(tag)
    log(obj={'tag': sanitized_tag, 'cat': category, 'lang': language})
    filterOperation('addTag', user)
    if not ret:
        raise UserError('INVALID_TAG')
    if len(sanitized_tag) > TagsConfig.MAX_TAG_LENGTH:
        raise UserError('TAG_TOO_LONG')
    with MongoTransaction(client) as s:
        tagdb.add_tag(sanitized_tag,
                      category,
                      language,
                      makeUserMeta(user),
                      session=s())
        s.mark_succeed()
Ejemplo n.º 2
0
def renameOrAddAlias(user, old_name_or_tag_name, new_name):
    ret, sanitized_alias = verifyAndSanitizeTagOrAlias(new_name)
    log(obj={
        'old_name_or_tag_name': old_name_or_tag_name,
        'new_name': sanitized_alias
    })
    filterOperation('renameOrAddAlias', user)
    if not ret:
        raise UserError('INVALID_TAG')
    if len(sanitized_alias) > TagsConfig.MAX_TAG_LENGTH:
        raise UserError('TAG_TOO_LONG')
    with MongoTransaction(client) as s:
        tagdb.add_or_rename_alias(old_name_or_tag_name,
                                  sanitized_alias,
                                  makeUserMeta(user),
                                  session=s())
        s.mark_succeed()
Ejemplo n.º 3
0
def renameTagOrAddTagLanguage(user, tag, new_tag, language):
    ret, sanitized_tag = verifyAndSanitizeTagOrAlias(new_tag)
    log(obj={'old_tag_or_id': tag, 'new_tag': sanitized_tag, 'lang': language})
    filterOperation('renameTagOrAddTagLanguage', user)
    if not ret:
        raise UserError('INVALID_TAG')
    if len(sanitized_tag) > TagsConfig.MAX_TAG_LENGTH:
        raise UserError('TAG_TOO_LONG')
    with MongoTransaction(client) as s:
        #tag_obj = tagdb.db.tag_alias.find_one({'tag': tag}, session = s())
        #if tag_obj and not _is_authorised(tag_obj, user, 'rename') :
        #    raise UserError('UNAUTHORISED_OPERATION')
        tagdb.add_or_rename_tag(tag,
                                sanitized_tag,
                                language,
                                makeUserMeta(user),
                                session=s())
        s.mark_succeed()