Esempio n. 1
0
def create_services():
    track = Track.get_service_name()
    session = Session.get_service_name()
    speaker = Speaker.get_service_name()
    sponsor = Sponsor.get_service_name()
    microlocation = Microlocation.get_service_name()

    get_or_create(Service, name=track)
    get_or_create(Service, name=session)
    get_or_create(Service, name=speaker)
    get_or_create(Service, name=sponsor)
    get_or_create(Service, name=microlocation)
Esempio n. 2
0
def create_permissions():
    ownr = Role.query.filter_by(name=Role.OWNER).first()
    orgr = Role.query.filter_by(name=Role.ORGANIZER).first()
    coorgr = Role.query.filter_by(name=Role.COORGANIZER).first()
    track_orgr = Role.query.filter_by(name=TRACK_ORGANIZER).first()
    mod = Role.query.filter_by(name=MODERATOR).first()
    regist = Role.query.filter_by(name=REGISTRAR).first()
    track = Service.query.filter_by(name=Track.get_service_name()).first()
    session = Service.query.filter_by(name=Session.get_service_name()).first()
    speaker = Service.query.filter_by(name=Speaker.get_service_name()).first()
    sponsor = Service.query.filter_by(name=Sponsor.get_service_name()).first()
    microlocation = Service.query.filter_by(
        name=Microlocation.get_service_name()).first()

    # For ORGANIZER and OWNER
    # All four permissions set to True
    services = [track, session, speaker, sponsor, microlocation]
    for service in services:
        perm, _ = get_or_create(Permission, role=ownr, service=service)
        db.session.add(perm)

    for service in services:
        perm, _ = get_or_create(Permission, role=orgr, service=service)
        db.session.add(perm)

    # For COORGANIZER
    for service in services:
        perm, _ = get_or_create(Permission, role=coorgr, service=service)
        perm.can_create, perm.can_delete = False, False
        db.session.add(perm)

    # For TRACK_ORGANIZER
    for service in services:
        perm, _ = get_or_create(Permission, role=track_orgr, service=service)
        if not service == track:
            perm.can_create, perm.can_update, perm.can_delete = False, False, False
        db.session.add(perm)

    # For MODERATOR
    for service in services:
        perm, _ = get_or_create(Permission, role=mod, service=service)
        perm.can_create, perm.can_update, perm.can_delete = False, False, False
        db.session.add(perm)

    # For REGISTRAR
    services = [track, session, speaker, sponsor, microlocation]
    for service in services:
        perm, _ = get_or_create(Permission, role=regist, service=service)
        perm.can_create, perm.can_update, perm.can_delete = False, False, False
        db.session.add(perm)