示例#1
0
def get_collection_with_private_check(coll_id, user):
    coll = WorkshopCollection.from_id(coll_id)
    if coll.publish_state == PublicationState.PRIVATE \
            and (user is None
                 or not (coll.is_owner(int(user.id)) or coll.is_editor(int(user.id)))):
        raise Error(403, "This collection is private.")
    return coll
示例#2
0
def remove_editor(user, coll_id, editor_id: int):
    coll = WorkshopCollection.from_id(coll_id)
    if not (coll.is_owner(int(user.id)) or editor_id == int(user.id)):
        return error(403, "you do not have permission to remove editors from this collection")

    coll.remove_editor(editor_id)
    return success(get_editors(coll), 200)
示例#3
0
def delete_collection(user, coll_id):
    coll = WorkshopCollection.from_id(coll_id)
    if not coll.is_owner(int(user.id)):
        return error(403, "you do not have permission to delete this collection")

    coll.delete()
    return success(f"Deleted {coll.name}", 200)
示例#4
0
def moderator_set_collection_state(_, body, coll_id):
    coll = WorkshopCollection.from_id(coll_id)

    try:
        coll.set_state(body['state'], run_checks=False)
    except ValueError as e:  # invalid publication state
        return error(400, str(e))

    return success(coll.to_dict(js=True), 200)
示例#5
0
def set_state(user, body, coll_id):
    coll = WorkshopCollection.from_id(coll_id)
    if not coll.is_owner(int(user.id)):
        return error(403, "you do not have permission to change the state of this collection")

    try:
        coll.set_state(body['state'])
    except ValueError as e:  # invalid publication state
        return error(400, str(e))

    return success(coll.to_dict(js=True), 200)
示例#6
0
def add_editor(user, coll_id, editor_id: int):
    coll = WorkshopCollection.from_id(coll_id)
    if not coll.is_owner(int(user.id)):
        return error(403, "You do not have permission to add editors to this collection.")
    if coll.is_owner(editor_id):
        return error(409, "You are already the owner of this collection.")

    try:
        coll.add_editor(editor_id)
    except NotAllowed as e:
        return error(409, str(e))
    return success(get_editors(coll), 200)
示例#7
0
def personal_subscribe(user, body, coll_id):
    coll = WorkshopCollection.from_id(coll_id)

    if body is None:
        alias_bindings = snippet_bindings = None
    else:
        alias_bindings = body['alias_bindings']
        _bindings_check(coll, alias_bindings)
        snippet_bindings = body['snippet_bindings']
        _bindings_check(coll, snippet_bindings)

    bindings = coll.subscribe(int(user.id), alias_bindings, snippet_bindings)
    return success(bindings, 200)
示例#8
0
def guild_subscribe(user, body, coll_id, guild_id):
    guild_permissions_check(user, guild_id)

    coll = WorkshopCollection.from_id(coll_id)
    if body is None:
        alias_bindings = snippet_bindings = None
    else:
        alias_bindings = body['alias_bindings']
        _bindings_check(coll, alias_bindings)
        snippet_bindings = body['snippet_bindings']
        _bindings_check(coll, snippet_bindings)

    bindings = coll.set_server_active(guild_id, alias_bindings, snippet_bindings, invoker_id=int(user.id))
    return success(bindings, 200)
示例#9
0
def get_owned_collections(user):
    """Returns a list of collection IDs the user owns in an unsorted order."""
    owned = WorkshopCollection.user_owned_ids(int(user.id))
    return success([str(o) for o in owned], 200)
示例#10
0
def get_guild_subscriptions(guild_id):
    """Returns a list of str representing the IDs of subscribed collections."""
    return success([str(oid) for oid in WorkshopCollection.guild_active_ids(guild_id)], 200)
示例#11
0
def get_guild_subscription(coll_id, guild_id):
    coll = WorkshopCollection.from_id(coll_id)
    sub = coll.guild_sub(guild_id)
    if sub is None:
        return error(404, "You are not subscribed to this collection")
    return success(sub, 200)
示例#12
0
def guild_unsubscribe(user, coll_id, guild_id):
    guild_permissions_check(user, guild_id)

    coll = WorkshopCollection.from_id(coll_id)
    coll.unset_server_active(guild_id, int(user.id))
    return success(f"Unsubscribed from {coll.name}", 200)
示例#13
0
def personal_unsubscribe(user, coll_id):
    coll = WorkshopCollection.from_id(coll_id)
    coll.unsubscribe(int(user.id))
    return success(f"Unsubscribed from {coll.name}", 200)
示例#14
0
def get_collection_with_editor_check(coll_id, user):
    coll = WorkshopCollection.from_id(coll_id)
    if not (coll.is_owner(int(user.id)) or coll.is_editor(int(user.id))):
        raise Error(403, "you do not have permission to edit this collection")
    return coll
示例#15
0
def route_get_editors(_, coll_id):
    coll = WorkshopCollection.from_id(coll_id)
    return success(get_editors(coll), 200)
示例#16
0
def get_editable_collections(user):
    """Returns a list of collection IDs the user has edit permission on in an unsorted order."""
    editable = WorkshopCollection.my_editable_ids(int(user.id))
    return success(list([str(o) for o in editable]), 200)
示例#17
0
def create_collection(user, body):
    new_collection = WorkshopCollection.create_new(int(user.id), body['name'], body['description'], body['image'])
    return success(new_collection.to_dict(js=True), 201)
示例#18
0
def get_personal_subscription(user, coll_id):
    coll = WorkshopCollection.from_id(coll_id)
    sub = coll.my_sub(int(user.id))
    if sub is None:
        return error(404, "You are not subscribed to this collection")
    return success(sub, 200)
示例#19
0
def moderator_delete_collection(_, coll_id):
    coll = WorkshopCollection.from_id(coll_id)
    coll.delete(run_checks=False)
    return success(f"Deleted {coll.name}", 200)
示例#20
0
def get_personal_subscriptions(user):
    """Returns a list of str representing the IDs of subscribed collections."""
    return success([str(oid) for oid in WorkshopCollection.my_sub_ids(int(user.id))], 200)