Beispiel #1
0
def new_project():
    """ Form to create a new project.
    """
    form = pagure.forms.ProjectForm()
    if form.validate_on_submit():
        name = form.name.data
        description = form.description.data

        try:
            message = pagure.lib.new_project(
                SESSION,
                name=name,
                description=description,
                user=flask.g.fas_user.username,
                blacklist=APP.config['BLACKLISTED_PROJECTS'],
                gitfolder=APP.config['GIT_FOLDER'],
                docfolder=APP.config['DOCS_FOLDER'],
                ticketfolder=APP.config['TICKETS_FOLDER'],
                requestfolder=APP.config['REQUESTS_FOLDER'],
            )
            SESSION.commit()
            generate_gitolite_acls()
            flask.flash(message)
            return flask.redirect(flask.url_for('view_repo', repo=name))
        except pagure.exceptions.PagureException, err:
            flask.flash(str(err), 'error')
        except SQLAlchemyError, err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'error')
Beispiel #2
0
def new_project():
    """ Form to create a new project.
    """
    form = pagure.forms.ProjectForm()
    if form.validate_on_submit():
        name = form.name.data
        description = form.description.data
        url = form.url.data
        avatar_email = form.avatar_email.data

        try:
            message = pagure.lib.new_project(
                SESSION,
                name=name,
                description=description,
                url=url,
                avatar_email=avatar_email,
                user=flask.g.fas_user.username,
                blacklist=APP.config['BLACKLISTED_PROJECTS'],
                gitfolder=APP.config['GIT_FOLDER'],
                docfolder=APP.config['DOCS_FOLDER'],
                ticketfolder=APP.config['TICKETS_FOLDER'],
                requestfolder=APP.config['REQUESTS_FOLDER'],
            )
            SESSION.commit()
            generate_gitolite_acls()
            flask.flash(message)
            return flask.redirect(flask.url_for('view_repo', repo=name))
        except pagure.exceptions.PagureException, err:
            flask.flash(str(err), 'error')
        except SQLAlchemyError, err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'error')
Beispiel #3
0
def group_user_delete(user, group):
    """ Delete an user from a certain group
    """
    form = pagure.forms.ConfirmationForm()
    if form.validate_on_submit():

        try:
            pagure.lib.delete_user_of_group(pagure.SESSION,
                                            username=user,
                                            groupname=group,
                                            user=flask.g.fas_user.username,
                                            is_admin=pagure.is_admin())
            pagure.SESSION.commit()
            pagure.generate_gitolite_acls()
            flask.flash('User `%s` removed from the group `%s`' %
                        (user, group))
        except pagure.exceptions.PagureException, err:
            pagure.SESSION.rollback()
            flask.flash(err.message, 'error')
            return flask.redirect(flask.url_for('.view_group', group=group))
        except SQLAlchemyError as err:  # pragma: no cover
            pagure.SESSION.rollback()
            flask.flash(
                'Could not remove user `%s` from the group `%s`.' %
                (user.user, group), 'error')
            pagure.APP.logger.debug(
                'Could not remove user `%s` from the group `%s`.' %
                (user.user, group))
            pagure.APP.logger.exception(err)
Beispiel #4
0
def fork_project(repo, username=None):
    """ Fork the project specified into the user's namespace
    """
    repo = pagure.lib.get_project(SESSION, repo, user=username)

    form = pagure.forms.ConfirmationForm()
    if not form.validate_on_submit():
        flask.abort(400)

    if repo is None:
        flask.abort(404)

    try:
        message = pagure.lib.fork_project(
            session=SESSION,
            repo=repo,
            gitfolder=APP.config['GIT_FOLDER'],
            forkfolder=APP.config['FORK_FOLDER'],
            docfolder=APP.config['DOCS_FOLDER'],
            ticketfolder=APP.config['TICKETS_FOLDER'],
            requestfolder=APP.config['REQUESTS_FOLDER'],
            user=flask.g.fas_user.username)

        SESSION.commit()
        generate_gitolite_acls()
        flask.flash(message)
        return flask.redirect(
            flask.url_for('view_repo',
                          username=flask.g.fas_user.username,
                          repo=repo.name))
    except pagure.exceptions.PagureException, err:
        flask.flash(str(err), 'error')
