Beispiel #1
0
def setup_for_flamenco(project: pillarsdk.Project):
    from pillar.api.utils import str2id
    import flamenco.setup

    project_id = project._id

    if not project.has_method('PUT'):
        log.warning(
            'User %s tries to set up project %s for Flamenco, but has no PUT rights.',
            current_user, project_id)
        raise wz_exceptions.Forbidden()

    if not current_flamenco.auth.current_user_is_flamenco_user():
        log.warning(
            'User %s tries to set up project %s for Flamenco, but is not flamenco-user.',
            current_user, project_id)
        raise wz_exceptions.Forbidden()

    log.info('User %s sets up project %s for Flamenco', current_user,
             project_id)
    flamenco.setup.setup_for_flamenco(project.url)

    # Find the Managers available to this user, so we can auto-assign if there is exactly one.
    man_man = current_flamenco.manager_manager
    managers = man_man.owned_managers(
        [bson.ObjectId(gid) for gid in current_user.groups])
    manager_count = managers.count()

    project_oid = str2id(project_id)
    user_id = current_user_id()

    if manager_count == 0:
        _, mngr_doc, _ = man_man.create_new_manager('My Manager', '', user_id)
        assign_man_oid = mngr_doc['_id']
        log.info(
            'Created and auto-assigning Manager %s to project %s upon setup for Flamenco.',
            assign_man_oid, project_oid)
        man_man.api_assign_to_project(assign_man_oid, project_oid, 'assign')

    elif manager_count == 1:
        assign_manager = managers.next()
        assign_man_oid = str2id(assign_manager['_id'])
        log.info(
            'Auto-assigning Manager %s to project %s upon setup for Flamenco.',
            assign_man_oid, project_oid)
        man_man.api_assign_to_project(assign_man_oid, project_oid, 'assign')

    return '', 204
Beispiel #2
0
def setup_for_film(project: pillarsdk.Project):
    import cloud.setup

    project_id = project._id

    if not project.has_method('PUT'):
        log.warning(
            'User %s tries to set up project %s for Blender Cloud, but has no PUT rights.',
            current_user, project_id)
        raise wz_exceptions.Forbidden()

    log.info('User %s sets up project %s for Blender Cloud', current_user,
             project_id)
    cloud.setup.setup_for_film(project.url)

    return '', 204
Beispiel #3
0
def setup_for_flamenco(project: pillarsdk.Project):
    from pillar.api.utils import str2id
    import flamenco.setup

    project_id = project._id

    if not project.has_method('PUT'):
        log.warning('User %s tries to set up project %s for Flamenco, but has no PUT rights.',
                    current_user, project_id)
        raise wz_exceptions.Forbidden()

    if not current_flamenco.auth.current_user_is_flamenco_user():
        log.warning('User %s tries to set up project %s for Flamenco, but is not flamenco-user.',
                    current_user, project_id)
        raise wz_exceptions.Forbidden()

    log.info('User %s sets up project %s for Flamenco', current_user, project_id)
    flamenco.setup.setup_for_flamenco(project.url)

    # Find the Managers available to this user, so we can auto-assign if there is exactly one.
    man_man = current_flamenco.manager_manager
    managers = man_man.owned_managers([bson.ObjectId(gid) for gid in current_user.groups])
    manager_count = managers.count()

    project_oid = str2id(project_id)
    user_id = current_user_id()

    if manager_count == 0:
        _, mngr_doc, _ = man_man.create_new_manager('My Manager', '', user_id)
        assign_man_oid = mngr_doc['_id']
        log.info('Created and auto-assigning Manager %s to project %s upon setup for Flamenco.',
                 assign_man_oid, project_oid)
        man_man.api_assign_to_project(assign_man_oid, project_oid, 'assign')

    elif manager_count == 1:
        assign_manager = managers.next()
        assign_man_oid = str2id(assign_manager['_id'])
        log.info('Auto-assigning Manager %s to project %s upon setup for Flamenco.',
                 assign_man_oid, project_oid)
        man_man.api_assign_to_project(assign_man_oid, project_oid, 'assign')

    return '', 204