def __init__(self, *args, **kwargs): """ Calls the default constructor with the normal argument but uses the list of collection provided to fill the choices of the drop-down list. """ super(ProjectForm, self).__init__(*args, **kwargs) # set the name validator regex = pagure_config.get("PROJECT_NAME_REGEX", "^[a-zA-z0-9_][a-zA-Z0-9-_]*$") self.name.validators = [ wtforms.validators.DataRequired(), wtforms.validators.Regexp(regex, flags=re.IGNORECASE), ] # Set the list of namespace if "namespaces" in kwargs: self.namespace.choices = [(namespace, namespace) for namespace in kwargs["namespaces"]] if not pagure_config.get("USER_NAMESPACE", False): self.namespace.choices.insert(0, ("", "")) if not (is_admin() and pagure_config.get("ALLOW_ADMIN_IGNORE_EXISTING_REPOS")) and ( flask.g.fas_user.username not in pagure_config["USERS_IGNORE_EXISTING_REPOS"]): self.ignore_existing_repos = None if not (is_admin() and pagure_config.get("REPOSPANNER_NEW_REPO_ADMIN_OVERRIDE")): self.repospanner_region = None
def __init__(self, *args, **kwargs): """ Calls the default constructor with the normal argument but uses the list of collection provided to fill the choices of the drop-down list. """ super(ProjectForm, self).__init__(*args, **kwargs) # set the name validator regex = pagure_config.get( "PROJECT_NAME_REGEX", "^[a-zA-z0-9_][a-zA-Z0-9-_.+]*$" ) self.name.validators = [ wtforms.validators.DataRequired(), wtforms.validators.Regexp(regex, flags=re.IGNORECASE), ] # Set the list of namespace if "namespaces" in kwargs: self.namespace.choices = [ (namespace, namespace) for namespace in kwargs["namespaces"] ] if not pagure_config.get("USER_NAMESPACE", False): self.namespace.choices.insert(0, ("", "")) if not ( is_admin() and pagure_config.get("ALLOW_ADMIN_IGNORE_EXISTING_REPOS") ) and ( flask.g.fas_user.username not in pagure_config["USERS_IGNORE_EXISTING_REPOS"] ): self.ignore_existing_repos = None if not ( is_admin() and pagure_config.get("REPOSPANNER_NEW_REPO_ADMIN_OVERRIDE") ): self.repospanner_region = None
def set_user(): if flask.g.fas_user.username is None: flask.flash( "It looks like your Identity Provider did not provide an " "username we could retrieve, username being needed we cannot " "go further.", "error", ) logout() return flask.session["_new_user"] = False if not pagure.lib.query.search_user( flask.g.session, username=flask.g.fas_user.username ): flask.session["_new_user"] = True try: pagure.lib.query.set_up_user( session=flask.g.session, username=flask.g.fas_user.username, fullname=flask.g.fas_user.fullname, default_email=flask.g.fas_user.email, ssh_key=flask.g.fas_user.get("ssh_key"), keydir=pagure_config.get("GITOLITE_KEYDIR", None), ) # If groups are managed outside pagure, set up the user at login if not pagure_config.get("ENABLE_GROUP_MNGT", False): user = pagure.lib.query.search_user( flask.g.session, username=flask.g.fas_user.username ) old_groups = set(user.groups) fas_groups = set(flask.g.fas_user.groups) # Add the new groups for group in fas_groups - old_groups: groupobj = None if group: groupobj = pagure.lib.query.search_groups( flask.g.session, group_name=group ) if groupobj: try: pagure.lib.query.add_user_to_group( session=flask.g.session, username=flask.g.fas_user.username, group=groupobj, user=flask.g.fas_user.username, is_admin=is_admin(), from_external=True, ) except pagure.exceptions.PagureException as err: _log.error(err) # Remove the old groups for group in old_groups - fas_groups: if group: try: pagure.lib.query.delete_user_of_group( session=flask.g.session, username=flask.g.fas_user.username, groupname=group, user=flask.g.fas_user.username, is_admin=is_admin(), force=True, from_external=True, ) except pagure.exceptions.PagureException as err: _log.error(err) flask.g.session.commit() except SQLAlchemyError as err: flask.g.session.rollback() _log.exception(err) message = Markup( "Could not set up you as a user properly," ' please <a href="/about">contact an administrator</a>' ) flask.flash(message, "error") # Ensure the user is logged out if we cannot set them up # correctly logout()
def set_user(): if flask.g.fas_user.username is None: flask.flash( "It looks like your Identity Provider did not provide an " "username we could retrieve, username being needed we cannot " "go further.", "error", ) logout() return flask.session["_new_user"] = False if not pagure.lib.query.search_user(flask.g.session, username=flask.g.fas_user.username): flask.session["_new_user"] = True try: pagure.lib.query.set_up_user( session=flask.g.session, username=flask.g.fas_user.username, fullname=flask.g.fas_user.fullname, default_email=flask.g.fas_user.email, ssh_key=flask.g.fas_user.get("ssh_key"), keydir=pagure_config.get("GITOLITE_KEYDIR", None), ) # If groups are managed outside pagure, set up the user at login if not pagure_config.get("ENABLE_GROUP_MNGT", False): user = pagure.lib.query.search_user( flask.g.session, username=flask.g.fas_user.username) old_groups = set(user.groups) fas_groups = set(flask.g.fas_user.groups) # Add the new groups for group in fas_groups - old_groups: groupobj = None if group: groupobj = pagure.lib.query.search_groups(flask.g.session, group_name=group) if groupobj: try: pagure.lib.query.add_user_to_group( session=flask.g.session, username=flask.g.fas_user.username, group=groupobj, user=flask.g.fas_user.username, is_admin=is_admin(), from_external=True, ) except pagure.exceptions.PagureException as err: _log.error(err) # Remove the old groups for group in old_groups - fas_groups: if group: try: pagure.lib.query.delete_user_of_group( session=flask.g.session, username=flask.g.fas_user.username, groupname=group, user=flask.g.fas_user.username, is_admin=is_admin(), force=True, from_external=True, ) except pagure.exceptions.PagureException as err: _log.error(err) flask.g.session.commit() except SQLAlchemyError as err: flask.g.session.rollback() _log.exception(err) message = Markup( "Could not set up you as a user properly," ' please <a href="/about">contact an administrator</a>') flask.flash(message, "error") # Ensure the user is logged out if we cannot set them up # correctly logout()
def set_user(): if flask.g.fas_user.username is None: flask.flash( 'It looks like your Identity Provider did not provide an ' 'username we could retrieve, username being needed we cannot ' 'go further.', 'error') logout() return flask.session['_new_user'] = False if not pagure.lib.search_user(flask.g.session, username=flask.g.fas_user.username): flask.session['_new_user'] = True try: pagure.lib.set_up_user( session=flask.g.session, username=flask.g.fas_user.username, fullname=flask.g.fas_user.fullname, default_email=flask.g.fas_user.email, ssh_key=flask.g.fas_user.get('ssh_key'), keydir=pagure_config.get('GITOLITE_KEYDIR', None), ) # If groups are managed outside pagure, set up the user at login if not pagure_config.get('ENABLE_GROUP_MNGT', False): user = pagure.lib.search_user(flask.g.session, username=flask.g.fas_user.username) old_groups = set(user.groups) fas_groups = set(flask.g.fas_user.groups) # Add the new groups for group in fas_groups - old_groups: groupobj = None if group: groupobj = pagure.lib.search_groups(flask.g.session, group_name=group) if groupobj: try: pagure.lib.add_user_to_group( session=flask.g.session, username=flask.g.fas_user.username, group=groupobj, user=flask.g.fas_user.username, is_admin=is_admin(), from_external=True, ) except pagure.exceptions.PagureException as err: _log.error(err) # Remove the old groups for group in old_groups - fas_groups: if group: try: pagure.lib.delete_user_of_group( session=flask.g.session, username=flask.g.fas_user.username, groupname=group, user=flask.g.fas_user.username, is_admin=is_admin(), force=True, from_external=True, ) except pagure.exceptions.PagureException as err: _log.error(err) flask.g.session.commit() except SQLAlchemyError as err: flask.g.session.rollback() _log.exception(err) flask.flash( 'Could not set up you as a user properly, please contact ' 'an admin', 'error') # Ensure the user is logged out if we cannot set them up # correctly logout()