Beispiel #5
0
def fork_project(repo, username=None):
    """ Fork the project specified into the user's namespace
    """
    repo = pagure.lib.get_project(SESSION, repo, user=username)

    form = pagure.forms.ConfirmationForm()
    if not form.validate_on_submit():
        flask.abort(400)

    if repo is None:
        flask.abort(404)

    try:
        message = pagure.lib.fork_project(
            session=SESSION,
            repo=repo,
            gitfolder=APP.config['GIT_FOLDER'],
            forkfolder=APP.config['FORK_FOLDER'],
            docfolder=APP.config['DOCS_FOLDER'],
            ticketfolder=APP.config['TICKETS_FOLDER'],
            requestfolder=APP.config['REQUESTS_FOLDER'],
            user=flask.g.fas_user.username)

        SESSION.commit()
        generate_gitolite_acls()
        flask.flash(message)
        return flask.redirect(
            flask.url_for(
                'view_repo',
                username=flask.g.fas_user.username,
                repo=repo.name)
        )
    except pagure.exceptions.PagureException, err:
        flask.flash(str(err), 'error')
Beispiel #6
0
def group_delete(group):
    """ Delete a certain group
    """
    form = pagure.forms.ConfirmationForm()
    if form.validate_on_submit():
        group_obj = pagure.lib.search_groups(pagure.SESSION, group_name=group)

        if not group_obj:
            flask.flash('No group `%s` found' % group, 'error')
            return flask.redirect(flask.url_for('.group_lists'))

        user = pagure.lib.search_user(pagure.SESSION,
                                      username=flask.g.fas_user.username)
        if not user:
            flask.abort(404, 'User not found')

        if group not in user.groups:
            flask.flash('You are not allowed to delete the group %s' % group,
                        'error')
            return flask.redirect(flask.url_for('.group_lists'))

        pagure.SESSION.delete(group_obj)

        pagure.SESSION.commit()
        pagure.generate_gitolite_acls()
        flask.flash('Group `%s` has been deleted' % (group))

    return flask.redirect(flask.url_for('.group_lists'))
Beispiel #7
0
def group_user_delete(user, group):
    """ Delete an user from a certain group
    """
    form = pagure.forms.ConfirmationForm()
    if form.validate_on_submit():

        try:
            pagure.lib.delete_user_of_group(
                pagure.SESSION,
                username=user,
                groupname=group,
                user=flask.g.fas_user.username,
                is_admin=pagure.is_admin(),
            )
            pagure.SESSION.commit()
            pagure.generate_gitolite_acls()
            flask.flash("User `%s` removed from the group `%s`" % (user, group))
        except pagure.exceptions.PagureException, err:
            pagure.SESSION.rollback()
            flask.flash(err.message, "error")
            return flask.redirect(flask.url_for(".view_group", group=group))
        except SQLAlchemyError as err:  # pragma: no cover
            pagure.SESSION.rollback()
            flask.flash("Could not remove user `%s` from the group `%s`." % (user.user, group), "error")
            pagure.APP.logger.debug("Could not remove user `%s` from the group `%s`." % (user.user, group))
            pagure.APP.logger.exception(err)
Beispiel #8
0
def group_delete(group):
    """ Delete a certain group
    """
    form = pagure.forms.ConfirmationForm()
    if form.validate_on_submit():
        group_obj = pagure.lib.search_groups(pagure.SESSION, group_name=group)

        if not group_obj:
            flask.flash("No group `%s` found" % group, "error")
            return flask.redirect(flask.url_for(".group_lists"))

        user = pagure.lib.search_user(pagure.SESSION, username=flask.g.fas_user.username)
        if not user:
            flask.abort(404, "User not found")

        if group not in user.groups:
            flask.flash("You are not allowed to delete the group %s" % group, "error")
            return flask.redirect(flask.url_for(".group_lists"))

        pagure.SESSION.delete(group_obj)

        pagure.SESSION.commit()
        pagure.generate_gitolite_acls()
        flask.flash("Group `%s` has been deleted" % (group))

    return flask.redirect(flask.url_for(".group_lists"))
