示例#1
0
def parse_auth_results(trans, auth_results, options):
    auth_return = {}
    auth_result, auto_email, auto_username = auth_results[:3]
    auto_email = str(auto_email).lower()
    auto_username = str(auto_username).lower()
    # make username unique
    if validate_publicname(trans, auto_username) != '':
        i = 1
        while i <= 10:  # stop after 10 tries
            if validate_publicname(trans, "%s-%i" % (auto_username, i)) == '':
                auto_username = "******" % (auto_username, i)
                break
            i += 1
        else:
            raise Conflict("Cannot make unique username")
    log.debug("Email: %s, auto-register with username: %s" %
              (auto_email, auto_username))
    auth_return["auto_reg"] = string_as_bool(
        options.get('auto-register', False))
    auth_return["email"] = auto_email
    auth_return["username"] = auto_username
    auth_return["auto_create_roles"] = string_as_bool(
        options.get('auto-create-roles', False))
    auth_return["auto_create_groups"] = string_as_bool(
        options.get('auto-create-groups', False))
    auth_return["auto_assign_roles_to_groups_only"] = string_as_bool(
        options.get('auto-assign-roles-to-groups-only', False))

    if len(auth_results) == 4:
        auth_return["attributes"] = auth_results[3]
    return auth_return
示例#2
0
 def create(self, trans, name, description=''):
     """
     Create a new group.
     """
     if not trans.user_is_admin():
         raise ItemAccessibilityException('Only administrators can create groups.')
     else:
         if self.get(trans, name=name):
             raise Conflict('Group with the given name already exists. Name: ' + str(name))
         # TODO add description field to the model
         group = trans.app.model.Group(name=name)
         trans.sa_session.add(group)
         trans.sa_session.flush()
         return group
示例#3
0
 def _check_duplicated_group_name(self, trans: ProvidesAppContext,
                                  group_name: str) -> None:
     if trans.sa_session.query(
             model.Group).filter(model.Group.name == group_name).first():
         raise Conflict(f"A group with name '{group_name}' already exists")