def __init__(self, app, cfg_manager, ups, bypass_authz = False): super(AdministrationApplication, self).__init__() import weblab.admin.web.app as app_module app_module.GLOBAL_APP_INSTANCE = self self.cfg_manager = cfg_manager db.initialize(cfg_manager) self.ups = ups db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=db.engine)) files_directory = cfg_manager.get_doc_value(configuration_doc.CORE_STORE_STUDENTS_PROGRAMS_PATH) core_server_url = cfg_manager.get_value( 'core_server_url', '' ) self.script_name = urlparse.urlparse(core_server_url).path.split('/weblab')[0] or '' self.app = app static_folder = os.path.abspath(os.path.join(os.path.dirname(web.__file__), 'static')) ################################################ # # Administration panel for administrators # # admin_url = '/weblab/administration/admin' self.admin = Admin(index_view = admin_views.HomeView(db_session, url = admin_url),name = 'WebLab-Deusto Admin', url = admin_url, endpoint = admin_url, base_template = 'weblab-master.html') self.admin.add_view(admin_views.UsersAddingView(db_session, category = 'General', name = 'Add multiple users', endpoint = 'general/multiple/users')) self.admin.add_view(admin_views.UsersPanel(db_session, category = 'General', name = 'Users', endpoint = 'general/users')) self.admin.add_view(admin_views.GroupsPanel(db_session, category = 'General', name = 'Groups', endpoint = 'general/groups')) self.admin.add_view(admin_views.AuthsPanel(db_session, category = 'General', name = 'Authentication', endpoint = 'general/auth')) self.admin.add_view(admin_views.UserUsedExperimentPanel(files_directory, db_session, category = 'Logs', name = 'User logs', endpoint = 'logs/users')) self.admin.add_view(admin_views.ExperimentCategoryPanel(db_session, category = 'Experiments', name = 'Categories', endpoint = 'experiments/categories')) self.admin.add_view(admin_views.ExperimentPanel(db_session, category = 'Experiments', name = 'Experiments', endpoint = 'experiments/experiments')) # TODO: Until finished, do not display # self.admin.add_view(admin_views.SchedulerPanel(db_session, category = 'Experiments', name = 'Schedulers', endpoint = 'experiments/schedulers')) self.admin.add_view(admin_views.PermissionsAddingView(db_session, category = 'Permissions', name = 'Create', endpoint = 'permissions/create')) self.admin.add_view(admin_views.UserPermissionPanel(db_session, category = 'Permissions', name = 'User', endpoint = 'permissions/user')) self.admin.add_view(admin_views.GroupPermissionPanel(db_session, category = 'Permissions', name = 'Group', endpoint = 'permissions/group')) self.admin.add_view(admin_views.RolePermissionPanel(db_session, category = 'Permissions', name = 'Roles', endpoint = 'permissions/role')) self.admin.add_view(RedirectView('instructor.index', url = 'instructor', name = 'Instructor panel', endpoint = 'instructor/admin')) self.admin.add_view(admin_views.MyProfileView(url = 'myprofile', name = 'My profile', endpoint = 'myprofile/admin')) self.admin.add_view(BackView(url = 'back', name = 'Back', endpoint = 'back/admin')) self.admin.init_app(self.app) self.full_admin_url = self.script_name + admin_url ################################################ # # Profile panel # profile_url = '/weblab/administration/profile' self.profile = Admin(index_view = profile_views.ProfileHomeView(db_session, url = profile_url, endpoint = 'profile'),name = 'WebLab-Deusto profile', url = profile_url, endpoint = profile_url, base_template = 'weblab-master.html') self.profile.add_view(profile_views.ProfileEditView(db_session, name = 'Edit', endpoint = 'edit')) self.profile.add_view(profile_views.MyAccessesPanel(files_directory, db_session, name = 'My accesses', endpoint = 'accesses')) self.profile.add_view(BackView(url = 'back', name = 'Back', endpoint = 'back/profile')) self.profile.init_app(self.app) ################################################ # # Instructors panel # # TODO. There should be able a new M2M relation between instructors and groups. # # Instructor should be able to: # # a) Create new groups (of which they are in charge) # b) Make other instructors in charge of these groups # c) Add students (and only students) to the system; forcing a group # d) Edit users (only students; of those groups that the administrator is in charge of) # e) Assign permissions on these courses # f) Manage the permissions on these courses # g) See the logs of their own students # h) See a panel with analytics of each of these groups (this panel is common to the administrator, and has not been implemented) instructor_url = '/weblab/administration/instructor' instructor_home = instructor_views.InstructorHomeView(db_session, url = instructor_url, endpoint = 'instructor') instructor_home.static_folder = static_folder self.instructor = Admin(index_view = instructor_home, name = "Weblab-Deusto instructor", url = instructor_url, endpoint = instructor_url, base_template = 'weblab-master.html') self.instructor.add_view(instructor_views.UsersPanel(db_session, category = 'General', name = 'Users', endpoint = 'users')) self.instructor.add_view(instructor_views.GroupsPanel(db_session, category = 'General', name = 'Groups', endpoint = 'groups')) self.instructor.add_view(instructor_views.UserUsedExperimentPanel(db_session, category = 'General', name = 'Raw accesses', endpoint = 'logs')) self.instructor.add_view(instructor_views.GroupStats(db_session, category = 'Stats', name = 'Group', endpoint = 'stats/groups')) self.instructor.add_view(BackView(url = 'back', name = 'Back', endpoint = 'back/instructor')) self.instructor.init_app(self.app) ################################################ # # Other # self.bypass_authz = bypass_authz
def __init__(self, cfg_manager): super(DatabaseGateway, self).__init__() self.cfg_manager = cfg_manager self.Session, self.engine = db.initialize(cfg_manager)
def __init__(self, app, cfg_manager, core_server, bypass_authz = False): super(AdministrationApplication, self).__init__() app.json_encoder = CustomJSONEncoder self.cfg_manager = cfg_manager pub_directory = os.path.join(os.path.abspath(self.cfg_manager.get('deployment_dir', '')), 'pub') self.config = cfg_manager db.initialize(cfg_manager) self.core_server = core_server db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=db.engine)) files_directory = cfg_manager.get_doc_value(configuration_doc.CORE_STORE_STUDENTS_PROGRAMS_PATH) core_server_url = cfg_manager.get_value( 'core_server_url', '' ) self.script_name = urlparse.urlparse(core_server_url).path.split('/weblab')[0] or '' self.app = app static_folder = os.path.abspath(os.path.join(os.path.dirname(web.__file__), 'static')) # Not allowed @app.route('/weblab/not_allowed') def not_allowed(): return "You are logged in, but not allowed to see this content. Please log in with a proper account" # Back @app.route('/weblab/back') def back_to_client(): return redirect(url_for('core_webclient.labs')) ################################################ # # Administration panel for administrators # # admin_url = '/weblab/admin' category_system = lazy_gettext("System") category_users = lazy_gettext("Users") category_logs = lazy_gettext("Logs") category_experiments = lazy_gettext("Experiments") category_permissions = lazy_gettext("Permissions") self.admin = Admin(index_view = admin_views.HomeView(db_session, url = admin_url),name = lazy_gettext('WebLab-Deusto Admin'), url = admin_url, endpoint = admin_url, base_template = 'weblab-master.html', template_mode = 'bootstrap3') self.admin.weblab_admin_app = self self.admin.add_view(admin_views.SystemProperties(db_session, category = category_system, name = lazy_gettext('Settings'), endpoint = 'system/settings', url='settings')) self.admin.add_view(admin_views.AuthsPanel(db_session, category = category_system, name = lazy_gettext('Authentication'), endpoint = 'system/auth', url='auth')) if not os.path.exists(pub_directory): try: os.mkdir(pub_directory) except (IOError, OSError) as e: print("WARNING: %s not found. Create it to upload files to it." % pub_directory) if os.path.exists(pub_directory): self.admin.add_view(admin_views.AdministratorFileAdmin(pub_directory, category = category_system, name = lazy_gettext('Public directory'), endpoint = 'system/pub', url='pub')) self.admin.add_view(admin_views.UsersAddingView(db_session, category = category_users, name = lazy_gettext('Add multiple users'), endpoint = 'users/multiple')) self.admin.add_view(admin_views.UsersPanel(db_session, category = category_users, name = lazy_gettext('Users'), endpoint = 'users/users', url='users')) self.admin.add_view(admin_views.GroupsPanel(db_session, category = category_users, name = lazy_gettext('Groups'), endpoint = 'users/groups', url='groups')) self.admin.add_view(admin_views.UserUsedExperimentPanel(files_directory, db_session, category = category_logs, name = lazy_gettext('User logs'), endpoint = 'logs/users', url='logs')) self.admin.add_view(admin_views.ExperimentCategoryPanel(db_session, category = category_experiments, name = lazy_gettext('Categories'), endpoint = 'experiments/categories', url='experiments/categories')) self.admin.add_view(admin_views.ExperimentPanel(db_session, category = category_experiments, name = lazy_gettext('Experiments'), endpoint = 'experiments/experiments', url='experiments')) # TODO: Until finished, do not display # self.admin.add_view(admin_views.SchedulerPanel(db_session, category = category_experiments, name = lazy_gettext('Schedulers'), endpoint = 'experiments/schedulers')) self.admin.add_view(admin_views.PermissionsAddingView(db_session, category = category_permissions, name = lazy_gettext('Create'), endpoint = 'permissions/create', url='permissions')) self.admin.add_view(admin_views.UserPermissionPanel(db_session, category = category_permissions, name = lazy_gettext('User'), endpoint = 'permissions/user')) self.admin.add_view(admin_views.GroupPermissionPanel(db_session, category = category_permissions, name = lazy_gettext('Group'), endpoint = 'permissions/group')) self.admin.add_view(admin_views.RolePermissionPanel(db_session, category = category_permissions, name = lazy_gettext('Roles'), endpoint = 'permissions/role')) self.admin.add_link(MenuLink(endpoint='instructor.index', name = lazy_gettext('Instructor panel'), icon_type='glyph', icon_value='glyphicon-stats')) self.admin.add_link(MenuLink(endpoint='profile.index', name = lazy_gettext('My profile'), icon_type='glyph', icon_value='glyphicon-user')) self.admin.add_link(MenuLink(endpoint = 'back_to_client', name = lazy_gettext('Back'), icon_type='glyph', icon_value='glyphicon-log-out')) self.admin.init_app(self.app) self.full_admin_url = self.script_name + admin_url ################################################ # # Profile panel # profile_url = '/weblab/profile' self.profile = Admin(index_view = profile_views.ProfileHomeView(db_session, url = profile_url, endpoint = 'profile'),name = lazy_gettext('WebLab-Deusto profile'), url = profile_url, endpoint = profile_url, base_template = 'weblab-master.html', template_mode='bootstrap3') self.profile.weblab_admin_app = self self.profile.add_view(profile_views.ProfileEditView(db_session, name = lazy_gettext('Edit'), endpoint = 'edit')) self.profile.add_view(profile_views.MyAccessesPanel(files_directory, db_session, name = lazy_gettext('My accesses'), endpoint = 'accesses')) self.profile.add_link(MenuLink(endpoint = 'back_to_client', name = lazy_gettext('Back'), icon_type='glyph', icon_value='glyphicon-log-out')) self.profile.init_app(self.app) ################################################ # # Instructors panel # # TODO. There should be able a new M2M relation between instructors and groups. # # Instructor should be able to: # # a) Create new groups (of which they are in charge) # b) Make other instructors in charge of these groups # c) Add students (and only students) to the system; forcing a group # d) Edit users (only students; of those groups that the administrator is in charge of) # e) Assign permissions on these courses # f) Manage the permissions on these courses # g) See the logs of their own students # h) See a panel with analytics of each of these groups (this panel is common to the administrator, and has not been implemented) instructor_url = '/weblab/instructor' instructor_home = instructor_views.InstructorHomeView(db_session, url = instructor_url, endpoint = 'instructor') instructor_home.static_folder = static_folder self.instructor = Admin(index_view = instructor_home, name = lazy_gettext("Weblab-Deusto instructor"), url = instructor_url, endpoint = instructor_url, base_template = 'weblab-master.html', template_mode='bootstrap3') self.instructor.weblab_admin_app = self category_general = lazy_gettext("General") category_stats = lazy_gettext("Stats") self.instructor.add_view(instructor_views.UsersPanel(db_session, category = category_general, name = lazy_gettext('Users'), endpoint = 'users')) self.instructor.add_view(instructor_views.GroupsPanel(db_session, category = category_general, name = lazy_gettext('Groups'), endpoint = 'groups')) self.instructor.add_view(instructor_views.UserUsedExperimentPanel(db_session, category = category_general, name = lazy_gettext('Raw accesses'), endpoint = 'logs')) self.instructor.add_view(instructor_views.GroupStats(db_session, category = category_stats, name = lazy_gettext('Group'), endpoint = 'stats/groups')) self.instructor.add_link(MenuLink(endpoint='profile.index', name = lazy_gettext('My profile'), icon_type='glyph', icon_value='glyphicon-user')) self.instructor.add_link(MenuLink(endpoint = 'back_to_client', name = lazy_gettext('Back'), icon_type='glyph', icon_value='glyphicon-log-out')) self.instructor.init_app(self.app) ################################################ # # Other # self.bypass_authz = bypass_authz
def __init__(self, app, cfg_manager, core_server, bypass_authz = False): super(AdministrationApplication, self).__init__() app.json_encoder = CustomJSONEncoder self.cfg_manager = cfg_manager pub_directory = os.path.join(os.path.abspath(self.cfg_manager.get('deployment_dir', '')), 'pub') self.config = cfg_manager db.initialize(cfg_manager) self.core_server = core_server db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=db.engine)) files_directory = cfg_manager.get_doc_value(configuration_doc.CORE_STORE_STUDENTS_PROGRAMS_PATH) core_server_url = cfg_manager.get_value( 'core_server_url', '' ) self.script_name = urlparse.urlparse(core_server_url).path.split('/weblab')[0] or '' self.app = app static_folder = os.path.abspath(os.path.join(os.path.dirname(web.__file__), 'static')) # Not allowed @app.route('/weblab/not_allowed') def not_allowed(): return "You are logged in, but not allowed to see this content. Please log in with a proper account" # Back @app.route('/weblab/back') def back_to_client(): return redirect(url_for('core_webclient.labs')) ################################################ # # Administration panel for administrators # # admin_url = '/weblab/admin' category_system = lazy_gettext("System") category_users = lazy_gettext("Users") category_logs = lazy_gettext("Logs") category_experiments = lazy_gettext("Experiments") category_permissions = lazy_gettext("Permissions") self.admin = Admin(index_view = admin_views.HomeView(db_session, url = admin_url),name = lazy_gettext('WebLab-Deusto Admin'), url = admin_url, endpoint = admin_url, base_template = 'weblab-master.html', template_mode = 'bootstrap3') self.admin.weblab_admin_app = self self.admin.add_view(admin_views.SystemProperties(db_session, category = category_system, name = lazy_gettext('Settings'), endpoint = 'system/settings', url='settings')) self.admin.add_view(admin_views.AuthsPanel(db_session, category = category_system, name = lazy_gettext('Authentication'), endpoint = 'system/auth', url='auth')) if not os.path.exists(pub_directory): try: os.mkdir(pub_directory) except (IOError, OSError) as e: print("WARNING: %s not found. Create it to upload files to it." % pub_directory) if os.path.exists(pub_directory): self.admin.add_view(admin_views.AdministratorFileAdmin(pub_directory, category = category_system, name = lazy_gettext('Public directory'), endpoint = 'system/pub', url='pub')) self.admin.add_view(admin_views.UsersAddingView(db_session, category = category_users, name = lazy_gettext('Add multiple users'), endpoint = 'users/multiple')) self.admin.add_view(admin_views.UsersPanel(db_session, category = category_users, name = lazy_gettext('Users'), endpoint = 'users/users', url='users')) self.admin.add_view(admin_views.GroupsPanel(db_session, category = category_users, name = lazy_gettext('Groups'), endpoint = 'users/groups', url='groups')) self.admin.add_view(admin_views.InvitationsPanel(db_session, category = category_users, name = lazy_gettext('Invitations'), endpoint = 'users/invitations', url='invitations')) self.admin.add_view(admin_views.UserUsedExperimentPanel(files_directory, db_session, category = category_logs, name = lazy_gettext('User logs'), endpoint = 'logs/users', url='logs')) self.admin.add_view(admin_views.ExperimentCategoryPanel(db_session, category = category_experiments, name = lazy_gettext('Categories'), endpoint = 'experiments/categories', url='experiments/categories')) self.admin.add_view(admin_views.ExperimentPanel(db_session, category = category_experiments, name = lazy_gettext('Experiments'), endpoint = 'experiments/experiments', url='experiments')) # TODO: Until finished, do not display # self.admin.add_view(admin_views.SchedulerPanel(db_session, category = category_experiments, name = lazy_gettext('Schedulers'), endpoint = 'experiments/schedulers')) self.admin.add_view(admin_views.PermissionsAddingView(db_session, category = category_permissions, name = lazy_gettext('Create'), endpoint = 'permissions/create', url='permissions')) self.admin.add_view(admin_views.UserPermissionPanel(db_session, category = category_permissions, name = lazy_gettext('User'), endpoint = 'permissions/user')) self.admin.add_view(admin_views.GroupPermissionPanel(db_session, category = category_permissions, name = lazy_gettext('Group'), endpoint = 'permissions/group')) self.admin.add_view(admin_views.RolePermissionPanel(db_session, category = category_permissions, name = lazy_gettext('Roles'), endpoint = 'permissions/role')) self.admin.add_link(MenuLink(endpoint='instructor.index', name = lazy_gettext('Instructor panel'), icon_type='glyph', icon_value='glyphicon-stats')) self.admin.add_link(MenuLink(endpoint='profile.index', name = lazy_gettext('My profile'), icon_type='glyph', icon_value='glyphicon-user')) self.admin.add_link(MenuLink(endpoint = 'back_to_client', name = lazy_gettext('Back'), icon_type='glyph', icon_value='glyphicon-log-out')) self.admin.init_app(self.app) self.full_admin_url = self.script_name + admin_url ################################################ # # Profile panel # profile_url = '/weblab/profile' self.profile = Admin(index_view = profile_views.ProfileHomeView(db_session, url = profile_url, endpoint = 'profile'),name = lazy_gettext('WebLab-Deusto profile'), url = profile_url, endpoint = profile_url, base_template = 'weblab-master.html', template_mode='bootstrap3') self.profile.weblab_admin_app = self self.profile.add_view(profile_views.ProfileEditView(db_session, name = lazy_gettext('Edit'), endpoint = 'edit')) self.profile.add_view(profile_views.MyAccessesPanel(files_directory, db_session, name = lazy_gettext('My accesses'), endpoint = 'accesses')) self.profile.add_link(MenuLink(endpoint = 'back_to_client', name = lazy_gettext('Back'), icon_type='glyph', icon_value='glyphicon-log-out')) self.profile.init_app(self.app) ################################################ # # Instructors panel # # TODO. There should be able a new M2M relation between instructors and groups. # # Instructor should be able to: # # a) Create new groups (of which they are in charge) # b) Make other instructors in charge of these groups # c) Add students (and only students) to the system; forcing a group # d) Edit users (only students; of those groups that the administrator is in charge of) # e) Assign permissions on these courses # f) Manage the permissions on these courses # g) See the logs of their own students # h) See a panel with analytics of each of these groups (this panel is common to the administrator, and has not been implemented) instructor_url = '/weblab/instructor' instructor_home = instructor_views.InstructorHomeView(db_session, url = instructor_url, endpoint = 'instructor') instructor_home.static_folder = static_folder self.instructor = Admin(index_view = instructor_home, name = lazy_gettext("Weblab-Deusto instructor"), url = instructor_url, endpoint = instructor_url, base_template = 'weblab-master.html', template_mode='bootstrap3') self.instructor.weblab_admin_app = self category_general = lazy_gettext("General") category_stats = lazy_gettext("Stats") self.instructor.add_view(instructor_views.UsersPanel(db_session, category = category_general, name = lazy_gettext('Users'), endpoint = 'users')) self.instructor.add_view(instructor_views.GroupsPanel(db_session, category = category_general, name = lazy_gettext('Groups'), endpoint = 'groups')) self.instructor.add_view(instructor_views.UserUsedExperimentPanel(db_session, category = category_general, name = lazy_gettext('Raw accesses'), endpoint = 'logs')) self.instructor.add_view(instructor_views.GroupStats(db_session, category = category_stats, name = lazy_gettext('Group'), endpoint = 'stats/groups')) self.instructor.add_link(MenuLink(endpoint='profile.index', name = lazy_gettext('My profile'), icon_type='glyph', icon_value='glyphicon-user')) self.instructor.add_link(MenuLink(endpoint = 'back_to_client', name = lazy_gettext('Back'), icon_type='glyph', icon_value='glyphicon-log-out')) self.instructor.init_app(self.app) ################################################ # # Other # self.bypass_authz = bypass_authz