예제 #1
0
def create_demo_db(s):

    # create demo user
    user = user_datastore.create_user(username="******", password="******")
    role = user_datastore.find_role("admin")
    user_datastore.add_role_to_user(user=user, role=role)
    s.commit()

    sysadmins = models.NotificationGroup(name="sysadmins")
    sysadmins.add_email("*****@*****.**")
    sysadmins.add_email("*****@*****.**")
    sysadmins.add_email("*****@*****.**")

    s.add(sysadmins)
    s.commit()

    # fill the database with dummy content
    jobs = create_jobs(s, sysadmins)

    envs = create_envs(s)

    contexts = create_contexts(s, jobs, envs)

    add_schedules(s, envs, jobs, contexts)

    create_topics(s)

    create_scripts(s, contexts, jobs, envs)

    s.commit()
예제 #2
0
파일: test_user.py 프로젝트: yennicks/kirby
def test_create_user(webapp):
    user = user_datastore.create_user(
        username="******", email="*****@*****.**", password="******"
    )
    db.session.commit()

    assert user.is_local
    assert not user.is_admin
예제 #3
0
파일: test_user.py 프로젝트: yennicks/kirby
def test_promote_user_to_admin(webapp):

    user = user_datastore.create_user(
        username="******", email="*****@*****.**", password="******"
    )
    role = user_datastore.find_role("admin")
    assert role

    db.session.commit()

    assert not user.is_admin

    user_datastore.add_role_to_user(role=role, user=user)

    db.session.commit()

    assert user.is_admin
예제 #4
0
파일: cli.py 프로젝트: yennicks/kirby
def adduser(username):
    app = app_maker()

    with app.app_context():
        app.try_trigger_before_first_request_functions()
        user = user_datastore.find_user(username=username)
        if user is None:
            user = user_datastore.create_user(username=username,
                                              password=getpass())

        msg = ""
        if click.confirm("Give admin rights?"):
            msg = "with admin rights"
            role = user_datastore.find_role("admin")
            user_datastore.add_role_to_user(user=user, role=role)

        click.echo(f"User {username} added {msg}")
        db.session.commit()