Exemplo n.º 1
0
def _grant_permission_to_user(session, users_data, experiments_data, login, exp_name, cat_name, time):
    if (exp_name, cat_name) not in experiments_data:
        raise Exception("Error: %s@%s not previously registered" % (exp_name, cat_name))

    db_user = users_data[login]

    up_allowed = model.DbUserPermission(
        db_user,
        permissions.EXPERIMENT_ALLOWED,
        "%s::%s" % (login, exp_name),
        datetime.datetime.utcnow(),
        "Permission for user %s to use %s" % (login, exp_name)
    )
    session.add(up_allowed)
    up_allowed_p1 = model.DbUserPermissionParameter(up_allowed, permissions.EXPERIMENT_PERMANENT_ID, exp_name)
    session.add(up_allowed_p1)
    up_allowed_p2 = model.DbUserPermissionParameter(up_allowed, permissions.EXPERIMENT_CATEGORY_ID, cat_name)
    session.add(up_allowed_p2)
    up_allowed_p3 = model.DbUserPermissionParameter(up_allowed, permissions.TIME_ALLOWED, six.text_type(time))
    session.add(up_allowed_p3)
Exemplo n.º 2
0
 def grant_on_admin_panel_to_user(self, user, permission_type, permanent_id,
                                  date, comments):
     try:
         user_permission = Model.DbUserPermission(
             user, permission_type.user_applicable, permanent_id, date,
             comments)
         self.session.add(user_permission)
         user_permission_p1 = Model.DbUserPermissionParameter(
             user_permission,
             permission_type.get_parameter("full_privileges"), True)
         self.session.add(user_permission_p1)
         self.session.commit()
         return user_permission
     except IntegrityError:
         return None
Exemplo n.º 3
0
    def grant_on_experiment_to_user(self, user, permission_type, permanent_id,
                                    date, comments, experiment, time_allowed,
                                    priority, initialization_in_accounting):
        try:
            user_permission = Model.DbUserPermission(
                user, permission_type.user_applicable, permanent_id, date,
                comments)
            self.session.add(user_permission)
            user_permission_p1 = Model.DbUserPermissionParameter(
                user_permission,
                permission_type.get_parameter("experiment_permanent_id"),
                experiment.name)
            self.session.add(user_permission_p1)
            user_permission_p2 = Model.DbUserPermissionParameter(
                user_permission,
                permission_type.get_parameter("experiment_category_id"),
                experiment.category.name)
            self.session.add(user_permission_p2)
            user_permission_p3 = Model.DbUserPermissionParameter(
                user_permission, permission_type.get_parameter("time_allowed"),
                time_allowed)
            self.session.add(user_permission_p3)
            user_permission_p4 = Model.DbUserPermissionParameter(
                user_permission, permission_type.get_parameter("priority"),
                priority)
            self.session.add(user_permission_p4)
            user_permission_p5 = Model.DbUserPermissionParameter(
                user_permission,
                permission_type.get_parameter("initialization_in_accounting"),
                initialization_in_accounting)
            self.session.add(user_permission_p5)

            self.session.commit()
            return user_permission
        except IntegrityError:
            return None
