Beispiel #1
0
def collection_settings(request, cid):
    '''Collection settings is the entrypoint for editing the builder, branches,
       and administrative actions like disabling and deleting collections. if 
       active tab is defined, it means we are coming from a submit to change one
       of these tabs, and it will return the user to the page with the correct
       tab active.
    
       Parameters
       ==========
       cid: the id of the collection
    '''
    from shub.apps.users.permissions import has_create_permission
    from shub.apps.users.models import Team

    collection = get_collection(cid)
    edit_permission = collection.has_edit_permission(request)
    has_create_permission = has_create_permission(request)

    # Give view a list of owner and member ids
    owners_ids = [x.id for x in collection.owners.all()]
    contrib_ids = [x.id for x in collection.contributors.all()]

    # Superusers, staff, and owners can edit collection settings
    if not edit_permission:
        messages.info(request, "You are not permitted to perform this action.")
        return redirect('collection_details', cid=collection.id)
               
    context = {'collection': collection,
               'teams': Team.objects.all(),
               'owners_ids': owners_ids,
               'contrib_ids': contrib_ids,
               'has_create_permission': has_create_permission,
               'edit_permission':edit_permission}

    return render(request, 'collections/collection_settings.html', context)
Beispiel #2
0
def view_teams(request):
    """view all teams (log in not required)
    :parma tid: the team id to edit or create. If none, indicates a new team
    """
    teams = Team.objects.all()

    # Does the user have permission to create a team?
    create_permission = has_create_permission(request)

    context = {"teams": teams, "has_create_permission": create_permission}

    return render(request, "teams/all_teams.html", context)