def get_display(my): web = WebContainer.get_web() context_url = web.get_context_url().to_string() js_url = "%s/javascript" % context_url spt_js_url = "%s/spt_js" % context_url # adding new core "spt" javascript library folder version = Environment.get_release_version() # add some third party libraries third_party = js_includes.third_party security = Environment.get_security() for include in js_includes.third_party: Container.append_seq("Page:js", "%s/%s" % (spt_js_url,include)) all_js_path = js_includes.get_compact_js_filepath() if os.path.exists( all_js_path ): Container.append_seq("Page:js", "%s/%s" % (context_url, js_includes.get_compact_js_context_path_suffix())) else: for include in js_includes.legacy_core: Container.append_seq("Page:js", "%s/%s" % (js_url,include)) for include in js_includes.spt_js: Container.append_seq("Page:js", "%s/%s" % (spt_js_url,include)) for include in js_includes.legacy_app: Container.append_seq("Page:js", "%s/%s" % (js_url,include)) # custom js files to include includes = Config.get_value("install", "include_js") includes = includes.split(",") for include in includes: include = include.strip() if include: print "include: ", include Container.append_seq("Page:js", include) widget = Widget() js_files = Container.get("Page:js") for js_file in js_files: widget.add('<script src="%s?ver=%s" ></script>\n' % (js_file,version) ) return widget
def get_display(my): web = WebContainer.get_web() context_url = web.get_context_url().to_string() js_url = "%s/javascript" % context_url spt_js_url = "%s/spt_js" % context_url # adding new core "spt" javascript library folder version = Environment.get_release_version() # add some third party libraries third_party = js_includes.third_party security = Environment.get_security() # FIXME: this logic should not be located here. # no reason to have the edit_area_full.js if not security.check_access("builtin", "view_script_editor", "allow") and security.check_access("builtin", "view_site_admin", "allow"): if "edit_area/edit_area_full.js" in third_party: third_party.remove("edit_area/edit_area_full.js") for include in js_includes.third_party: Container.append_seq("Page:js", "%s/%s" % (spt_js_url,include)) all_js_path = js_includes.get_compact_js_filepath() if os.path.exists( all_js_path ): Container.append_seq("Page:js", "%s/%s" % (context_url, js_includes.get_compact_js_context_path_suffix())) else: for include in js_includes.legacy_core: Container.append_seq("Page:js", "%s/%s" % (js_url,include)) for include in js_includes.spt_js: Container.append_seq("Page:js", "%s/%s" % (spt_js_url,include)) for include in js_includes.legacy_app: Container.append_seq("Page:js", "%s/%s" % (js_url,include)) #Container.append_seq("Page:js", "http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js") #Container.append_seq("Page:js", "/context/spt_js/UnityObject.js") #widget = DivWdg() #widget.set_id("javascript") #my.set_as_panel(widget) widget = Widget() js_files = Container.get("Page:js") for js_file in js_files: widget.add('<script src="%s?ver=%s" ></script>\n' % (js_file,version) ) return widget
def test_all(self): batch = Batch() Environment.get_security().set_admin(True) from pyasm.unittest import UnittestEnvironment, Sample3dEnvironment test_env = UnittestEnvironment() test_env.create() sample3d_env = Sample3dEnvironment(project_code='sample3d') sample3d_env.create() Project.set_project("unittest") try: self.access_manager = Environment.get_security( ).get_access_manager() self._test_all() finally: # Reset access manager for tear down Environment.get_security()._access_manager = self.access_manager Environment.get_security().reset_access_manager() self._tear_down() Environment.get_security().set_admin(True) test_env.delete() Environment.get_security().set_admin(True) sample3d_env.delete() Site.pop_site()
def test_all(self): batch = Batch() Environment.get_security().set_admin(True) from pyasm.unittest import UnittestEnvironment, Sample3dEnvironment test_env = UnittestEnvironment() test_env.create() sample3d_env = Sample3dEnvironment(project_code='sample3d') sample3d_env.create() Project.set_project("unittest") try: self.access_manager = Environment.get_security().get_access_manager() self._test_all() finally: # Reset access manager for tear down Environment.get_security()._access_manager = self.access_manager Environment.get_security().reset_access_manager() self._tear_down() Environment.get_security().set_admin(True) test_env.delete() Environment.get_security().set_admin(True) sample3d_env.delete() Site.pop_site()
def execute(self): if not self.login_name: self.login_name = self.kwargs.get('login'); # invalidate the ticket security = Environment.get_security() ticket = security.get_ticket() if ticket == None: return login_name = ticket.get_value("login") print "Signing out: ", login_name # expire the ticket from pyasm.security import Site site = Site.get() if site: Site.set_site("default") try: from pyasm.search import Sql, DbContainer sql = DbContainer.get("sthpw") ticket.set_value("expiry", sql.get_timestamp_now(), quoted=False) ticket.commit() except: if site: Site.pop_site()
def insert_data_check(server=None, input_data=None): department_request_sobject = input_data.get('sobject') if not department_request_sobject.get('name'): raise TacticException("Name field is required.") if not department_request_sobject.get('due_date'): raise TacticException("Due Date field is required.") if not department_request_sobject.get('description'): raise TacticException("Description field is required.") # If 'status' is not set, set it to 'in_progress' by default if not department_request_sobject.get('status'): status = 'in_progress' else: status = None # If 'login' is not in the inserted sobject, insert it using the logged in user's name if not department_request_sobject.get('login'): login = Environment.get_security().get_login().get_login() else: login = None # If either status or login was set, and update is needed if status or login: update_dictionary = {} if status: update_dictionary['status'] = status if login: update_dictionary['login'] = login # Send the update data server.update(department_request_sobject.get('__search_key__'), update_dictionary)
def get_file_menu(self): menu_items = [ { "type": "action", "label": "Export All...", "bvr_cb": { 'cbfn_action': "spt.dg_table_action.set_actionbar_aux_content", 'class_name': 'tactic.ui.widget.CsvExportWdg', 'args': {"table_id": "%s" %self.table_id, \ "is_export_all": "true"}}}, { "type": "action", "label": "Export Selected", "bvr_cb": { 'cbfn_action': "spt.dg_table_action.set_actionbar_aux_content", 'class_name': 'tactic.ui.widget.CsvExportWdg', 'args': {"table_id": "%s" %self.table_id}}}, { "type": "separator" }, { "type": "action", "label": "Sign Out", "bvr_cb": {'cbjs_action': "alert('File->Sign Out');"} } ] security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): menu_items.insert(0, { "type": "action", "label": "Import CSV", "bvr_cb": { 'cbfn_action': "spt.dg_table_action.set_actionbar_aux_content", 'class_name': 'tactic.ui.widget.CsvImportWdg', 'args': {"table_id": "%s" %self.table_id} }}) return {'menu_id': 'ActionBar_FileMenu_Main', 'width': 150, 'allow_icons': False, 'opt_spec_list': menu_items}
def _do_login(self): security = Environment.get_security() require_password = Config.get_value("security", "api_require_password") api_password = Config.get_value("security", "api_password") site = Site.get() allow_guest = site.allow_guest() # the xmlrpc login can be overridden to not require a password if require_password == "false" or (allow_guest and self.login_name == "guest"): security.login_user_without_password(self.login_name, expiry="NULL") elif api_password: if api_password == self.password: security.login_user_without_password(self.login_name, expiry="NULL") else: # if api password is incorrect, still try and authenticate with # user's password security.login_user(self.login_name, self.password, expiry="NULL") elif self.login_name == "guest": security.login_user_without_password(self.login_name) else: security.login_user(self.login_name, self.password, expiry="NULL") if not security.is_logged_in(): raise SecurityException("Cannot login as user: %s." % self.login_name)
def get_main_menu(my): opt_spec_list = [ {"type": "submenu", "label": "Edit", "submenu_tag_suffix": "EDIT"}, {"type": "submenu", "label": "File", "submenu_tag_suffix": "FILE"}, {"type": "submenu", "label": "Clipboard", "submenu_tag_suffix": "CLIPBOARD"}, {"type": "submenu", "label": "View", "submenu_tag_suffix": "VIEW"}, {"type": "submenu", "label": "Print", "submenu_tag_suffix": "PRINT"}, {"type": "submenu", "label": "Chart", "submenu_tag_suffix": "CHART"}, ] security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): is_admin = True else: is_admin = False if not my.layout or my.layout.can_add_columns(): opt_spec_list.extend( [ {"type": "separator"}, {"type": "submenu", "label": "Tasks", "submenu_tag_suffix": "TASK"}, {"type": "submenu", "label": "Notes", "submenu_tag_suffix": "NOTE"}, {"type": "submenu", "label": "Check-ins", "submenu_tag_suffix": "CHECKIN"}, ] ) if is_admin: opt_spec_list.append({"type": "submenu", "label": "Pipelines", "submenu_tag_suffix": "PIPELINE"}) if my.custom_tools: opt_spec_list.append({"type": "submenu", "label": "Custom Tools", "submenu_tag_suffix": "CUSTOM"}) menu = {"menu_tag_suffix": "MAIN", "width": 130, "opt_spec_list": opt_spec_list} return menu
def set_project(cls, project_code): '''This is kept here because everybody is used to using this''' security = Environment.get_security() # FIXME: # Because it is possible to call this before one is # logged in. This is required to see the login screen. from pyasm.security import get_security_version security_version = get_security_version() if security_version != 1 and not project_code == 'admin': key = {'code': project_code} key2 = {'code': "*"} keys = [key, key2] if not security.check_access( "project", keys, access="allow", default="deny"): user = Environment.get_login() if user: user = user.get_value("login") raise SecurityException( "User [%s] is not permitted to view project [%s]" % (user, project_code)) else: raise SecurityException( "Not permitted to view project [%s]" % (project_code)) from pyasm.security import Site site = Site.get_site() PROJECT_KEY = "Project:global:%s:" % site Container.put(PROJECT_KEY, project_code)
def get_main_menu(my): security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): return { "menu_tag_suffix": "MAIN", "width": 110, "opt_spec_list": [ {"type": "submenu", "label": "Add", "submenu_tag_suffix": "ADD"}, {"type": "submenu", "label": "Edit", "submenu_tag_suffix": "EDIT"}, {"type": "submenu", "label": "Tools", "submenu_tag_suffix": "TOOLS"}, {"type": "submenu", "label": "Help", "submenu_tag_suffix": "HELP"}, ], } else: return { "menu_tag_suffix": "MAIN", "width": 110, "opt_spec_list": [ {"type": "submenu", "label": "Edit", "submenu_tag_suffix": "EDIT"}, {"type": "submenu", "label": "Help", "submenu_tag_suffix": "HELP"}, ], }
def _test_access_level(my): security = Environment.get_security() from pyasm.security import get_security_version security_version = get_security_version() projects = Search.eval('@SOBJECT(sthpw/project)') if security_version >= 2: for project in projects: key = { "code": project.get_code() } key2 = { "code": "*" } keys = [key, key2] default = "deny" # other than sample3d, unittest as allowed above, a default low access level user # should not see other projects access = security.check_access("project", keys, "allow", default=default) process_keys = [{'process': 'anim'}] proc_access = security.check_access("process", process_keys, "allow") my.assertEquals(proc_access, True) if project.get_code() in ['sample3d','unittest']: my.assertEquals(access, True) else: my.assertEquals(access, False) else: raise SecurityException('Please test with security version 2. Set it in your config file')
def execute(self): web = self.get_web() keys = web.get_form_keys() file_name = self.kwargs.get("file_name") # process and get the uploaded files dir = Environment.get_upload_dir() license_file = "%s/%s" % (dir, file_name) if not os.path.exists(license_file): raise TacticException("Error retrieving the license file in [%s]"%license_file) std_name = 'tactic-license.xml' head, file_name = os.path.split(license_file) # no restrictions for license file #if file_name != std_name: # raise TacticException("License file name should be named tactic-license.xml. The file given is [%s]" %file_name) license_dir = Environment.get_license_dir() current_license = "%s/%s" %(license_dir, std_name) if os.path.exists(current_license): FileUndo.remove(current_license) FileUndo.move(license_file, current_license) self.add_description('Renewed license file') security = Environment.get_security() security.reread_license()
def get_file_menu(my): menu_items = [ { "type": "action", "label": "Export All...", "bvr_cb": { 'cbfn_action': "spt.dg_table_action.set_actionbar_aux_content", 'class_name': 'tactic.ui.widget.CsvExportWdg', 'args': {"table_id": "%s" %my.table_id, \ "is_export_all": "true"}}}, { "type": "action", "label": "Export Selected", "bvr_cb": { 'cbfn_action': "spt.dg_table_action.set_actionbar_aux_content", 'class_name': 'tactic.ui.widget.CsvExportWdg', 'args': {"table_id": "%s" %my.table_id}}}, { "type": "separator" }, { "type": "action", "label": "Sign Out", "bvr_cb": {'cbjs_action': "alert('File->Sign Out');"} } ] security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): menu_items.insert(0, { "type": "action", "label": "Import CSV", "bvr_cb": { 'cbfn_action': "spt.dg_table_action.set_actionbar_aux_content", 'class_name': 'tactic.ui.widget.CsvImportWdg', 'args': {"table_id": "%s" %my.table_id} }}) return {'menu_id': 'ActionBar_FileMenu_Main', 'width': 150, 'allow_icons': False, 'opt_spec_list': menu_items}
def get_render_dir(my): ticket = Environment.get_security().get_ticket_key() tmpdir = Environment.get_tmp_dir() render_dir = "%s/temp/%s" % (tmpdir, ticket) System().makedirs(render_dir) return render_dir
def get_license_info_wdg(self): div = DivWdg() license = Environment.get_security().get_license() if self.first_error: return div #if not license.is_licensed(): # return div msg = DivWdg() div.add(msg) msg.add("The following describes the details of the installed license:<br/><br/>") info_wdg = DivWdg() div.add(info_wdg) info_wdg.add_style("margin: 10px 30px") info_wdg.add_style("font-size: 12px") version = license.get_data("tactic_version") if version: info_wdg.add("TACTIC Version: ") if version == "ALL": version = "ALL (Open Source)" info_wdg.add(version) info_wdg.add(HtmlElement.br(2)) company = license.get_data("company") info_wdg.add("Licensed To: ") if company.find("Southpaw EPL") != -1: company = SpanWdg("<a name='license'>Eclipse Public License v1.0</a> ") icon = IconWdg("EPL v1.0", IconWdg.ZOOM) company.add(icon) company.add_class("hand") company.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.help.load_alias("license") ''' } ) info_wdg.add(company) info_wdg.add(HtmlElement.br(2)) info_wdg.add("Max Users: ") info_wdg.add(license.get_data("max_users") ) info_wdg.add(HtmlElement.br(2)) info_wdg.add("Current Users: ") info_wdg.add(license.get_current_users() ) info_wdg.add(HtmlElement.br(2)) info_wdg.add("Expiry Date: ") expiry_date = license.get_data("expiry_date") if not expiry_date: expiry_date = "Permanent" info_wdg.add(expiry_date) info_wdg.add(HtmlElement.br(2)) return div
def _get_base_job(my): cpus = 1 job_type = my.render_package.get_option("job_type") # generic qube parameters job = { 'name': job_type, 'prototype': job_type, 'cpus': cpus, 'priority': my.queue.get_value("priority"), } # create an agenda based on the frames ... frame_range = my.render_package.get_frame_range() start, end, by = frame_range.get_values() frames = qb.genframes("%s-%s" % (start, end) ) if frames: job['agenda'] = frames # create a default package package = {} job['package'] = package # store the ticket in the job # FIXME: the problem with this is that the ticket may expire before # the job actually gets executed ticket = Environment.get_security().get_ticket_key() package['ticket'] = ticket return job
def _do_login(my): security = Environment.get_security() require_password = Config.get_value("security", "api_require_password") api_password = Config.get_value("security", "api_password") # the xmlrpc login can be overridden to not require a password if require_password == "false": security.login_user_without_password(my.login_name, expiry="NULL") elif api_password: if api_password == my.password: security.login_user_without_password(my.login_name, expiry="NULL") else: # if api password is incorrect, still try and authenticate with # user's password security.login_user(my.login_name, my.password, expiry="NULL") else: security.login_user(my.login_name, my.password, expiry="NULL") if not security.is_logged_in(): raise SecurityException("Cannot login as user: %s." % my.login_name)
def get_tools_menu(my): menu_items = [ #{ "type": "action", "label": "Search Types Manager", # "bvr_cb": {'cbjs_action': "spt.panel.load('main_body','tactic.ui.panel.SearchTypeManagerWdg')"} }, #{ "type": "separator" }, { "type": "action", "label": "Web Client Output Log", "bvr_cb": {'cbjs_action': "spt.js_log.show(false);"} }, { "type": "action", "label": "TACTIC Script Editor", "bvr_cb": {'cbjs_action': 'spt.panel.load_popup("TACTIC Script Editor",\ "tactic.ui.app.ShelfEditWdg", {}, {"load_once": true} );'} } ] security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): menu_items.insert(0, {"type": "action", "label": "Create New Project", "bvr_cb": { 'cbjs_action': "spt.popup.open('create_project_wizard'); Effects.fade_in($('create_project_wizard'), 200);"}}) menu_items.insert(1, { "type": "separator" }) return { 'menu_id': 'ActionBar_ToolsMenu_Main', 'width': 140, 'allow_icons': False, 'opt_spec_list': menu_items }
def _get_base_job(my): cpus = 1 job_type = my.render_package.get_option("job_type") # generic qube parameters job = { 'name': job_type, 'prototype': job_type, 'cpus': cpus, 'priority': my.queue.get_value("priority"), } # create an agenda based on the frames ... frame_range = my.render_package.get_frame_range() start, end, by = frame_range.get_values() frames = qb.genframes("%s-%s" % (start, end)) if frames: job['agenda'] = frames # create a default package package = {} job['package'] = package # store the ticket in the job # FIXME: the problem with this is that the ticket may expire before # the job actually gets executed ticket = Environment.get_security().get_ticket_key() package['ticket'] = ticket return job
def execute(my): web = my.get_web() keys = web.get_form_keys() file_name = my.kwargs.get("file_name") # process and get the uploaded files dir = Environment.get_upload_dir() license_file = "%s/%s" % (dir, file_name) if not os.path.exists(license_file): raise TacticException("Error retrieving the license file in [%s]" % license_file) std_name = 'tactic-license.xml' head, file_name = os.path.split(license_file) # no restrictions for license file #if file_name != std_name: # raise TacticException("License file name should be named tactic-license.xml. The file given is [%s]" %file_name) license_dir = Environment.get_license_dir() current_license = "%s/%s" % (license_dir, std_name) if os.path.exists(current_license): FileUndo.remove(current_license) FileUndo.move(license_file, current_license) my.add_description('Renewed license file') security = Environment.get_security() security.reread_license()
def set_project(cls, project_code): '''This is kept here because everybody is used to using this''' security = Environment.get_security() # FIXME: # Because it is possible to call this before one is # logged in. This is required to see the login screen. from pyasm.security import get_security_version security_version = get_security_version() if security_version != 1 and not project_code == 'admin': key = { 'code': project_code } key2 = { 'code': "*" } keys = [key, key2] if not security.check_access("project", keys, access="allow", default="deny"): user = Environment.get_login() if user: user = user.get_value("login") raise SecurityException("User [%s] is not permitted to view project [%s]" % (user, project_code)) else: raise SecurityException("User is not permitted to view project [%s]" % (project_code)) from pyasm.security import Site site = Site.get_site() PROJECT_KEY = "Project:global:%s:" % site Container.put(PROJECT_KEY, project_code)
def get_tools_menu(self): menu_items = [ #{ "type": "action", "label": "Search Types Manager", # "bvr_cb": {'cbjs_action': "spt.panel.load('main_body','tactic.ui.panel.SearchTypeManagerWdg')"} }, #{ "type": "separator" }, { "type": "action", "label": "Web Client Output Log", "bvr_cb": {'cbjs_action': "spt.js_log.show(false);"} }, { "type": "action", "label": "TACTIC Script Editor", "bvr_cb": {'cbjs_action': 'spt.panel.load_popup("TACTIC Script Editor",\ "tactic.ui.app.ShelfEditWdg", {}, {"load_once": true} );'} } ] security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): menu_items.insert(0, {"type": "action", "label": "Create New Project", "bvr_cb": { 'cbjs_action': "spt.popup.open('create_project_wizard'); Effects.fade_in($('create_project_wizard'), 200);"}}) menu_items.insert(1, { "type": "separator" }) return { 'menu_id': 'ActionBar_ToolsMenu_Main', 'width': 140, 'allow_icons': False, 'opt_spec_list': menu_items }
def get_display(my): security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): menus = [my.get_main_menu(), my.get_add_menu(), my.get_edit_menu(), my.get_tools_menu(), my.get_help_menu()] else: menus = [my.get_main_menu(), my.get_edit_menu(), my.get_help_menu()] """ btn_dd = DivWdg() btn_dd.add_styles("width: 36px; height: 18px; padding: none; padding-top: 1px;") btn_dd.add( "<img src='/context/icons/common/transparent_pixel.gif' alt='' " \ # "title='TACTIC Actions Menu' class='tactic_tip' " \ "style='text-decoration: none; padding: none; margin: none; width: 4px;' />" ) btn_dd.add( "<img src='/context/icons/silk/cog.png' alt='' " \ "title='TACTIC Actions Menu' class='tactic_tip' " \ "style='text-decoration: none; padding: none; margin: none;' />" ) btn_dd.add( "<img src='/context/icons/silk/bullet_arrow_down.png' alt='' " \ "title='TACTIC Actions Menu' class='tactic_tip' " \ "style='text-decoration: none; padding: none; margin: none;' />" ) """ from tactic.ui.widget import SingleButtonWdg btn_dd = SingleButtonWdg(title="Global Options", icon=IconWdg.GEAR, show_arrow=True) # btn_dd.add_behavior( { 'type': 'hover', # 'mod_styles': 'background-image: url(/context/icons/common/gear_menu_btn_bkg_hilite.png); ' \ # 'background-repeat: no-repeat;' } ) smenu_set = SmartMenu.add_smart_menu_set(btn_dd, {"DG_TABLE_GEAR_MENU": menus}) SmartMenu.assign_as_local_activator(btn_dd, "DG_TABLE_GEAR_MENU", True) return btn_dd
def set_admin(self, flag, sudo=False): self.set_up() security = Environment.get_security() if security.get_user_name() == "admin": self.is_admin_flag = True return self.is_admin_flag = flag """ if flag == False: import traceback, sys # print the stacktrace tb = sys.exc_info()[2] stacktrace = traceback.format_tb(tb) stacktrace_str = "".join(stacktrace) print "-"*50 print "TRACE: ", self.was_admin print stacktrace_str print "-"*50 """ if not self.was_admin and flag: if 'admin' not in security.get_group_names(): security._group_names.append('admin') elif 'admin' in security.get_group_names(): if not self.was_admin: security._group_names.remove('admin')
def get_license_info_wdg(my): div = DivWdg() license = Environment.get_security().get_license() if my.first_error: return div #if not license.is_licensed(): # return div msg = DivWdg() div.add(msg) msg.add("The following describes the details of the installed license:<br/><br/>") info_wdg = DivWdg() div.add(info_wdg) info_wdg.add_style("margin: 10px 30px") info_wdg.add_style("font-size: 12px") version = license.get_data("tactic_version") if version: info_wdg.add("TACTIC Version: ") if version == "ALL": version = "ALL (Open Source)" info_wdg.add(version) info_wdg.add(HtmlElement.br(2)) company = license.get_data("company") info_wdg.add("Licensed To: ") if company.find("Southpaw EPL") != -1: company = SpanWdg("<a name='license'>Eclipse Public License v1.0</a> ") icon = IconWdg("EPL v1.0", IconWdg.ZOOM) company.add(icon) company.add_class("hand") company.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.help.load_alias("license") ''' } ) info_wdg.add(company) info_wdg.add(HtmlElement.br(2)) info_wdg.add("Max Users: ") info_wdg.add(license.get_data("max_users") ) info_wdg.add(HtmlElement.br(2)) info_wdg.add("Current Users: ") info_wdg.add(license.get_current_users() ) info_wdg.add(HtmlElement.br(2)) info_wdg.add("Expiry Date: ") expiry_date = license.get_data("expiry_date") if not expiry_date: expiry_date = "Permanent" info_wdg.add(expiry_date) info_wdg.add(HtmlElement.br(2)) return div
def _do_login(my): security = Environment.get_security() ticket = security.login_with_ticket(my.ticket) if not ticket: raise SecurityException("Cannot login with key: %s. Session may have expired." % my.ticket)
def init(self): self.search_type = "config/custom_script" security = Environment.get_security() if not security.check_access("builtin", "view_script_editor", "allow"): raise SecurityException( 'You are not allowed to access this widget.')
def get_link_wdg(self, element_name, config, options): attributes = config.get_element_attributes(element_name) title = self._get_title(config, element_name) default_access = "view" path = options.get('path') security = Environment.get_security() if not security.check_access( "side_bar", element_name, "view", default=default_access): return # backwards compatibility?? #if not security.check_access("url", path, "view"): # return link_wdg = DivWdg(css="hand") link_wdg.add_style("padding-top: 4px") link_wdg.add_attr("spt_title", title) link_wdg.add_attr("spt_icon", attributes.get("icon")) link_wdg.add_class("spt_side_bar_link") link_wdg.add_attr("spt_view", config.get_view()) link_wdg.add_attr("spt_element_name", element_name) link_wdg.add_attr("spt_path", options['path']) # add the mouseover color change link_wdg.add_style("color: #292929") link_wdg.add_class("SPT_DTS") hover = link_wdg.get_color("background3", -10) link_wdg.add_event("onmouseover", "this.style.background='%s'" % hover) link_wdg.add_event("onmouseout", "this.style.background=''") link_wdg.add_class("spt_side_bar_element") link_wdg.add_looks("fnt_text") link_wdg.add_attr("spt_view", config.get_view()) # add an invisible drop widget drop_wdg = self.get_drop_wdg() drop_wdg.add_style("margin-top: -3px") link_wdg.add(drop_wdg) span = SpanWdg() span.add_class("spt_side_bar_title") # add an icon icon = attributes.get("icon") if icon: icon = icon.upper() from pyasm.widget import IconWdg try: span.add(IconWdg(title, eval("IconWdg.%s" % icon))) except: pass span.add(title) link_wdg.add(span) return link_wdg
def alter_search(self, search): # get all of the relevant tasks to the user task_search = Search("sthpw/task") task_search.add_column("search_id") # only look at this project project = Project.get_project_name() task_search.add_filter("search_type", search.get_search_type()) # figure out who the user is security = Environment.get_security() login = security.get_login() user = login.get_value("login") print "is_artist: ", self.is_artist() print "is_supervisor: ", self.is_supervisor() # do some filtering web = WebContainer.get_web() show_assigned_only = self.checkbox.get_value() show_process = web.get_form_values("process") if not show_process or show_process[0] == '': show_process = [] show_task_status = web.get_form_values("task_status") if not show_task_status or show_task_status[0] == '': show_task_status = [] if show_assigned_only == "on": task_search.add_filter("assigned", user) if show_process: where = "process in (%s)" % ", ".join( ["'%s'" % x for x in show_process] ) task_search.add_where(where) if show_task_status: where = "status in (%s)" % ", ".join( ["'%s'" % x for x in show_task_status] ) task_search.add_where(where) else: task_search.add_where("NULL") # record the tasks self.tasks = task_search.get_sobjects() # get all of the sobject ids sobject_ids = ["'%s'" % x.get_value("search_id") for x in self.tasks] # get all of the sobjects related to this task if sobject_ids: search.add_where( "id in (%s)" % ", ".join(sobject_ids) )
def get_display(my): widget = Widget() span = SpanWdg('[ projects ]', css='hand') span.add_style('color','white') span.add_event('onclick',"spt.show_block('%s')" %my.WDG_ID) widget.add(span) # add the popup div = DivWdg(id=my.WDG_ID, css='popup_wdg') widget.add(div) div.add_style('width', '80px') div.add_style('display', 'none') title_div = DivWdg() div.add(title_div) title = FloatDivWdg(' ', width='60px') title.add_style('margin-right','2px') title_div.add_style('padding-bottom', '4px') title_div.add(title) title_div.add(CloseWdg(my.get_off_script(), is_absolute=False)) div.add(HtmlElement.br()) search = Search(Project) search.add_where("\"code\" not in ('sthpw','admin')") search.add_column('code') projects = search.get_sobjects() values = SObject.get_values(projects, 'code') web = WebContainer.get_web() root = web.get_site_root() security = Environment.get_security() for value in values: if not security.check_access("project", value, "view"): continue script = "location.href='/%s/%s'"%(root, value) sub_div = DivWdg(HtmlElement.b(value), css='selection_item') sub_div.add_event('onclick', script) div.add(sub_div) div.add(HtmlElement.hr()) if security.check_access("project", 'default', "view"): script = "location.href='/%s'" % root sub_div = DivWdg('home', css='selection_item') sub_div.add_event('onclick', script) div.add(sub_div) if security.check_access("project", "admin", "view"): script = "location.href='/%s/admin/'" %root sub_div = DivWdg('admin', css='selection_item') sub_div.add_event('onclick', script) div.add(sub_div) return widget
def alter_search(my, search): # get all of the relevant tasks to the user task_search = Search("sthpw/task") task_search.add_column("search_id") # only look at this project project = Project.get_project_name() task_search.add_filter("search_type", search.get_search_type()) # figure out who the user is security = Environment.get_security() login = security.get_login() user = login.get_value("login") print "is_artist: ", my.is_artist() print "is_supervisor: ", my.is_supervisor() # do some filtering web = WebContainer.get_web() show_assigned_only = my.checkbox.get_value() show_process = web.get_form_values("process") if not show_process or show_process[0] == '': show_process = [] show_task_status = web.get_form_values("task_status") if not show_task_status or show_task_status[0] == '': show_task_status = [] if show_assigned_only == "on": task_search.add_filter("assigned", user) if show_process: where = "process in (%s)" % ", ".join( ["'%s'" % x for x in show_process] ) task_search.add_where(where) if show_task_status: where = "status in (%s)" % ", ".join( ["'%s'" % x for x in show_task_status] ) task_search.add_where(where) else: task_search.add_where("NULL") # record the tasks my.tasks = task_search.get_sobjects() # get all of the sobject ids sobject_ids = ["'%s'" % x.get_value("search_id") for x in my.tasks] # get all of the sobjects related to this task if sobject_ids: search.add_where( "id in (%s)" % ", ".join(sobject_ids) )
def __init__(my, **kwargs): my.kwargs = kwargs user = my.kwargs.get('user') project = my.kwargs.get('project') if user and project: from pyasm.security import Batch Batch(login_code=user, project_code=project) my.security = Environment.get_security()
def set_up(self): if self.was_admin == None: security = Environment.get_security() if security._login and not security._is_logged_in: security._groups = [] security._group_names = [] security._find_all_login_groups() self.was_admin = security.is_in_group('admin')
def _do_login(my): security = Environment.get_security() ticket = security.login_with_ticket(my.ticket) if not ticket: raise SecurityException( "Cannot login with key: %s. Session may have expired." % my.ticket)
def test_all(self): Batch(project_code='unittest') self.security = Environment.get_security() self._test_succeed() self._test_fail() self._test_autocreate() self._test_cache()
def test_all(my): Batch(project_code='unittest') my.security = Environment.get_security() my._test_succeed() my._test_fail() my._test_autocreate() my._test_cache()
def get_edit_menu(my): opt_spec_list = [] security = Environment.get_security() project_code = Project.get_project_code() access_keys = my._get_access_keys("retire_delete", project_code) if security.check_access("builtin", access_keys, "allow"): if not my.layout or my.layout.can_select(): opt_spec_list.extend( [ { "type": "action", "label": "Retire Selected Items", "bvr_cb": {"cbjs_action": "spt.dg_table.gear_smenu_retire_selected_cbk(evt,bvr);"}, }, { "type": "action", "label": "Delete Selected Items", "bvr_cb": { "cbjs_action": """ spt.dg_table.gear_smenu_delete_selected_cbk(evt,bvr); """ }, }, {"type": "separator"}, ] ) opt_spec_list.extend( [ { "type": "action", "label": "Show Server Transaction Log", "bvr_cb": { "cbjs_action": "spt.popup.get_widget(evt, bvr)", "options": { "class_name": "tactic.ui.popups.TransactionPopupWdg", "title": "Transaction Log", "popup_id": "TransactionLog_popup", }, }, } ] ) # MTM TURNED OFF TO PREVENT AUTO-UNDOING # # { "type": "separator" }, # # { "type": "action", "label": "Undo Last Server Transaction", # "bvr_cb": {'cbjs_action': "spt.undo_cbk(evt, bvr);"} # }, # # { "type": "action", "label": "Redo Last Server Transaction", # "bvr_cb": {'cbjs_action': "spt.redo_cbk(evt, bvr);"} # }, return {"menu_tag_suffix": "EDIT", "width": 200, "opt_spec_list": opt_spec_list}
def filter_sobjects(my, orig_sobjects): # look for groups that are relevant groups = Environment.get_security().get_groups() login = Environment.get_security().get_login() # either we are user centric or process centric user = login.get_value("login") sobjects = [] # filter out sobjects that do not have appropriate tasks if orig_sobjects: search_type = orig_sobjects[0].get_search_type() ids = [str(x.get_id()) for x in orig_sobjects] search = Search("sthpw/task") search.add_filter("search_type", search_type) search.add_where("search_id in (%s)" % ",".join(ids) ) # get only tasks assigned to a user show_assigned_only = True if show_assigned_only: search.add_filter("assigned", user) search.add_where("status in ('Pending','In Progress')") search.add_where("status is NULL") tasks = search.get_sobjects() task_search_ids = [int(x.get_value("search_id")) for x in tasks] # once we have all of the tasks for this episode, we filter # out any assets that don't have these tasks for orig_sobject in orig_sobjects: search_id = orig_sobject.get_id() if search_id in task_search_ids: sobjects.append(orig_sobject) return sobjects
def filter_sobjects(self, orig_sobjects): # look for groups that are relevant groups = Environment.get_security().get_groups() login = Environment.get_security().get_login() # either we are user centric or process centric user = login.get_value("login") sobjects = [] # filter out sobjects that do not have appropriate tasks if orig_sobjects: search_type = orig_sobjects[0].get_search_type() ids = [str(x.get_id()) for x in orig_sobjects] search = Search("sthpw/task") search.add_filter("search_type", search_type) search.add_where("search_id in (%s)" % ",".join(ids) ) # get only tasks assigned to a user show_assigned_only = True if show_assigned_only: search.add_filter("assigned", user) search.add_where("status in ('Pending','In Progress')") search.add_where("status is NULL") tasks = search.get_sobjects() task_search_ids = [int(x.get_value("search_id")) for x in tasks] # once we have all of the tasks for this episode, we filter # out any assets that don't have these tasks for orig_sobject in orig_sobjects: search_id = orig_sobject.get_id() if search_id in task_search_ids: sobjects.append(orig_sobject) return sobjects
def __init__(my): #print "Setting admin" my.security = Environment.get_security() # if not already logged in, login as a safe user (guest) if not my.security.is_logged_in(): #my.security.login_as_guest() pass my.access_manager = my.security.get_access_manager() my.access_manager.set_admin(True)
def set_admin(my, flag, sudo=False): my.set_up() my.is_admin_flag = flag security = Environment.get_security() if not my.was_admin and flag: if 'admin' not in security.get_group_names(): security._group_names.append('admin') elif 'admin' in security.get_group_names(): if not my.was_admin: security._group_names.remove('admin')
def get_display(self): widget = Widget() span = SpanWdg('[ projects ]', css='hand') span.add_style('color', 'white') span.add_event('onclick', "spt.show_block('%s')" % self.WDG_ID) widget.add(span) # add the popup div = DivWdg(id=self.WDG_ID, css='popup_wdg') widget.add(div) div.add_style('width', '80px') div.add_style('display', 'none') title_div = DivWdg() div.add(title_div) title = FloatDivWdg(' ', width='60px') title.add_style('margin-right', '2px') title_div.add_style('padding-bottom', '4px') title_div.add(title) title_div.add(CloseWdg(self.get_off_script(), is_absolute=False)) div.add(HtmlElement.br()) search = Search(Project) search.add_where("\"code\" not in ('sthpw','admin')") search.add_column('code') projects = search.get_sobjects() values = SObject.get_values(projects, 'code') web = WebContainer.get_web() root = web.get_site_root() security = Environment.get_security() for value in values: if not security.check_access("project", value, "view"): continue script = "location.href='/%s/%s'" % (root, value) sub_div = DivWdg(HtmlElement.b(value), css='selection_item') sub_div.add_event('onclick', script) div.add(sub_div) div.add(HtmlElement.hr()) if security.check_access("project", 'default', "view"): script = "location.href='/%s'" % root sub_div = DivWdg('home', css='selection_item') sub_div.add_event('onclick', script) div.add(sub_div) if security.check_access("project", "admin", "view"): script = "location.href='/%s/admin/'" % root sub_div = DivWdg('admin', css='selection_item') sub_div.add_event('onclick', script) div.add(sub_div) return widget
def get_main_menu(my): security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): return { 'menu_tag_suffix': 'MAIN', 'width': 110, 'opt_spec_list': [ { "type": "submenu", "label": "Add", "submenu_tag_suffix": "ADD" }, { "type": "submenu", "label": "Edit", "submenu_tag_suffix": "EDIT" }, { "type": "submenu", "label": "Tools", "submenu_tag_suffix": "TOOLS" }, { "type": "submenu", "label": "Help", "submenu_tag_suffix": "HELP" }, ] } else: return { 'menu_tag_suffix': 'MAIN', 'width': 110, 'opt_spec_list': [ { "type": "submenu", "label": "Edit", "submenu_tag_suffix": "EDIT" }, { "type": "submenu", "label": "Help", "submenu_tag_suffix": "HELP" }, ] }
def test_all(my): batch = Batch() from pyasm.unittest import UnittestEnvironment, Sample3dEnvironment test_env = UnittestEnvironment() test_env.create() sample3d_env = Sample3dEnvironment(project_code='sample3d') sample3d_env.create() Project.set_project("unittest") try: my.access_manager = Environment.get_security().get_access_manager() my._test_all() finally: #Project.set_project("unittest") Environment.get_security()._access_manager = my.access_manager my._tear_down() test_env.delete() sample3d_env.delete()
def get_edit_menu(my): opt_spec_list = [] security = Environment.get_security() project_code = Project.get_project_code() access_keys = my._get_access_keys("retire_delete", project_code) if security.check_access("builtin", access_keys, "allow"): if not my.layout or my.layout.can_select(): opt_spec_list.extend([ { "type": "action", "label": "Retire Selected Items", "bvr_cb": {'cbjs_action': "spt.dg_table.gear_smenu_retire_selected_cbk(evt,bvr);"} }, { "type": "action", "label": "Delete Selected Items", "bvr_cb": {'cbjs_action': ''' spt.dg_table.gear_smenu_delete_selected_cbk(evt,bvr); '''} }, {"type": "separator"} ]) opt_spec_list.extend([ { "type": "action", "label": "Show Server Transaction Log", "bvr_cb": { 'cbjs_action': "spt.popup.get_widget(evt, bvr)", 'options': { 'class_name': 'tactic.ui.popups.TransactionPopupWdg', 'title': 'Transaction Log', 'popup_id': 'TransactionLog_popup' } } }, { "type": "separator" }, { "type": "action", "label": "Undo Last Server Transaction", "bvr_cb": {'cbjs_action': "spt.undo_cbk(evt, bvr);"} }, { "type": "action", "label": "Redo Last Server Transaction", "bvr_cb": {'cbjs_action': "spt.redo_cbk(evt, bvr);"} }, ]) return { 'menu_tag_suffix': 'EDIT', 'width': 200, 'opt_spec_list': opt_spec_list}
def get_display(my): top_div = DivWdg() top_div.add_styles("text-align: center") top_div.add_style("margin-top: 10px") top_div.add_style("opacity: 0.5") top_div.add_style("font-size: 10px") tactic_span = SpanWdg() tactic_span.add("TACTIC®") rel_span = SpanWdg() rel_span.add(" Release %s" % Environment.get_release_version()) top_div.add(tactic_span) top_div.add(rel_span) top_div.add( " © 2005-2015, Southpaw Technology Inc. All Rights Reserved. " ) show_license_info = my.kwargs.get("show_license_info") if show_license_info: security = Environment.get_security() if security: license = Environment.get_security().get_license() company = license.get_data("company") if company.startswith('ALL'): lic_type = '' tmps = company.split('-') if tmps: lic_type = tmps[-1] lic_type = lic_type.strip() license_text = "Open Source License - %s" % lic_type else: license_text = "Licensed to %s" % company else: license_text = "No License" top_div.add(license_text) top_div.add("<br/>" * 2) return top_div
def _test_sobject_access_manager(my): '''test a more realistic example''' # create a test person person = Person.create("Donald", "Duck", "DisneyLand", "A duck!!!") my.person = person for project_code in ['unittest','unittest','sample3d']: task = SearchType.create('sthpw/task') task.set_sobject_value(person) task.set_value('assigned', 'unittest_guy') task.set_value('project_code', project_code) task.set_value('description', 'do something good') task.set_value('process', 'unittest') task.set_value('context', 'unittest') task.commit() # an extra task for list-based search_filter test task = SearchType.create('sthpw/task') task.set_sobject_value(person) task.set_value('assigned', 'unittest_gal') task.set_value('project_code', 'unittest') task.set_value('description', 'do something good') task.set_value('process', 'unittest2') task.set_value('context', 'unittest2') task.commit() # add these rules to the current user rules = """ <rules> <rule group="sobject_column" default="edit"/> <rule group="sobject_column" search_type="unittest/person" column="name_first" access="edit"/> <rule group="sobject_column" search_type="unittest/person" column="name_last" access="deny"/> <rule group="sobject_column" search_type="unittest/person" column="nationality" access="deny"/> </rules> """ xml = Xml() xml.read_string(rules) access_manager = Environment.get_security().get_access_manager() access_manager.add_xml_rules(xml) # disable admin for this test access_manager.set_admin(False) # should succeed person.set_value("name_first", "Donny") # should fail try: person.set_value("name_last", "Ducky") except SecurityException, e: pass
def _do_login(self): allow_guest = Config.get_value("security", "allow_guest") if allow_guest == 'true': allow_guest = True else: allow_guest = False security = Environment.get_security() login = security.login_with_ticket(self.ticket, allow_guest=allow_guest) if not login: raise SecurityException("Cannot login with key: %s. Session may have expired." % self.ticket)