Example #1
0
def generate_system_roles():
    # create admin role if it doesn't exist
    r = Role.query.filter_by(name='Admin').first()
    if not r:
        Role(name='Admin').save()

    # create DA role, if not exists
    r = Role.query.filter_by(name='DA').first()
    if not r:
        Role(name='DA').save()

    # create MOD role, if not exists
    r = Role.query.filter_by(name='Mod').first()
    if not r:
        Role(name='Mod').save()
Example #2
0
def add_role(email, role):
    """Adds a role to the specified user.
        """
    from enferno.user.models import Role
    u = User.query.filter(User.email == email).first()

    if u is None:
        print('Sorry, this user does not exist!')
    else:
        r = Role.query.filter(Role.name == role).first()
        if r is None:
            print('Sorry, this role does not exist!')
            u = click.prompt('Would you like to create one? Y/N', default='N')
            if u.lower() == 'y':
                r = Role(name=role)
                try:
                    db.session.add(r)
                    db.session.commit()
                    print(
                        'Role created successfully, you may add it now to the user'
                    )
                except Exception as e:
                    db.session.rollback()
        # add role to user
        u.roles.append(r)
Example #3
0
def add_role(email, role):
    """Adds a role to the specified user.
        """
    from enferno.user.models import Role
    u = User.query.filter(User.email == email).first()
    if u == None:
        print('Sorry, this user does not exist!')
        return
    r = Role.query.filter(Role.name == role).first()
    if r == None:
        print('Sorry, this role does not exist!')
        u = click.prompt('Would you like to create one? Y/N', default='N')
        if u.lower() == 'y':
            r = Role(name=role)
            try:
                db.session.add(r)
                db.session.commit()
                print(
                    'Role created successfully, you may add it now to the user'
                )
            except:
                db.session.rollback()

    else:
        AddRoleCommand().run(user_identifier=email, role_name=role)
Example #4
0
def add_role(email, role):
    """Adds a role to the specified user.
    """
    from enferno.user.models import Role
    u = User.objects(email = email).first()
    if u == None:
        print ('Sorry, this user does not exist!')
        return
    r = Role.objects(name = role).first()
    if r == None:
        print ('Sorry, this role does not exist!')
        u = click.prompt('Would you like to create one? Y/N', default='N')
        if u.lower() == 'y':
            Role(name=role).save()
            print ('Role created successfully, you may add it now to the user')
    else:
        AddRoleCommand().run(user_identifier=email, role_name=role)
Example #5
0
def generate_user_roles():
    '''
    Generates standard user roles.
    '''
    # create admin role if it doesn't exist
    r = Role.query.filter_by(name='Admin').first()
    if not r:
        Role(name='Admin').save()

    # create DA role, if not exists
    r = Role.query.filter_by(name='DA').first()
    if not r:
        Role(name='DA').save()

    # create MOD role, if not exists
    r = Role.query.filter_by(name='Mod').first()
    if not r:
        Role(name='Mod').save()
Example #6
0
def install():
    """Install a default Admin user and add an Admin role to it.
    """
    # check if admin exists
    from enferno.user.models import Role
    a = Role.query.filter(Role.name == 'Admin').first()
    if a is None:
        # create admin role
        r = Role(name='Admin')
        r.save()
        u = click.prompt('Admin username?', default='admin')
        p = click.prompt('Admin Password (min 6 characters)?')
        user = User(username=u, password=hash_password(p), active=1)
        user.name = 'Admin'
        user.roles.append(r)
        user.save()

    else:
        print('Seems like an Admin is already installed')
Example #7
0
def install():
    """Install a default admin user and add an admin role to it.
    """
    #check if admin exists
    from enferno.user.models import Role
    a = Role.objects.filter(name ='admin').first()

    if a == None:
        r = Role(name='admin').save()
        u = click.prompt('Admin Email?',default='*****@*****.**')
        p = click.prompt('Admin Password (min 6 characters)?',default='enferno')
        CreateUserCommand().run(email=u,password=p,active=1)
        AddRoleCommand().run(user_identifier=u,role_name='admin')
    else:
        print ('Seems like an Admin is already installed')
Example #8
0
def install():
    """Install a default Admin user and add an Admin role to it.
    """
    # check if admin exists
    from enferno.user.models import Role
    a = Role.query.filter(Role.name == 'Admin').first()

    if a is None:
        r = Role(name='Admin')
        try:
            db.session.add(r)
            db.session.commit()
            u = click.prompt('Admin Email?', default='*****@*****.**')
            p = click.prompt('Admin Password (min 6 characters)?',
                             default='enferno')
            user = User(email=u, password=hash_password(p), active=1)
            user.name = 'Admin'
            user.roles.append(r)
            user.save()
        except Exception as e:
            db.session.rollback()
    else:
        print('Seems like an Admin is already installed')