Exemplo n.º 4
0
    def test_model(self):

        #
        # Create objects
        #
        auth_type = Model.DbAuthType("DB")

        permission_type = permissions.EXPERIMENT_ALLOWED
        permission_type_p1 = permissions.EXPERIMENT_PERMANENT_ID
        permission_type_p2 = permissions.EXPERIMENT_CATEGORY_ID
        permission_type_p3 = permissions.TIME_ALLOWED

        auth = Model.DbAuth(auth_type, "WebLab DB", 1)

        role = Model.DbRole("administrator")

        user = Model.DbUser("admin1", "Name of administrator 1",
                            "*****@*****.**", None, role)

        group = Model.DbGroup("5A")

        user_permission = Model.DbUserPermission(
            user, permission_type, "student2::weblab-pld",
            datetime.datetime.utcnow(),
            "Permission for student2 to use WebLab-PLD")
        user_permission_p1 = Model.DbUserPermissionParameter(
            user_permission, permission_type_p1, "ud-pld")
        user_permission_p2 = Model.DbUserPermissionParameter(
            user_permission, permission_type_p2, "PLD experiments")
        user_permission_p3 = Model.DbUserPermissionParameter(
            user_permission, permission_type_p3, "100")

        group_permission = Model.DbGroupPermission(
            group, permission_type, "5A::weblab-dummy",
            datetime.datetime.utcnow(),
            "Permission for group 5A to use WebLab-Dummy")
        group_permission_p1 = Model.DbGroupPermissionParameter(
            group_permission, permission_type_p1, "ud-dummy")
        group_permission_p2 = Model.DbGroupPermissionParameter(
            group_permission, permission_type_p2, "Dummy experiments")
        group_permission_p3 = Model.DbGroupPermissionParameter(
            group_permission, permission_type_p3, "300")

        role_permission = Model.DbRolePermission(
            role, permission_type, "administrator::weblab-dummy",
            datetime.datetime.utcnow(),
            "Permission for administrator to use WebLab-Dummy")
        role_permission_p1 = Model.DbRolePermissionParameter(
            role_permission, permission_type_p1, "ud-dummy")
        role_permission_p2 = Model.DbRolePermissionParameter(
            role_permission, permission_type_p2, "Dummy experiments")
        role_permission_p3 = Model.DbRolePermissionParameter(
            role_permission, permission_type_p3, "300")

        #
        # Method __repr__()
        #
        variables = locals()
        variables.pop("self")
        for k in variables.keys():
            repr(eval(k))

        #
        # Method DbAuth.get_config_value()
        #
        auth.configuration = "param1=value1;param2=value2"
        self.assertEquals("value1", auth.get_config_value("param1"))
        self.assertEquals("value2", auth.get_config_value("param2"))

        #
        # Method Db(User|Group|Role)Permission.get_permission_type()
        #
        self.assertEquals(permission_type,
                          user_permission.get_permission_type())
        self.assertEquals(permission_type,
                          group_permission.get_permission_type())
        self.assertEquals(permission_type,
                          role_permission.get_permission_type())

        #
        # Method Db(User|Group|Role)Permission.get_parameter()
        #
        self.assertEquals(
            user_permission_p1,
            user_permission.get_parameter("experiment_permanent_id"))
        self.assertEquals(
            user_permission_p2,
            user_permission.get_parameter("experiment_category_id"))
        self.assertEquals(user_permission_p3,
                          user_permission.get_parameter("time_allowed"))
        self.assertEquals(
            group_permission_p1,
            group_permission.get_parameter("experiment_permanent_id"))
        self.assertEquals(
            group_permission_p2,
            group_permission.get_parameter("experiment_category_id"))
        self.assertEquals(group_permission_p3,
                          group_permission.get_parameter("time_allowed"))
        self.assertEquals(
            role_permission_p1,
            role_permission.get_parameter("experiment_permanent_id"))
        self.assertEquals(
            role_permission_p2,
            role_permission.get_parameter("experiment_category_id"))
        self.assertEquals(role_permission_p3,
                          role_permission.get_parameter("time_allowed"))

        #
        # Method Db(User|Group|Role)PermissionParameter.get_name()
        #
        self.assertEquals("experiment_permanent_id",
                          user_permission_p1.get_name())
        self.assertEquals("experiment_category_id",
                          user_permission_p2.get_name())
        self.assertEquals("time_allowed", user_permission_p3.get_name())
        self.assertEquals("experiment_permanent_id",
                          group_permission_p1.get_name())
        self.assertEquals("experiment_category_id",
                          group_permission_p2.get_name())
        self.assertEquals("time_allowed", group_permission_p3.get_name())
        self.assertEquals("experiment_permanent_id",
                          role_permission_p1.get_name())
        self.assertEquals("experiment_category_id",
                          role_permission_p2.get_name())
        self.assertEquals("time_allowed", role_permission_p3.get_name())

        #
        # Method Db(User|Group|Role)PermissionParameter.get_datatype()
        #
        self.assertEquals("string", user_permission_p1.get_datatype())
        self.assertEquals("string", user_permission_p2.get_datatype())
        self.assertEquals("float", user_permission_p3.get_datatype())
        self.assertEquals("string", group_permission_p1.get_datatype())
        self.assertEquals("string", group_permission_p2.get_datatype())
        self.assertEquals("float", group_permission_p3.get_datatype())
        self.assertEquals("string", role_permission_p1.get_datatype())
        self.assertEquals("string", role_permission_p2.get_datatype())
        self.assertEquals("float", role_permission_p3.get_datatype())
