def add_user_to_groups(username): """ Create a user to group relationship in the database Returns a json object """ groups = request.get_json().get("groups", []) return jsonify(admin.add_user_to_groups(current_session, username, groups=groups))
def test_add_user_to_group(db_session, awg_users, awg_groups): accesses = (db_session.query(AccessPrivilege).join( AccessPrivilege.user).filter(User.username == "awg_user_2").all()) assert accesses == [] adm.add_user_to_groups(db_session, "awg_user_2", ["test_group_4"]) accesses = (db_session.query(AccessPrivilege).join( AccessPrivilege.user).filter(User.username == "awg_user_2").all()) projects = [ db_session.query(Project).filter( Project.id == item.project_id).first().name for item in accesses if item.project_id != None ] assert "test_project_6" in projects assert "test_project_7" in projects group_access = (db_session.query(UserToGroup).join( UserToGroup.user).filter(User.username == "awg_user_2").first()) assert ("test_group_4" == db_session.query(Group).filter( Group.id == group_access.group_id).first().name)