def create_super(): #role = Roles.query.filter_by(name="").first() try: role_s = Roles(name="SUPER_USER") role_a = Roles(name="ADMINISTRATOR") role_u = Roles(name="USER") db.session.add(role_s) db.session.add(role_a) db.session.add(role_u) db.session.commit() except Exception as e: db.session.rollback() print(e) try: role_id = Roles.query.filter_by(name="SUPER_USER").first() user = User( username="******", #password_hash=generate_password_hash("super"), email="*****@*****.**", role_id=role_id.id) user.set_password("super") db.session.add(user) db.session.commit() except Exception as e: print(e) db.session.rollback()
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() from app.models import Roles Roles.insert_roles()
def add_roles(): roles_admin = Roles(name='Администратор') roles_user = Roles(name='Пользователь') db.session.add(roles_admin) db.session.add(roles_user) db.session.commit()
def role_create(name, description): try: role = Roles() role.name = name role.description = description db.session.add(role) db.session.flush() db.session.commit() return role except Exception as e: raise Exception('Database operation exception')
def role_create_db(options=None): if not options['name']: return False else: res = role_exist(options['name']) if res: return False else: role = Roles() role.name = options['name'] role.description = options['description'] db.session.add(role) db.session.commit() return role.name
def add_new_user(user, is_admin=False, is_owner=False): """ Add a user to the database :param user: A string of 9 characters representing a slack user id """ db.session.add(User(id=user)) db.session.commit() if is_owner: db.session.add(Roles(user_id=user, title="owner", perm_level=2)) db.session.commit() elif is_admin: db.session.add(Roles(user_id=user, title="admin", perm_level=1)) db.session.commit()
def create_role_superadmin(): superadmin = Roles(role_id=0, role_name='Superadmin', b_inside=1, b_super=1) db.session.add(superadmin) db.session.commit()
def test_roles(self): roles = Roles.roles_all() list = [] for role in roles: list.append(role.role) self.assertEquals(list[0], "user") self.assertEquals(list[1], "admin") self.assertEquals(list[2], "superadmin")
def create_roles(): app = create_app(Config) app_context = app.app_context() app_context.push() db.create_all() if Roles.query.all(): return True try: role_s = Roles(name=Config.SUPER_USER_STR) role_a = Roles(name=Config.ADMINISTRATOR_STR) role_u = Roles(name=Config.USER_STR) db.session.add(role_s) db.session.add(role_a) db.session.add(role_u) db.session.commit() except Exception as e: db.session.rollback() print(e) return False return True
def main(): try: #-----------------create user roles---------------- role1 = Roles(name ='admin') role2 = Roles(name ='Engg Manager') role3 = Roles(name ='Office Manager') with app.app_context(): db.session.add(role1) db.session.add(role2) db.session.add(role3) db.session.commit() #---------------------create employee types-------------------- employee1 = Employee(emp_id='BP001', name='John Doe', email='*****@*****.**', position='CEO', team='Management', phone='(+91)078-356-7263') employee2 = Employee(emp_id='BP012', name='Gerald Reeves', email='*****@*****.**', position='CTO', team='Management', phone='(+91)592-122-8320') room1 = Rooms(room_id='BP001', name='John Doe', email='*****@*****.**', sitting='10', status='Available') room2 = Rooms(room_id='BP012', name='Gerald Reeves', email='*****@*****.**', sitting='15', status='Booked') db.session.add(employee1) db.session.add(employee2) db.session.add(room1) db.session.add(room2) db.session.commit() #----------------------create user types------------------------------ role_val = Roles.query.filter_by(name='admin').first() user1 = User(email='*****@*****.**', password = '******', role_id=role_val.id) role_val = Roles.query.filter_by(name='Engg Manager').first() user2 = User(email='*****@*****.**', password = '******', role_id=role_val.id) role_val = Roles.query.filter_by(name='Office Manager').first() user3 = User(email='*****@*****.**', password = '******', role_id=role_val.id) db.session.add(user1) db.session.add(user2) db.session.add(user3) db.session.commit() except Exception as ex: print(ex)
def register(): if current_user.is_authenticated: return redirect(url_for("sections.main")) form = RegistrationForm() if form.validate_on_submit(): user = Users(email=form.email.data, last_name=form.last_name.data, first_name=form.first_name.data) user.set_password(form.password.data) user.roles.append(Roles(name="Not confirmed")) db.session.add(user) db.session.commit() flash(_l('Wait for administrator register confirmation.')) return redirect(url_for('auth.login')) return render_template('register.html', title='Register', form=form)
def populate_database(): Roles.populate() Agencies.populate()
from app import Create_app, db from flask_migrate import Migrate from flask_script import Manager from app.models import Roles from flask import current_app app = Create_app('default') app_context = app.app_context() app_context.push() Roles.insert_roles() db.create_all() migrate = Migrate(app, db) manager = Manager(app) # @manager.command # def test(): # '''runs the unit tests''' # import unittest # test = unittest.TestLoader().discover('tests') # unittest.TextTestRunner(verbosity=2).run(tests) if __name__ == "__main__": app.run()
def db_populate(): Roles.insert_roles() Users.superadmin() return redirect('/login')
["HRM", "Master", 0], ["HRM", "Super", 1], ["HRM", "Basic", 2], ["HRM", "Custom1", 777], ["AMS", "Master", 0], ["AMS", "Super", 1], ["AMS", "Basic", 2], ["AMS", "Custom1", 777], ["MMS", "Master", 0], ["MMS", "Super", 1], ["MMS", "Basic", 2], ["MMS", "Custom1", 777]] roles_errors = False for module_abbreviation, role, permission_level in roles_rows: try: db.session.add(Roles(module_abbreviation, role, permission_level)) db.session.commit() except: roles_errors = True db.session.rollback() if roles_errors == True: errors.append(integrity_error.format('Roles')) # Permissions initialization. # - Initializes the app with admin roles. # Parameters: module, role, permission, r(read), w(write), u(update), d(delete). permissions_rows = [["App", "Master", "Master_All", True, True, True, True], ["App", "Super", "Super_All", True, True, True, True], ["App", "Basic", "Read_Only", True, False, False, False], ["App", "Read", "Can_Read", True, False, False, False],
from app import db from app.models import User, Roles db.create_all() U = User(nickname='admin', password='******', email='*****@*****.**', role='admin', name='Виктор', second_name='Сергеев', thriiid_name='Сергеевич', name_avatar='ava.png') db.session.add(U) R = Roles(description='Создаёт/удаляет преподавателей, предметы, группы') db.session.add(R) R = Roles( description= 'Создаёт разделы для загрузки программ и анализирует статистику полученную в ходе работы детектора плагиата' ) db.session.add(R) R = Roles(description='Загружает программы и надеется на лучшее') db.session.add(R) db.session.commit()
def create_role_guest(): guest = Roles(role_id=10000, role_name='Guest', b_inside=1, data_scope=2) db.session.add(guest) db.session.commit()