Exemplo n.º 5
0
    def test_model(self):

        #
        # Create objects
        #
        auth_type = Model.DbAuthType("DB")

        permission_type = Model.DbPermissionType(
            'experiment_allowed',
            'This type has a parameter which is the permanent ID (not a INT) of an Experiment. Users which have this permission will have access to the experiment defined in this parameter',
            user_applicable=True,
            group_applicable=True,
            role_applicable=True,
            ee_applicable=True)
        permission_type_p1 = Model.DbPermissionTypeParameter(
            permission_type, 'experiment_permanent_id', 'string',
            'the unique name of the experiment')
        permission_type_p2 = Model.DbPermissionTypeParameter(
            permission_type, 'experiment_category_id', 'string',
            'the unique name of the category of experiment')
        permission_type_p3 = Model.DbPermissionTypeParameter(
            permission_type, 'time_allowed', 'float',
            'Time allowed (in seconds)')

        auth = Model.DbAuth(auth_type, "WebLab DB", 1)

        role = Model.DbRole("administrator")

        user = Model.DbUser("admin1", "Name of administrator 1",
                            "*****@*****.**", None, role)

        ee = Model.DbExternalEntity("ee1", "Country of ee1",
                                    "Description of ee1", "*****@*****.**",
                                    "password")

        group = Model.DbGroup("5A")

        user_permission = Model.DbUserPermission(
            user, permission_type.group_applicable, "student2::weblab-pld",
            datetime.datetime.utcnow(),
            "Permission for student2 to use WebLab-PLD")
        user_permission_p1 = Model.DbUserPermissionParameter(
            user_permission, permission_type_p1, "ud-pld")
        user_permission_p2 = Model.DbUserPermissionParameter(
            user_permission, permission_type_p2, "PLD experiments")
        user_permission_p3 = Model.DbUserPermissionParameter(
            user_permission, permission_type_p3, "100")

        group_permission = Model.DbGroupPermission(
            group, permission_type.group_applicable, "5A::weblab-dummy",
            datetime.datetime.utcnow(),
            "Permission for group 5A to use WebLab-Dummy")
        group_permission_p1 = Model.DbGroupPermissionParameter(
            group_permission, permission_type_p1, "ud-dummy")
        group_permission_p2 = Model.DbGroupPermissionParameter(
            group_permission, permission_type_p2, "Dummy experiments")
        group_permission_p3 = Model.DbGroupPermissionParameter(
            group_permission, permission_type_p3, "300")

        role_permission = Model.DbRolePermission(
            role, permission_type.role_applicable,
            "administrator::weblab-dummy", datetime.datetime.utcnow(),
            "Permission for administrator to use WebLab-Dummy")
        role_permission_p1 = Model.DbRolePermissionParameter(
            role_permission, permission_type_p1, "ud-dummy")
        role_permission_p2 = Model.DbRolePermissionParameter(
            role_permission, permission_type_p2, "Dummy experiments")
        role_permission_p3 = Model.DbRolePermissionParameter(
            role_permission, permission_type_p3, "300")

        ee_permission = Model.DbExternalEntityPermission(
            ee, permission_type.ee_applicable, "ee1::weblab-dummy",
            datetime.datetime.utcnow(),
            "Permission for ee1 to use WebLab-Dummy")
        ee_permission_p1 = Model.DbExternalEntityPermissionParameter(
            ee_permission, permission_type_p1, "ud-dummy")
        ee_permission_p2 = Model.DbExternalEntityPermissionParameter(
            ee_permission, permission_type_p2, "Dummy experiments")
        ee_permission_p3 = Model.DbExternalEntityPermissionParameter(
            ee_permission, permission_type_p3, "300")

        #
        # Method __repr__()
        #
        variables = locals()
        variables.pop("self")
        for k in variables.keys():
            repr(eval(k))

        #
        # Method DbAuth.get_config_value()
        #
        auth.configuration = "param1=value1;param2=value2"
        self.assertEquals("value1", auth.get_config_value("param1"))
        self.assertEquals("value2", auth.get_config_value("param2"))

        #
        # Method DbPermissionType.get_parameter()
        #
        self.assertEquals(
            permission_type_p1,
            permission_type.get_parameter("experiment_permanent_id"))
        self.assertEquals(
            permission_type_p2,
            permission_type.get_parameter("experiment_category_id"))
        self.assertEquals(permission_type_p3,
                          permission_type.get_parameter("time_allowed"))

        #
        # Method Db(User|Group|Role|ExternalEntity)Permission.get_permission_type()
        #
        self.assertEquals(permission_type,
                          user_permission.get_permission_type())
        self.assertEquals(permission_type,
                          group_permission.get_permission_type())
        self.assertEquals(permission_type,
                          role_permission.get_permission_type())
        self.assertEquals(permission_type, ee_permission.get_permission_type())

        #
        # Method Db(User|Group|Role|ExternalEntity)Permission.get_parameter()
        #
        self.assertEquals(
            user_permission_p1,
            user_permission.get_parameter("experiment_permanent_id"))
        self.assertEquals(
            user_permission_p2,
            user_permission.get_parameter("experiment_category_id"))
        self.assertEquals(user_permission_p3,
                          user_permission.get_parameter("time_allowed"))
        self.assertEquals(
            group_permission_p1,
            group_permission.get_parameter("experiment_permanent_id"))
        self.assertEquals(
            group_permission_p2,
            group_permission.get_parameter("experiment_category_id"))
        self.assertEquals(group_permission_p3,
                          group_permission.get_parameter("time_allowed"))
        self.assertEquals(
            role_permission_p1,
            role_permission.get_parameter("experiment_permanent_id"))
        self.assertEquals(
            role_permission_p2,
            role_permission.get_parameter("experiment_category_id"))
        self.assertEquals(role_permission_p3,
                          role_permission.get_parameter("time_allowed"))
        self.assertEquals(
            ee_permission_p1,
            ee_permission.get_parameter("experiment_permanent_id"))
        self.assertEquals(
            ee_permission_p2,
            ee_permission.get_parameter("experiment_category_id"))
        self.assertEquals(ee_permission_p3,
                          ee_permission.get_parameter("time_allowed"))

        #
        # Method Db(User|Group|Role|ExternalEntity)PermissionParameter.get_name()
        #
        self.assertEquals("experiment_permanent_id",
                          user_permission_p1.get_name())
        self.assertEquals("experiment_category_id",
                          user_permission_p2.get_name())
        self.assertEquals("time_allowed", user_permission_p3.get_name())
        self.assertEquals("experiment_permanent_id",
                          group_permission_p1.get_name())
        self.assertEquals("experiment_category_id",
                          group_permission_p2.get_name())
        self.assertEquals("time_allowed", group_permission_p3.get_name())
        self.assertEquals("experiment_permanent_id",
                          role_permission_p1.get_name())
        self.assertEquals("experiment_category_id",
                          role_permission_p2.get_name())
        self.assertEquals("time_allowed", role_permission_p3.get_name())
        self.assertEquals("experiment_permanent_id",
                          ee_permission_p1.get_name())
        self.assertEquals("experiment_category_id",
                          ee_permission_p2.get_name())
        self.assertEquals("time_allowed", ee_permission_p3.get_name())

        #
        # Method Db(User|Group|Role|ExternalEntity)PermissionParameter.get_datatype()
        #
        self.assertEquals("string", user_permission_p1.get_datatype())
        self.assertEquals("string", user_permission_p2.get_datatype())
        self.assertEquals("float", user_permission_p3.get_datatype())
        self.assertEquals("string", group_permission_p1.get_datatype())
        self.assertEquals("string", group_permission_p2.get_datatype())
        self.assertEquals("float", group_permission_p3.get_datatype())
        self.assertEquals("string", role_permission_p1.get_datatype())
        self.assertEquals("string", role_permission_p2.get_datatype())
        self.assertEquals("float", role_permission_p3.get_datatype())
        self.assertEquals("string", ee_permission_p1.get_datatype())
        self.assertEquals("string", ee_permission_p2.get_datatype())
        self.assertEquals("float", ee_permission_p3.get_datatype())