Beispiel #9
0
def admin_generate_acl():
    """ Regenerate the gitolite ACL file. """
    form = pagure.forms.ConfirmationForm()
    if form.validate_on_submit():
        try:
            generate_gitolite_acls()
            flask.flash('Gitolite ACLs updated')
        except pagure.exceptions.PagureException, err:
            flask.flash(str(err), 'error')
Beispiel #10
0
def add_user(repo, username=None):
    """ Add the specified user from the project.
    """
    if admin_session_timedout():
        if flask.request.method == 'POST':
            flask.flash('Action canceled, try it again', 'error')
        return flask.redirect(
            flask.url_for('auth_login', next=flask.request.url))

    repo = pagure.lib.get_project(SESSION, repo, user=username)

    if not repo:
        flask.abort(404, 'Project not found')

    if not is_repo_admin(repo):
        flask.abort(
            403,
            'You are not allowed to add users to this project')

    form = pagure.forms.AddUserForm()

    if form.validate_on_submit():
        try:
            msg = pagure.lib.add_user_to_project(
                SESSION, repo,
                new_user=form.user.data,
                user=flask.g.fas_user.username,
            )
            SESSION.commit()
            pagure.generate_gitolite_acls()
            flask.flash(msg)
            return flask.redirect(
                flask.url_for(
                    '.view_settings', repo=repo.name, username=username)
            )
        except pagure.exceptions.PagureException as msg:
            SESSION.rollback()
            flask.flash(msg, 'error')
        except SQLAlchemyError as err:  # pragma: no cover
            SESSION.rollback()
            APP.logger.exception(err)
            flask.flash('User could not be added', 'error')

    return flask.render_template(
        'add_user.html',
        form=form,
        username=username,
        repo=repo,
    )
Beispiel #11
0
def add_group_project(repo, username=None):
    """ Add the specified group from the project.
    """
    if admin_session_timedout():
        if flask.request.method == 'POST':
            flask.flash('Action canceled, try it again', 'error')
        return flask.redirect(
            flask.url_for('auth_login', next=flask.request.url))

    repo = pagure.lib.get_project(SESSION, repo, user=username)

    if not repo:
        flask.abort(404, 'Project not found')

    if not is_repo_admin(repo):
        flask.abort(403, 'You are not allowed to add groups to this project')

    form = pagure.forms.AddGroupForm()

    if form.validate_on_submit():
        try:
            msg = pagure.lib.add_group_to_project(
                SESSION,
                repo,
                new_group=form.group.data,
                user=flask.g.fas_user.username,
            )
            SESSION.commit()
            pagure.generate_gitolite_acls()
            flask.flash(msg)
            return flask.redirect(
                flask.url_for('.view_settings',
                              repo=repo.name,
                              username=username))
        except pagure.exceptions.PagureException as msg:
            SESSION.rollback()
            flask.flash(msg, 'error')
        except SQLAlchemyError as err:  # pragma: no cover
            SESSION.rollback()
            APP.logger.exception(err)
            flask.flash('Group could not be added', 'error')

    return flask.render_template(
        'add_group_project.html',
        form=form,
        username=username,
        repo=repo,
    )
Beispiel #12
0
def remove_user(repo, userid, username=None):
    """ Remove the specified user from the project.
    """
    if admin_session_timedout():
        flask.flash('Action canceled, try it again', 'error')
        url = flask.url_for(
            'view_settings', username=username, repo=repo)
        return flask.redirect(
            flask.url_for('auth_login', next=url))

    repo = pagure.lib.get_project(SESSION, repo, user=username)

    if not repo:
        flask.abort(404, 'Project not found')

    if not is_repo_admin(repo):
        flask.abort(
            403,
            'You are not allowed to change the users for this project')

    form = pagure.forms.ConfirmationForm()
    if form.validate_on_submit():
        userids = [str(user.id) for user in repo.users]

        if str(userid) not in userids:
            flask.flash(
                'User does not have commit or cannot loose it right', 'error')
            return flask.redirect(
                flask.url_for(
                    '.view_settings', repo=repo.name, username=username)
            )

        for user in repo.users:
            if str(user.id) == str(userid):
                repo.users.remove(user)
                break
        try:
            SESSION.commit()
            pagure.generate_gitolite_acls()
            flask.flash('User removed')
        except SQLAlchemyError as err:  # pragma: no cover
            SESSION.rollback()
            APP.logger.exception(err)
            flask.flash('User could not be removed', 'error')

    return flask.redirect(
        flask.url_for('.view_settings', repo=repo.name, username=username)
    )
