def get_display(my): top = DivWdg() hash = my.kwargs.get("hash") Container.put("url_hash", hash) security = Environment.get_security() is_admin = security.check_access("builtin", "view_site_admin", "allow") if hash == "/admin" and not is_admin: hash = "/index" if not hash: # NOTE: this really doesn't get call anymore because an empty # hash gets remapped to "/index" widget = my.get_default_wdg() top.add(widget) # This would provide a way to get the default index widget. #elif hash == "/projects": # widget = my.get_default_wdg() # from tactic_sites.default.modules import IndexWdg # top.add( IndexWdg() ) else: from tactic.ui.panel import HashPanelWdg project_code = Project.get_project_code() if project_code == 'admin' and hash == '/index': widget = my.get_default_wdg() else: #print "HASH: ", hash #print "project: ", project_code from pyasm.security import Site #print "site: ", Site.get_site() widget = HashPanelWdg.get_widget_from_hash(hash, return_none=True) if not widget: if hash == "/index": widget = my.get_default_wdg() elif hash == '/admin': widget = my.get_default_wdg() else: widget = HashPanelWdg.get_widget_from_hash("/index", return_none=True) top.add(widget) return top
def get_display(my): top = DivWdg() hash = my.kwargs.get("hash") Container.put("url_hash", hash) security = Environment.get_security() is_admin = security.check_access("builtin", "view_site_admin", "allow") if hash == "/admin" and not is_admin: hash = "/index" if not hash: # NOTE: this really doesn't get call anymore because an empty # hash gets remapped to "/index" widget = my.get_default_wdg() top.add(widget) # This would provide a way to get the default index widget. #elif hash == "/projects": # widget = my.get_default_wdg() # from tactic_sites.default.modules import IndexWdg # top.add( IndexWdg() ) else: from tactic.ui.panel import HashPanelWdg project_code = Project.get_project_code() if project_code == 'admin' and hash == '/index': widget = my.get_default_wdg() else: print "HASH: ", hash print "project: ", project_code from pyasm.security import Site print "site: ", Site.get_site() widget = HashPanelWdg.get_widget_from_hash(hash, return_none=True) if not widget: if hash == "/index": widget = my.get_default_wdg() elif hash == '/admin': widget = my.get_default_wdg() else: widget = HashPanelWdg.get_widget_from_hash("/index", return_none=True) top.add(widget) return top
def get_display(my): div = DivWdg() class_path = Common.get_full_class_name(my) from tactic.ui.panel import HashPanelWdg try: widget = HashPanelWdg.get_widget_from_hash("/index", return_none=True) div.add(widget) except: widget = None if not widget: class_path = class_path.replace("IndexWdg", "IndexWdg2") kwargs = {} div.add_behavior( { 'type': 'load', 'class_path': class_path, 'kwargs': kwargs, 'cbjs_action': ''' spt.dom.load_js(["popup.js"], function() { spt.panel.load(bvr.src_el, bvr.class_path, bvr.kwargs); }); ''' } ) return div
def get_content(my, request_type): web = WebContainer.get_web() # NOTE: is this needed anymore? if request_type in ["upload", "dynamic_file"]: print "DEPRECATED: dynamic file in app_server.py" widget = Widget() page = my.get_page_widget() widget.add(page) return widget # find hash of url my.custom_url = None if my.hash: hash = "/".join(my.hash) hash = "/%s" % hash from tactic.ui.panel import HashPanelWdg my.custom_url = HashPanelWdg.get_url_from_hash(hash) if my.custom_url: content_type = my.custom_url.get_value("content_type", no_exception=True) # TODO: we may want to handle this differently for content types # other that text/html return my.get_application_wdg()
def get_display(self): div = DivWdg() class_path = Common.get_full_class_name(self) from tactic.ui.panel import HashPanelWdg try: widget = HashPanelWdg.get_widget_from_hash("/index", return_none=True) div.add(widget) except: widget = None if not widget: class_path = class_path.replace("IndexWdg", "IndexWdg2") kwargs = {} div.add_behavior({ 'type': 'load', 'class_path': class_path, 'kwargs': kwargs, 'cbjs_action': 'spt.panel.load(bvr.src_el, bvr.class_path, bvr.kwargs)' }) return div
def get_display(self): top = DivWdg() hash = self.kwargs.get("hash") pathname = self.kwargs.get("pathname") Container.put("url_hash", hash) security = Environment.get_security() is_admin = security.check_access("builtin", "view_site_admin", "allow") if hash == "/admin" and not is_admin: hash = "/index" if not hash: widget = self.get_default_wdg() top.add(widget) # This would provide a way to get the default index widget. #elif hash == "/projects": # widget = self.get_default_wdg() # from tactic_sites.default.modules import IndexWdg # top.add( IndexWdg() ) else: from tactic.ui.panel import HashPanelWdg project_code = Project.get_project_code() if project_code == 'admin' and hash == '/index': widget = self.get_default_wdg() else: from pyasm.security import Site widget = HashPanelWdg.get_widget_from_hash(hash, return_none=True) if not widget: if hash == "/index": widget = self.get_default_wdg() elif hash == '/admin': widget = self.get_default_wdg() else: widget = HashPanelWdg.get_widget_from_hash( "/index", return_none=True) top.add(widget) return top
def get_display(self): top = DivWdg() hash = self.kwargs.get("hash") pathname = self.kwargs.get("pathname") Container.put("url_hash", hash) security = Environment.get_security() is_admin = security.check_access("builtin", "view_site_admin", "allow") if hash == "/admin" and not is_admin: hash = "/index" if not hash: widget = self.get_default_wdg() top.add(widget) # This would provide a way to get the default index widget. #elif hash == "/projects": # widget = self.get_default_wdg() # from tactic_sites.default.modules import IndexWdg # top.add( IndexWdg() ) else: from tactic.ui.panel import HashPanelWdg project_code = Project.get_project_code() if project_code == 'admin' and hash == '/index': widget = self.get_default_wdg() else: from pyasm.security import Site widget = HashPanelWdg.get_widget_from_hash(hash, return_none=True) if not widget: if hash == "/index": widget = self.get_default_wdg() elif hash == '/admin': widget = self.get_default_wdg() else: widget = HashPanelWdg.get_widget_from_hash("/index", return_none=True) top.add(widget) return top
def get_display(self): top = DivWdg() top.set_id('top_of_application') top.add_style("overflow: hidden") from tactic.ui.panel import HashPanelWdg splash_div = HashPanelWdg.get_widget_from_hash("/splash", return_none=True) if not splash_div: splash_div = DivWdg() splash_div.add_style('text-align: center') splash_div.add( '<img src="/context/icons/common/indicator_snake.gif" border="0"/>' ) splash_div.add(" ") project = Project.get() title = project.get_value("title") if not title: title = "TACTIC" splash_div.add('''Loading "%s" ....''' % title) splash_div.add_style("font-size: 1.5em") splash_div.add_style("margin: 200 0 500 0") splash_div.add_behavior({ 'type': 'load', 'hash': self.hash, 'cbjs_action': ''' if (bvr.hash) { spt.hash.hash = "/" + bvr.hash; } else { spt.hash.hash = "/index"; } spt.hash.set_index_hash("link/_startup"); ''' }) top.add(splash_div) return top
def get_display(self): top = DivWdg() top.set_id('top_of_application') top.add_style("overflow: hidden") from tactic.ui.panel import HashPanelWdg splash_div = HashPanelWdg.get_widget_from_hash("/splash", return_none=True) if not splash_div: splash_div = DivWdg() splash_div.add_style('text-align: center') splash_div.add('<img src="/context/icons/common/indicator_snake.gif" border="0"/>') splash_div.add(" ") project = Project.get() title = project.get_value("title") if not title: title = "TACTIC" splash_div.add('''Loading "%s" ....'''% title) splash_div.add_style("font-size: 1.5em") splash_div.add_style("margin: 200 0 500 0") splash_div.add_behavior( { 'type': 'load', 'hash': self.hash, 'cbjs_action': ''' if (bvr.hash) { spt.hash.hash = "/" + bvr.hash; } else { spt.hash.hash = "/index"; } spt.hash.set_index_hash("link/_startup"); ''' } ) top.add(splash_div) return top
def get_display(my): top = DivWdg() hash = my.kwargs.get("hash") Container.put("url_hash", hash) if not hash: # NOTE: this really doesn't get call anymore because an empty # hash gets remapped to "/index" widget = my.get_default_wdg() top.add(widget) # This would provide a way to get the default index widget. #elif hash == "/projects": # widget = my.get_default_wdg() # from tactic_sites.default.modules import IndexWdg # top.add( IndexWdg() ) else: from tactic.ui.panel import HashPanelWdg project_code = Project.get_project_code() if project_code == 'admin' and hash == '/index': widget = my.get_default_wdg() else: widget = HashPanelWdg.get_widget_from_hash(hash, return_none=True) if hash == "/index" and not widget: widget = my.get_default_wdg() elif hash == '/admin' and not widget: widget = my.get_default_wdg() top.add(widget) return top
def get_display(my): # Custom URLs have the ability to send out different content types url = my.kwargs.get("url") web = WebContainer.get_web() #content_type = my.kwargs.get("content_type") #print "content_type: ", content_type hash = my.kwargs.get("hash") ticket = web.get_form_value("ticket") method = web.get_request_method() headers = web.get_request_headers() accept = headers.get("Accept") expression = url.get_value("url") kwargs = Common.extract_dict(hash, expression) # Does the URL listen to specific Accept values? # or does it enforce a return content type ... and how does one # know what exactly is supported? Accept is kind of complicated. # Easier to put in as a paramenter ... but should accept both # get the widget designated for hash kwargs['Accept'] = accept kwargs['Method'] = method from tactic.ui.panel import HashPanelWdg hash_widget = HashPanelWdg.get_widget_from_hash(hash, kwargs=kwargs) # Really, the hash widget should determine what is returned, but # should take the Accept into account. It is not up to this # class to determine what is or isn't implemented, not is it the # responsibility of this class to convert the data. So, it # returns whatever is given. widget = Widget() # We need to to get the content-type from the widget ... however # it decides to make use of the "Accept" type #widget.get_content_type() # # Example implementation of custom script, run by hash_widget # if accept == "application/json": value = hash_widget.get_display() value = jsondumps(value) web.set_content_type(accept) elif accept == "application/xml": from pyasm.common import Xml value = hash_widget.get_display() if isinstance(value, basestring): xml = Xml(value) value = xml.to_string() elif isinstance(value, Xml): value = value.to_string() web.set_content_type(accept) elif accept == "plain/text": from pyasm.common import Xml value = hash_widget.get_display() value = str(value) web.set_content_type(accept) else: # return text/html value = DivWdg() if isinstance(hash_widget, basestring): value.add(hash_widget) else: value.add(hash_widget.get_display()) web.set_content_type("text/html") widget.add(value) return widget
def init(my): link = my.kwargs.get('link') hash = my.kwargs.get('hash') my.widget = None if link: from tactic.ui.panel import SideBarBookmarkMenuWdg personal = False if '.' in link: personal = True config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", link, personal=personal) options = config.get_display_options(link) # this is vital for view saving element_name = link attr_dict = config.get_element_attributes(link) title = attr_dict.get('title') hash = "/tab/%s" % link config = ''' <config> <application> <element name="left_nav"> <display class="tactic.ui.panel.SideBarPanelWdg"> </display> </element> <element name="main_body"> <display class="tactic.ui.panel.HashPanelWdg"> <hash>%s</hash> <element_name>%s</element_name> <title>%s</title> </display> <web/> </element> </application> </config> ''' % (hash, element_name, title) elif hash: from tactic.ui.panel import HashPanelWdg my.widget = HashPanelWdg.get_widget_from_hash(hash, force_no_index=True) config = None else: security = Environment.get_security() start_link = security.get_start_link() if start_link: my.kwargs['link'] = start_link return my.init() # search for a defined welcome view search = Search("config/widget_config") search.add_filter("category", "top_layout") search.add_filter("view", "welcome") config_sobj = search.get_sobject() if config_sobj: config = config_sobj.get_value("config") else: config = WidgetSettings.get_value_by_key("top_layout") if not config: config = my.get_default_config() my.config_xml = Xml() my.config_xml.read_string(config)
def _get_display(self): # set up the security object from pyasm.security import Security, Sudo from pyasm.biz import Project from pyasm.web import WebContainer web = WebContainer.get_web() # guest mode # allow_guest = Config.get_value("security", "allow_guest") if allow_guest == 'true': allow_guest = True else: allow_guest = False site_obj = Site.get() site_allow_guest = site_obj.allow_guest() if site_allow_guest != None: allow_guest = site_allow_guest security = Security() try: security = self.handle_security(security) is_logged_in = security.is_logged_in() except Exception as e: print("AppServer Exception: ", e) return self.handle_not_logged_in() guest_mode = Config.get_value("security", "guest_mode") if not guest_mode: guest_mode = 'restricted' # Test #allow_guest = True #guest_mode = "full" # if not logged in, then log in as guest if not is_logged_in: if not allow_guest: return self.handle_not_logged_in() else: # login as guest security = Security() self.handle_guest_security(security) # for here on, the user is logged in login_name = Environment.get_user_name() is_upload = '/UploadServer' in web.get_request_url().to_string() # check if the user has permission to see this project project = web.get_context_name() if project == 'default': override_default = Project.get_default_project() if override_default: project = override_default if is_upload: print("IS UPLOAD") access = True elif project != 'default': # make sure the security check is done on the appropriate site path_info = site_obj.get_request_path_info() if path_info: site = path_info.get("site") Site.set_site(site) s = Environment.get_security() has_site = True else: s = security has_site = False try: security_version = get_security_version() if security_version == 1: default = "view" access = s.check_access("project", project, "view", default="view") else: default = "deny" key = {"code": project} key2 = {"code": "*"} keys = [key, key2] access = s.check_access("project", keys, "allow", default=default) finally: if has_site: Site.pop_site() else: # you always have access to the default project access = True if not access: if login_name == "guest": from pyasm.widget import WebLoginWdg msg = web.get_form_value(WebLoginWdg.LOGIN_MSG) if not msg: msg = "User [%s] is not allowed to see this project [%s]" % ( login_name, project) web.set_form_value(WebLoginWdg.LOGIN_MSG, msg) return self.handle_not_logged_in(allow_change_admin=False) else: from pyasm.widget import BottomWdg, Error403Wdg widget = Widget() top = self.get_top_wdg() widget.add(top) widget.add(Error403Wdg()) widget.add(BottomWdg()) widget.get_display() if is_upload: print( "WARNING: User [%s] is not allowed to upload to project [%s]." % (login_name, project)) return if login_name == 'guest': # let the site handle the guest completely guest_wdg = site_obj.get_guest_wdg(self.hash) if guest_wdg: web_app = WebApp() web_app.get_display(guest_wdg) return # some extra precautions in guest mode if login_name == 'guest' and guest_mode != "full": # show a restricted guest mode from pyasm.widget import WebLoginWdg, BottomWdg from tactic.ui.app import TitleTopWdg from pyasm.biz import Project from tactic.ui.panel import HashPanelWdg web = WebContainer.get_web() widget = Widget() top = TitleTopWdg() widget.add(top) body = top.get_body() body.add_color("background", "background") body.add_color("color", "color") has_site = False # use the path to set the project and/or site path_info = site_obj.get_request_path_info() if path_info: path_site = path_info.get("site") try: Site.set_site(path_site) has_site = True except Exception as e: print("WARNING: ", e) current_project = web.get_context_name() else: current_project = path_info.get("project_code") if not current_project: current_project = web.get_context_name() else: # get the project from the url because we are still # in the admin project at this stage current_project = web.get_context_name() sudo = Sudo() try: if current_project != "default": project = Project.get_by_code(current_project, use_cache=False) if not project: raise Exception("Project [%s] does not exist" % current_project) except Exception as e: print("WARNING: ", e) web_wdg = None else: if not current_project or current_project == "default": current_project = Project.get_default_project() if current_project and current_project != "default": try: Project.set_project(current_project) except SecurityException as e: print(e) if 'is not permitted to view project' in e.__str__(): pass else: raise # find the guest views #search = Search("config/url") #urls = search.get_sobjects() #open_hashes = [x.get("url").lstrip("/").split("/")[0] for x in urls] link = "/%s" % "/".join(self.hash) # guest views open_hashes = site_obj.get_guest_hashes() if len(self.hash) >= 1 and self.hash[0] in open_hashes: web_wdg = HashPanelWdg.get_widget_from_hash( link, return_none=True) else: web_wdg = None if not web_wdg: web_wdg = HashPanelWdg.get_widget_from_hash( "/guest", return_none=True, kwargs={"hash": link}) if web_wdg: if not isinstance(web_wdg, basestring): web_wdg = web_wdg.get_buffer_display() top.add(web_wdg) else: web_wdg = None finally: sudo.exit() if has_site: Site.pop_site() if not web_wdg: msg = "No default page defined for guest user. Please set up /guest in Custom URL." web.set_form_value(WebLoginWdg.LOGIN_MSG, msg) return self.handle_not_logged_in(allow_change_admin=False) # create a web app and run it through the pipeline web_app = WebApp() web_app.get_display(widget) return # Full access # if a guest has full access, then handle it here if login_name == 'guest' and guest_mode == "full": # some extra security for guest users guest_url_allow = Config.get_value("security", "guest_url_allow") if guest_url_allow: items = guest_url_allow.split("|") allowed = False if self.hash: url = self.hash[0] else: url = "index" for item in items: item = item.strip("/") if item == url: allowed = True break if not allowed: return self.handle_not_logged_in() # Welcome message for first time run is_first_run = Environment.is_first_run() if is_first_run: from pyasm.widget import WebLoginWdg, BottomWdg top = self.get_top_wdg() from tactic.ui.app import PageHeaderWdg from tactic.ui.startup import DbConfigPanelWdg widget = DivWdg() widget.add(top) widget.add(DbConfigPanelWdg()) widget.add(BottomWdg()) web_app = WebApp() web_app.get_display(widget) return # handle licensing license = security.get_license() user_name = security.get_user_name() is_licensed = license.is_licensed() # handle url security url_security = UrlSecurity() html = url_security.get_display() if html: widget = Widget() widget.add(html.getvalue()) widget.get_display() return web = WebContainer.get_web() # FIXME: although this works, it should be cleaned up # determine the type of request if '/UploadServer' in web.get_request_url().to_string(): page_type = "upload" elif web.get_form_value("ajax") != "": page_type = "ajax" elif web.get_form_value("dynamic_file") != "": # this mode creates a file dynamically page_type = "dynamic_file" else: page_type = "normal" # TODO: the following could be combined into a page_init function # provide the opportunity to set some templates self.set_templates() self.add_triggers() self.init_web_container() # install the language Translation.install() path_info = site_obj.get_request_path_info() if path_info and path_info.get("site") != "default": Site.set_site(path_info.get("site")) project_code = path_info.get("project_code") # handle the case where the project does not exist project = Project.get(no_exception=True) if not project: from pyasm.widget import BottomWdg, Error404Wdg Project.set_project("admin") widget = Widget() top = self.get_top_wdg() widget.add(top) widget.add(Error404Wdg()) widget.add(BottomWdg()) widget.get_display() return widget # get the content of the page try: widget = self.get_content(page_type) except Exception as e: print("ERROR: ", e) from pyasm.widget import BottomWdg, Error403Wdg widget = Widget() top = self.get_top_wdg() widget.add(top) widget.add(Error403Wdg()) widget.add(BottomWdg()) widget.get_display() # put an annoying alert if there is a problem with the license if not is_licensed: # to be sure, reread license. This gets around the problem # of the extra error message when uploading a new license license = security.reread_license() is_licensed = license.is_licensed() if not is_licensed: widget.add("<script>alert('%s')</script>" % license.get_message()) # create a web app and run it through the pipeline web_app = WebApp() web_app.get_display(widget)
try: if current_project != "default": project = Project.get_by_code(current_project) assert project except Exception, e: web_wdg = None else: # custom login widget if not current_project or current_project == "default": current_project = Project.get_default_project() if current_project and current_project != "default": Project.set_project(current_project) try: web_wdg = HashPanelWdg.get_widget_from_hash("/login", return_none=True) except Exception, e: print "WARNING: ", e raise from pyasm.widget import ExceptionMinimalWdg web_wdg = ExceptionMinimalWdg(e) web_wdg.add_style("margin: 50px auto") if web_wdg: web_wdg = web_wdg.get_buffer_display() top.add(web_wdg) else: web_wdg = None # display default web login
def get_error_wdg(self): kwargs = { } from tactic.ui.panel import HashPanelWdg widget = HashPanelWdg.get_widget_from_hash("/error404", return_none=True, kwargs=kwargs) if widget: return widget div = DivWdg() error_div = DivWdg() error_div.add("<hr/>") error_div.add("Error %s" % self.status) error_div.add("<hr/>") div.add(error_div) error_div.add_style("font-size: 18px") error_div.add_style("font-weight: bold") error_div.add_style("padding: 10px") error_div.add_style("width: auto") error_div.add_color("background", "background", -3) error_div.add_color("color", "color") #error_div.add_border() error_div.add_style("margin-left: 5px") error_div.add_style("margin-right: 5px") error_div.add_style("margin-top: -10px") div.add("<br/>") span = DivWdg() #span.add_color("color", "color") #span.add_style("color", "#FFF") if self.status == 404: span.add(HtmlElement.b("You have tried to access a url that is not recognized.")) else: span.add(HtmlElement.b(self.message)) span.add(HtmlElement.br(2)) web = WebContainer.get_web() root = web.get_site_root() if self.message.startswith('No project ['): label = 'You may need to correct the default_project setting in the TACTIC config.' else: label = "Go to the Main page for a list of valid projects" span.add(label) div.add(span) div.add(HtmlElement.br()) from tactic.ui.widget import ActionButtonWdg button_div = DivWdg() button_div.add_style("width: 90px") button_div.add_style("margin: 0px auto") div.add(button_div) button = ActionButtonWdg(title="Go to Main", tip='Click to go to main page') button_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' document.location = '/'; ''' } ) button.add_event("onmouseup", "document.location='/'") return div
try: if current_project != "default": project = Project.get_by_code(current_project) assert project except Exception, e: web_wdg = None else: # custom loginwidget if not current_project or current_project == "default": current_project = Config.get_value("install", "default_project") if current_project and current_project != "default": Project.set_project(current_project) try: web_wdg = HashPanelWdg.get_widget_from_hash("/login", return_none=True) except Exception, e: from pyasm.widget import ExceptionMinimalWdg web_wdg = ExceptionMinimalWdg(e) web_wdg.add_style("margin: 50px auto") if web_wdg: web_wdg = web_wdg.get_buffer_display() top.add(web_wdg) else: web_wdg = None # display default web login if not web_wdg: top.add(WebLoginWdg(allow_change_admin=allow_change_admin) )
def _get_display(my): # set up the security object from pyasm.security import Security, Sudo from pyasm.biz import Project from pyasm.web import WebContainer web = WebContainer.get_web() security = Security() security = my.handle_security(security) is_logged_in = security.is_logged_in() # guest mode # allow_guest = Config.get_value("security", "allow_guest") if allow_guest == 'true': allow_guest = True else: allow_guest = False guest_mode = Config.get_value("security", "guest_mode") if not guest_mode: guest_mode = 'restricted' #allow_guest = True #guest_mode = "full" # if not logged in, then log in as guest if not is_logged_in: if not allow_guest: return my.handle_not_logged_in() else: # login as guest security = Security() my.handle_guest_security(security) # for here on, the user is logged in login_name = Environment.get_user_name() # check if the user has permission to see this project project = web.get_context_name() if project == 'default': override_default = Config.get_value("install", "default_project") if override_default: project = override_default if project != 'default': security_version = get_security_version() if security_version == 1: default = "view" access = security.check_access("project", project, "view", default="view") else: default = "deny" key = { "code": project } key2 = { "code": "*" } #keys = [key] keys = [key, key2] access = security.check_access("project", keys, "allow", default=default) else: # you always have access to the default project access = True access = True if not access: if login_name == "guest": from pyasm.widget import WebLoginWdg msg = web.get_form_value(WebLoginWdg.LOGIN_MSG) if not msg: msg = "User [%s] is not allowed to see this project [%s]" % (login_name, project) web.set_form_value(WebLoginWdg.LOGIN_MSG, msg) return my.handle_not_logged_in(allow_change_admin=False) else: from pyasm.widget import WebLicenseWdg, BottomWdg, Error403Wdg widget = Widget() top = my.get_top_wdg() widget.add( top ) widget.add( Error403Wdg() ) widget.add( BottomWdg() ) widget.get_display() return if login_name == 'guest' and guest_mode == "full": # some extra security for guest users guest_url_allow = Config.get_value("security", "guest_url_allow") if guest_url_allow: items = guest_url_allow.split("|") allowed = False if my.hash: url = my.hash[0] else: url = "index" for item in items: item = item.strip("/") if item == url: allowed = True break if not allowed: return my.handle_not_logged_in() # some extra precautions in guest mode if login_name == 'guest' and guest_mode != "full": # show a restricted guest mode from pyasm.widget import WebLoginWdg, BottomWdg from tactic.ui.app import TitleTopWdg from pyasm.biz import Project from tactic.ui.panel import HashPanelWdg web = WebContainer.get_web() widget = Widget() top = TitleTopWdg() widget.add(top) body = top.get_body() body.add_gradient("background", "background", 5, -20) body.add_color("color", "color") # get the project from the url because we are still # in the admin project at this stage current_project = web.get_context_name() try: if current_project != "default": project = Project.get_by_code(current_project) assert project except Exception, e: web_wdg = None else: if not current_project or current_project == "default": current_project = Config.get_value("install", "default_project") if current_project and current_project != "default": Project.set_project(current_project) web_wdg = HashPanelWdg.get_widget_from_hash("/guest", return_none=True) if web_wdg: web_wdg = web_wdg.get_buffer_display() top.add(web_wdg) else: web_wdg = None if not web_wdg: msg = "No widget for Guest defined" web.set_form_value(WebLoginWdg.LOGIN_MSG, msg) top.add(WebLoginWdg() ) # create a web app and run it through the pipeline web_app = WebApp() web_app.get_display(widget) return
# FIXME: this doesn't work!!! It resets the home page search = Search("config/url") urls = search.get_sobjects() open_hashes = [ x.get("url").lstrip("/").split("/")[0] for x in urls ] print "open_hashes: ", open_hashes link = "/%s" % "/".join(my.hash) # guest views open_hashes = [ 'register', 'accept', 'thank_you', 'sign_in', 'pricing', 'change_password' ] if len(my.hash) >= 1 and my.hash[0] in open_hashes: web_wdg = HashPanelWdg.get_widget_from_hash( link, return_none=True) else: web_wdg = None if not web_wdg: web_wdg = HashPanelWdg.get_widget_from_hash( "/guest", return_none=True, kwargs={"hash": link}) if web_wdg: if not isinstance(web_wdg, basestring): web_wdg = web_wdg.get_buffer_display() top.add(web_wdg) else: web_wdg = None if not web_wdg: msg = "No default page for Guest defined"
def init(self): link = self.kwargs.get('link') hash = self.kwargs.get('hash') self.widget = None if link: from tactic.ui.panel import SideBarBookmarkMenuWdg personal = False if '.' in link: personal = True config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", link, personal=personal) options = config.get_display_options(link) # this is vital for view saving element_name = link attr_dict = config.get_element_attributes(link) title = attr_dict.get('title') hash = "/tab/%s" % link config = ''' <config> <application> <element name="left_nav"> <display class="tactic.ui.panel.SideBarPanelWdg"> </display> </element> <element name="main_body"> <display class="tactic.ui.panel.HashPanelWdg"> <hash>%s</hash> <element_name>%s</element_name> <title>%s</title> </display> <web/> </element> </application> </config> ''' % (hash, element_name, title) elif hash: from tactic.ui.panel import HashPanelWdg self.widget = HashPanelWdg.get_widget_from_hash( hash, force_no_index=True) config = None else: security = Environment.get_security() start_link = security.get_start_link() if start_link: self.kwargs['link'] = start_link return self.init() # search for a defined welcome view search = Search("config/widget_config") search.add_filter("category", "top_layout") search.add_filter("view", "welcome") config_sobj = search.get_sobject() if config_sobj: config = config_sobj.get_value("config") else: config = WidgetSettings.get_value_by_key("top_layout") if not config: config = self.get_default_config() self.config_xml = Xml() self.config_xml.read_string(config)
def _get_display(self): # set up the security object from pyasm.security import Security, Sudo from pyasm.biz import Project from pyasm.web import WebContainer web = WebContainer.get_web() # guest mode # allow_guest = Config.get_value("security", "allow_guest") if allow_guest == 'true': allow_guest = True else: allow_guest = False site_obj = Site.get() site_allow_guest = site_obj.allow_guest() if site_allow_guest != None: allow_guest = site_allow_guest security = Security() try: security = self.handle_security(security) is_logged_in = security.is_logged_in() except Exception as e: print("AppServer Exception: ", e) return self.handle_not_logged_in() guest_mode = Config.get_value("security", "guest_mode") if not guest_mode: guest_mode = 'restricted' # Test #allow_guest = True #guest_mode = "full" # if not logged in, then log in as guest if not is_logged_in: if not allow_guest: return self.handle_not_logged_in() else: # login as guest security = Security() self.handle_guest_security(security) # for here on, the user is logged in login_name = Environment.get_user_name() is_upload = '/UploadServer' in web.get_request_url().to_string() # check if the user has permission to see this project project = web.get_context_name() if project == 'default': override_default = Project.get_default_project() if override_default: project = override_default if is_upload: print("IS UPLOAD") access = True elif project != 'default': # make sure the security check is done on the appropriate site path_info = site_obj.get_request_path_info() if path_info: site = path_info.get("site") Site.set_site(site) s = Environment.get_security() has_site = True else: s = security has_site = False try: security_version = get_security_version() if security_version == 1: default = "view" access = s.check_access("project", project, "view", default="view") else: default = "deny" key = { "code": project } key2 = { "code": "*" } keys = [key, key2] access = s.check_access("project", keys, "allow", default=default) finally: if has_site: Site.pop_site() else: # you always have access to the default project access = True if not access: if login_name == "guest": from pyasm.widget import WebLoginWdg msg = web.get_form_value(WebLoginWdg.LOGIN_MSG) if not msg: msg = "User [%s] is not allowed to see this project [%s]" % (login_name, project) web.set_form_value(WebLoginWdg.LOGIN_MSG, msg) return self.handle_not_logged_in(allow_change_admin=False) else: from pyasm.widget import BottomWdg, Error403Wdg widget = Widget() top = self.get_top_wdg() widget.add( top ) widget.add( Error403Wdg() ) widget.add( BottomWdg() ) widget.get_display() if is_upload: print("WARNING: User [%s] is not allowed to upload to project [%s]."%(login_name, project)) return if login_name == 'guest': # let the site handle the guest completely guest_wdg = site_obj.get_guest_wdg(self.hash) if guest_wdg: web_app = WebApp() web_app.get_display(guest_wdg) return # some extra precautions in guest mode if login_name == 'guest' and guest_mode != "full": # show a restricted guest mode from pyasm.widget import WebLoginWdg, BottomWdg from tactic.ui.app import TitleTopWdg from pyasm.biz import Project from tactic.ui.panel import HashPanelWdg web = WebContainer.get_web() widget = Widget() top = TitleTopWdg() widget.add(top) body = top.get_body() body.add_color("background", "background") body.add_color("color", "color") has_site = False # use the path to set the project and/or site path_info = site_obj.get_request_path_info() if path_info: path_site = path_info.get("site") try: Site.set_site(path_site) has_site = True except Exception as e: print("WARNING: ", e) current_project = web.get_context_name() else: current_project = path_info.get("project_code") if not current_project: current_project = web.get_context_name() else: # get the project from the url because we are still # in the admin project at this stage current_project = web.get_context_name() sudo = Sudo() try: if current_project != "default": project = Project.get_by_code(current_project, use_cache=False) if not project: raise Exception("Project [%s] does not exist" % current_project) except Exception as e: print("WARNING: ", e) web_wdg = None else: if not current_project or current_project == "default": current_project = Project.get_default_project() if current_project and current_project != "default": try: Project.set_project(current_project) except SecurityException as e: print(e) if 'is not permitted to view project' in e.__str__(): pass else: raise # find the guest views #search = Search("config/url") #urls = search.get_sobjects() #open_hashes = [x.get("url").lstrip("/").split("/")[0] for x in urls] link = "/%s" % "/".join(self.hash) # guest views open_hashes = site_obj.get_guest_hashes() if len(self.hash) >= 1 and self.hash[0] in open_hashes: web_wdg = HashPanelWdg.get_widget_from_hash(link, return_none=True) else: web_wdg = None if not web_wdg: web_wdg = HashPanelWdg.get_widget_from_hash("/guest", return_none=True, kwargs={"hash": link}) if web_wdg: if not isinstance(web_wdg, basestring): web_wdg = web_wdg.get_buffer_display() top.add(web_wdg) else: web_wdg = None finally: sudo.exit() if has_site: Site.pop_site() if not web_wdg: msg = "No default page defined for guest user. Please set up /guest in Custom URL." web.set_form_value(WebLoginWdg.LOGIN_MSG, msg) return self.handle_not_logged_in(allow_change_admin=False) # create a web app and run it through the pipeline web_app = WebApp() web_app.get_display(widget) return # Full access # if a guest has full access, then handle it here if login_name == 'guest' and guest_mode == "full": # some extra security for guest users guest_url_allow = Config.get_value("security", "guest_url_allow") if guest_url_allow: items = guest_url_allow.split("|") allowed = False if self.hash: url = self.hash[0] else: url = "index" for item in items: item = item.strip("/") if item == url: allowed = True break if not allowed: return self.handle_not_logged_in() # Welcome message for first time run is_first_run = Environment.is_first_run() if is_first_run: from pyasm.widget import WebLoginWdg, BottomWdg top = self.get_top_wdg() from tactic.ui.app import PageHeaderWdg from tactic.ui.startup import DbConfigPanelWdg widget = DivWdg() widget.add( top ) widget.add( DbConfigPanelWdg() ) widget.add( BottomWdg() ) web_app = WebApp() web_app.get_display(widget) return # handle licensing license = security.get_license() user_name = security.get_user_name() is_licensed = license.is_licensed() # handle url security url_security = UrlSecurity() html = url_security.get_display() if html: widget = Widget() widget.add(html.getvalue()) widget.get_display() return web = WebContainer.get_web() # FIXME: although this works, it should be cleaned up # determine the type of request if '/UploadServer' in web.get_request_url().to_string(): page_type = "upload" elif web.get_form_value("ajax") != "": page_type = "ajax" elif web.get_form_value("dynamic_file") != "": # this mode creates a file dynamically page_type = "dynamic_file" else: page_type = "normal" # TODO: the following could be combined into a page_init function # provide the opportunity to set some templates self.set_templates() self.add_triggers() self.init_web_container() # install the language Translation.install() path_info = site_obj.get_request_path_info() if path_info and path_info.get("site") != "default": Site.set_site(path_info.get("site")) project_code = path_info.get("project_code") # handle the case where the project does not exist project = Project.get(no_exception=True) if not project: from pyasm.widget import BottomWdg, Error404Wdg Project.set_project("admin") widget = Widget() top = self.get_top_wdg() widget.add( top ) widget.add( Error404Wdg() ) widget.add( BottomWdg() ) widget.get_display() return widget # get the content of the page try: widget = self.get_content(page_type) except Exception as e: print("ERROR: ", e) from pyasm.widget import BottomWdg, Error403Wdg widget = Widget() top = self.get_top_wdg() widget.add( top ) widget.add( Error403Wdg() ) widget.add( BottomWdg() ) widget.get_display() # put an annoying alert if there is a problem with the license if not is_licensed: # to be sure, reread license. This gets around the problem # of the extra error message when uploading a new license license = security.reread_license() is_licensed = license.is_licensed() if not is_licensed: widget.add("<script>alert('%s')</script>" % license.get_message()) # create a web app and run it through the pipeline web_app = WebApp() web_app.get_display(widget)
raise # find the guest views # FIXME: this doesn't work!!! It resets the home page search = Search("config/url") urls = search.get_sobjects() open_hashes = [x.get("url").lstrip("/").split("/")[0] for x in urls] print "open_hashes: ", open_hashes link = "/%s" % "/".join(my.hash) # guest views open_hashes = ['register', 'accept', 'thank_you', 'sign_in','pricing', 'change_password'] if len(my.hash) >= 1 and my.hash[0] in open_hashes: web_wdg = HashPanelWdg.get_widget_from_hash(link, return_none=True) else: web_wdg = None if not web_wdg: web_wdg = HashPanelWdg.get_widget_from_hash("/guest", return_none=True, kwargs={"hash": link}) if web_wdg: if not isinstance(web_wdg, basestring): web_wdg = web_wdg.get_buffer_display() top.add(web_wdg) else: web_wdg = None if not web_wdg: msg = "No default page defined for guest user. Please set up /guest in Custom URL." web.set_form_value(WebLoginWdg.LOGIN_MSG, msg)