Exemplo n.º 6
0
def populate_weblab_tests(engine, tests):
    Session = sessionmaker(bind=engine)
    Session._model_changes = {}
    session = Session()

    ldap = session.query(model.DbAuthType).filter_by(name="LDAP").one()
    iptrusted = session.query(model.DbAuthType).filter_by(name="TRUSTED-IP-ADDRESSES").one()
    facebook = session.query(model.DbAuthType).filter_by(name="FACEBOOK").one()

    # Auths
    cdk_ldap = model.DbAuth(ldap, "Configuration of CDK at Deusto", 2, "ldap_uri=ldaps://castor.cdk.deusto.es;domain=cdk.deusto.es;base=dc=cdk,dc=deusto,dc=es")
    session.add(cdk_ldap)

    deusto_ldap = model.DbAuth(ldap, "Configuration of DEUSTO at Deusto", 3, "ldap_uri=ldaps://altair.cdk.deusto.es;domain=deusto.es;base=dc=deusto,dc=es")
    session.add(deusto_ldap)

    localhost_ip = model.DbAuth(iptrusted, "trusting in localhost", 4, "127.0.0.1")
    session.add(localhost_ip)

    auth_facebook = model.DbAuth(facebook, "Facebook", 5)
    session.add(auth_facebook)

    administrator = session.query(model.DbRole).filter_by(name='administrator').one()
    instructor    = session.query(model.DbRole).filter_by(name='instructor').one()
    student       = session.query(model.DbRole).filter_by(name='student').one()
    federated     = session.query(model.DbRole).filter_by(name='federated').one()

    # Users
    # Please keep alphabetical order :-)
    all_users = _create_users(session, {
        'admin1'       : (administrator, 'Name of administrator 1',       '*****@*****.**'),
        'admin2'       : (administrator, 'Name of administrator 2',       '*****@*****.**'),
        'admin3'       : (administrator, 'Name of administrator 3',       '*****@*****.**'),

        'any'          : (student,       'Name of any',                   '*****@*****.**',  'password', None, [(auth_facebook, '1168497114')]),
        'admin'        : (administrator, 'Administrator',                 '*****@*****.**'),

        'archimedes'   : (student,       'Usuario de prueba para Splash', '*****@*****.**',  'archimedes'),
        'consumer1'    : (federated,     'Consumer University 1',         '*****@*****.**'),
        'fedstudent1'  : (federated,     'Name of federated user 1',      '*****@*****.**'),
        'fedstudent2'  : (federated,     'Name of federated user 2',      '*****@*****.**'),
        'fedstudent3'  : (federated,     'Name of federated user 3',      '*****@*****.**'),
        'fedstudent4'  : (federated,     'Name of federated user 4',      '*****@*****.**'),

        'intstudent1'  : (student,       'Name of integration test 1',    '*****@*****.**'),
        'intstudent2'  : (student,       'Name of integration test 2',    '*****@*****.**'),
        'intstudent3'  : (student,       'Name of integration test 3',    '*****@*****.**'),
        'intstudent4'  : (student,       'Name of integration test 4',    '*****@*****.**'),
        'intstudent5'  : (student,       'Name of integration test 5',    '*****@*****.**'),
        'intstudent6'  : (student,       'Name of integration test 6',    '*****@*****.**'),

        'prof1'        : (instructor,    'Name of instructor 1',          '*****@*****.**'),
        'prof2'        : (instructor,    'Name of instructor 2',          '*****@*****.**'),
        'prof3'        : (instructor,    'Name of instructor 3',          '*****@*****.**'),
        'provider1'    : (federated,     'Provider University 1',         '*****@*****.**'),
        'provider2'    : (federated,     'Provider University 2',         '*****@*****.**'),

        'student1'     : (student,       'Name of student 1',             '*****@*****.**'),
        'student2'     : (student,       'Name of student 2',             '*****@*****.**'),
        'student3'     : (student,       'Name of student 3',             '*****@*****.**'),
        'student4'     : (student,       'Name of student 4',             '*****@*****.**'),
        'student5'     : (student,       'Name of student 5',             '*****@*****.**'),
        'student6'     : (student,       'Name of student 6',             '*****@*****.**'),
        'student7'     : (student,       'Name of student 7',             '*****@*****.**', None, 'aaaa{thishashdoesnotexist}a776159c8c7ff8b73e43aa54d081979e72511474'),
        'student8'     : (student,       'Name of student 8',             '*****@*****.**', None, 'this.format.is.not.valid.for.the.password'),
        'studentILAB'  : (student,       'Name of student ILAB',          '*****@*****.**'),
        'studentLDAP1' : (student,       'Name of student LDAP1',         '*****@*****.**', 'password', None, [(cdk_ldap, None)]),
        'studentLDAP2' : (student,       'Name of student LDAP2',         '*****@*****.**', 'password', None, [(cdk_ldap, None)]),
        'studentLDAP3' : (student,       'Name of student LDAP3',         '*****@*****.**', 'password', None, [(deusto_ldap, None)]),
    })

    # Please keep alphabetical order :-)
    all_groups = _create_groups(session, all_users, {
        ('Course 2008/09',    None)              : ('student1', 'student2'),
        ('Course 2009/10',    None)              : ('student1', 'student2', 'student3', 'student4', 'student5', 'student6'),
        ('Course Tests',      None)              : ('intstudent1', 'intstudent2', 'intstudent3', 'intstudent4', 'intstudent5', 'intstudent6'),
        ('Federated users',   None)              : ('fedstudent1', 'fedstudent2', 'fedstudent3', 'fedstudent4', 'consumer1', 'provider1', 'provider2'),
        ('Mechatronics',      'Course 2008/09')  : ('student3', 'student4'),
        ('Telecomunications', 'Course 2008/09')  : ('student5', 'student6'),
    })

    # Please keep alphabetical order :-)
    all_experiments = _create_experiments(session, {
        ('aquarium',                'Aquatic experiments')   : 'aquarium',
        ('aquariumjs',              'Aquatic experiments')   : 'js',
        ('archimedes',              'Aquatic experiments')   : 'js',
        ('binary',                  'Games')                 : 'binary',
        ('blink-led',               'LabVIEW experiments')   : 'labview',
        ('control-app',             'Control experiments')   : 'control-app',
        ('dummy1',                  'Dummy experiments')     : 'dummy',
        ('dummy2',                  'Dummy experiments')     : 'dummy',
        ('dummy4',                  'Dummy experiments')     : 'dummy',
        ('elevator',                'FPGA experiments')      : 'js',
        ('external-robot-movement', 'Robot experiments')     : 'blank',
        ('flashdummy',              'Dummy experiments')     : 'flash',
        ('http',                    'HTTP experiments')      : 'redirect',
        ('hwboard-fpga',            'FPGA experiments')      : 'js',
        ('hwboard-fpga-watertank',  'FPGA experiments')      : 'js',
        ('incubator',               'Farm experiments')      : 'incubator',
        ('new_incubator',           'Farm experiments')      : 'js',
        ('javadummy',               'Dummy experiments')     : 'java',
        ('jsdummy',                 'Dummy experiments')     : 'js',
        ('jsfpga',                  'FPGA experiments')      : 'js',
        ('microelectronics',        'iLab experiments')      : 'ilab-batch',
        ('robot-maze',              'Robot experiments')     : 'robot-maze',
        ('robot-movement',          'Robot experiments')     : 'robot-movement',
        ('robot-proglist',          'Robot experiments')     : 'robot-proglist',
        ('robot-standard',          'Robot experiments')     : 'robot-standard',
        ('robotarm',                'Robot experiments')     : 'robotarm',
        ('romie',                   'Robot experiments')     : 'js',
        ('romie_labpsico',          'Robot experiments')     : 'js',
        ('romie_demo',              'Robot experiments')     : 'js',
        ('romie_blockly',           'Robot experiments')     : 'js',
        ('submarine',               'Submarine experiments') : 'submarine',
        ('submarinejs',             'Aquatic experiments')   : 'js',
        ('ud-demo-fpga',            'FPGA experiments')      : 'xilinx',
        ('ud-demo-pld',             'PLD experiments')       : 'xilinx',
        ('ud-demo-xilinx',          'Xilinx experiments')    : 'xilinx',
        ('ud-dummy',                'Dummy experiments')     : 'js',
        ('ud-dummy-batch',          'Dummy experiments')     : 'dummybatch',
        ('ud-fpga',                 'FPGA experiments')      : 'xilinx',
        ('ud-gpib',                 'GPIB experiments')      : 'gpib',
        ('ud-logic',                'PIC experiments')       : 'logic',
        ('ud-pld',                  'PLD experiments')       : 'xilinx',
        ('ud-pic18',                'PIC experiments')       : 'pic18',
        ('unr-physics',             'Physics experiments')   : 'js',
        ('visir',                   'Visir experiments')     : 'visir',
        ('visir-html5',             'Visir experiments')     : 'js',
        ('visirtest',               'Dummy experiments')     : 'visir',
        ('vm',                      'Dummy experiments')     : 'vm',
        ('vm-win',                  'Dummy experiments')     : 'vm',
    })

    if tests != '2':
        all_experiments['dummy3', 'Dummy experiments'] = _create_experiment(session, 'dummy3', 'Dummy experiments', 'dummy')
    else:
        all_experiments['dummy3_with_other_name', 'Dummy experiments'] = _create_experiment(session, 'dummy3_with_other_name', 'Dummy experiments', 'dummy')


    # Please keep alphabetical order :-)
    _grant_permissions_to_groups(session, all_groups, all_experiments, [
        ('Course 2008/09',  'flashdummy',  'Dummy experiments',  30),
        ('Course 2008/09',  'javadummy',   'Dummy experiments',  30),
        ('Course 2008/09',  'ud-dummy',    'Dummy experiments', 150),
        ('Course 2008/09',  'ud-fpga',     'FPGA experiments',  300),
        ('Course 2008/09',  'ud-logic',    'PIC experiments',   150),

        ('Course 2009/10',  'ud-fpga',     'FPGA experiments',  300),

        ('Course Tests',    'dummy1',      'Dummy experiments',  300),
        ('Course Tests',    'dummy2',      'Dummy experiments',  300),

        ('Federated users', 'dummy1',      'Dummy experiments', 300),
        ('Federated users', 'dummy2',      'Dummy experiments', 300),
        ('Federated users', 'dummy4',      'Dummy experiments', 300),
    ])

    if tests != '2':
        _grant_permissions_to_groups(session, all_groups, all_experiments, [
            ('Federated users', 'dummy3',  'Dummy experiments', 300),
        ])
    else:
        _grant_permissions_to_groups(session, all_groups, all_experiments, [
            ('Federated users', 'dummy3_with_other_name',  'Dummy experiments', 300),
        ])


    # Please keep alphabetical order :-)
    _grant_permissions_to_users(session, all_users, all_experiments, [
        ('archimedes', 'archimedes',              'Aquatic experiments',   1400),

        ('any',        'aquarium',                'Aquatic experiments',    200),
        ('any',        'aquariumjs',              'Aquatic experiments',    200),
        ('any',        'binary',                  'Games',                  200),
        ('any',        'blink-led',               'LabVIEW experiments',    200),
        ('any',        'control-app',             'Control experiments',    200),
        ('any',        'elevator',                'FPGA experiments',      1400),
        ('any',        'external-robot-movement', 'Robot experiments',      200),
        ('any',        'http',                    'HTTP experiments',       200),
        ('any',        'hwboard-fpga',            'FPGA experiments',      1400),
        ('any',        'hwboard-fpga-watertank',  'FPGA experiments',      1400),
        ('any',        'new_incubator',           'Farm experiments',       300),
        ('any',        'jsdummy',                 'Dummy experiments',     1400),
        ('any',        'jsfpga',                  'FPGA experiments',      1400),
        ('any',        'microelectronics',        'iLab experiments',       200),
        ('any',        'robot-maze',              'Robot experiments',      200),
        ('any',        'robot-movement',          'Robot experiments',      200),
        ('any',        'robot-proglist',          'Robot experiments',      200),
        ('any',        'robot-standard',          'Robot experiments',      200),
        ('any',        'robotarm',                'Robot experiments',      200),
        ('any',        'romie',                   'Robot experiments',      1200),
        ('any',        'romie_labpsico',          'Robot experiments',      1800),
        ('any',        'romie_demo',              'Robot experiments',      1800),
        ('any',        'romie_blockly',           'Robot experiments',      1800),
        ('any',        'submarine',               'Submarine experiments',  200),
        ('any',        'submarinejs',             'Aquatic experiments',    200),
        ('any',        'ud-demo-fpga',            'FPGA experiments',       200),
        ('any',        'ud-demo-pld',             'PLD experiments',        200),
        ('any',        'ud-demo-xilinx',          'Xilinx experiments',     200),
        ('any',        'ud-dummy',                'Dummy experiments',      200),
        ('any',        'ud-dummy-batch',          'Dummy experiments',      200),
        ('any',        'ud-fpga',                 'FPGA experiments',      1400),
        ('any',        'ud-gpib',                 'GPIB experiments',       150),
        ('any',        'ud-logic',                'PIC experiments',        200),
        ('any',        'ud-pic18',                'PIC experiments',        200),
        ('any',        'unr-physics',             'Physics experiments',    200),
        ('any',        'visir',                   'Visir experiments',     3600),
        ('any',        'visir-html5',             'Visir experiments',     3600),
        ('any',        'visirtest',               'Dummy experiments',     3600),
        ('any',        'vm',                      'Dummy experiments',      200),
        ('any',        'vm-win',                  'Dummy experiments',      200),

        ('student2',   'ud-gpib',                 'GPIB experiments',       150),
        ('student2',   'ud-pld',                  'PLD experiments',        100),
        ('student6',   'ud-pld',                  'PLD experiments',        140),
    ])

    # Other permissions
    up_student1_admin_panel_access = model.DbUserPermission(
        all_users['student1'],
        permissions.ADMIN_PANEL_ACCESS,
        "student1::admin_panel_access",
        datetime.datetime.utcnow(),
        "Access to the admin panel for student1 with full_privileges"
    )
    session.add(up_student1_admin_panel_access)
    up_student1_admin_panel_access_p1 = model.DbUserPermissionParameter(up_student1_admin_panel_access, permissions.FULL_PRIVILEGES, True)
    session.add(up_student1_admin_panel_access_p1)

    up_any_access_forward = model.DbUserPermission(
        all_users['any'],
        permissions.ACCESS_FORWARD,
        "any::access_forward",
        datetime.datetime.utcnow(),
        "Access to forward external accesses"
    )

    session.add(up_any_access_forward)

    client_properties = {
        "demo.available": True,
        "admin.email": "*****@*****.**",
        "google.analytics.tracking.code": "UA-1234567-8",
        "host.entity.link": "http://www.deusto.es/",
    }
    
    for key, value in six.iteritems(client_properties):
        session.add(model.DbClientProperties(key, value))

    session.commit()