Beispiel #13
0
def remove_user(repo, userid, username=None):
    """ Remove the specified user from the project.
    """
    if admin_session_timedout():
        flask.flash('Action canceled, try it again', 'error')
        url = flask.url_for('view_settings', username=username, repo=repo)
        return flask.redirect(flask.url_for('auth_login', next=url))

    repo = pagure.lib.get_project(SESSION, repo, user=username)

    if not repo:
        flask.abort(404, 'Project not found')

    if not is_repo_admin(repo):
        flask.abort(
            403, 'You are not allowed to change the users for this project')

    form = pagure.forms.ConfirmationForm()
    if form.validate_on_submit():
        userids = [str(user.id) for user in repo.users]

        if str(userid) not in userids:
            flask.flash('User does not have commit or cannot loose it right',
                        'error')
            return flask.redirect(
                flask.url_for('.view_settings',
                              repo=repo.name,
                              username=username))

        for user in repo.users:
            if str(user.id) == str(userid):
                repo.users.remove(user)
                break
        try:
            SESSION.commit()
            pagure.generate_gitolite_acls()
            flask.flash('User removed')
        except SQLAlchemyError as err:  # pragma: no cover
            SESSION.rollback()
            APP.logger.exception(err)
            flask.flash('User could not be removed', 'error')

    return flask.redirect(
        flask.url_for('.view_settings', repo=repo.name, username=username))
Beispiel #14
0
def view_group(group):
    ''' Displays information about this group. '''

    group_type = 'user'
    if pagure.is_admin():
        group_type = None
    group = pagure.lib.search_groups(pagure.SESSION,
                                     group_name=group,
                                     group_type=group_type)

    if not group:
        flask.abort(404, 'Group not found')

    # Add new user to the group if asked
    form = pagure.forms.AddUserForm()
    if pagure.authenticated() and form.validate_on_submit():

        username = form.user.data

        try:
            msg = pagure.lib.add_user_to_group(
                pagure.SESSION,
                username=username,
                group=group,
                user=flask.g.fas_user.username,
                is_admin=pagure.is_admin(),
            )
            pagure.SESSION.commit()
            pagure.generate_gitolite_acls()
            flask.flash(msg)
        except pagure.exceptions.PagureException, err:
            pagure.SESSION.rollback()
            flask.flash(err.message, 'error')
            return flask.redirect(
                flask.url_for('.view_group', group=group.group_name))
        except SQLAlchemyError as err:  # pragma: no cover
            pagure.SESSION.rollback()
            flask.flash(
                'Could not add user `%s` to group `%s`.' %
                (username, group.group_name), 'error')
            pagure.APP.logger.debug('Could not add user `%s` to group `%s`.' %
                                    (username, group.group_name))
            pagure.APP.logger.exception(err)
Beispiel #15
0
def view_group(group):
    """ Displays information about this group. """

    group_type = "user"
    if pagure.is_admin():
        group_type = None
    group = pagure.lib.search_groups(pagure.SESSION, group_name=group, group_type=group_type)

    if not group:
        flask.abort(404, "Group not found")

    # Add new user to the group if asked
    form = pagure.forms.AddUserForm()
    if pagure.authenticated() and form.validate_on_submit():

        username = form.user.data

        try:
            msg = pagure.lib.add_user_to_group(
                pagure.SESSION,
                username=username,
                group=group,
                user=flask.g.fas_user.username,
                is_admin=pagure.is_admin(),
            )
            pagure.SESSION.commit()
            pagure.generate_gitolite_acls()
            flask.flash(msg)
        except pagure.exceptions.PagureException, err:
            pagure.SESSION.rollback()
            flask.flash(err.message, "error")
            return flask.redirect(flask.url_for(".view_group", group=group.group_name))
        except SQLAlchemyError as err:  # pragma: no cover
            pagure.SESSION.rollback()
            flask.flash("Could not add user `%s` to group `%s`." % (username, group.group_name), "error")
            pagure.APP.logger.debug("Could not add user `%s` to group `%s`." % (username, group.group_name))
            pagure.APP.logger.exception(err)