Ejemplo n.º 1
0
    def _get_predefined_url(cls, key, hash):

        # make some predefined fake urls
        if key in ["link", "tab", "admin"]:
            # this is called by PageNav
            if key == "admin":
                expression = "/admin/link/{link}"
            else:
                expression = "/%s/{link}" % key
            options = Common.extract_dict(hash, expression)
            link = options.get("link")

            if not link:
                return None


            # test link security
            project_code = Project.get_project_code()
            security = Environment.get_security()
            keys = [
                    { "element": link },
                    { "element": "*" },
                    { "element": link, "project": project_code },
                    { "element": "*", "project": project_code }
            ]
            if not security.check_access("link", keys, "allow", default="deny"):
                return None


            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)
            if not options:

                from pyasm.biz import Schema
                config_xml = []
                config_xml.append( '''
                <config>
                ''')
         
                config_schema = Schema.get_predefined_schema('config')
                SideBarBookmarkMenuWdg.get_schema_snippet("_config_schema", config_schema, config_xml)
                schema = Schema.get_admin_schema()
                SideBarBookmarkMenuWdg.get_schema_snippet("_admin_schema", schema, config_xml)

                config_xml.append( '''
                </config>
                ''')

                xml = "".join(config_xml)

                from pyasm.widget import WidgetConfig
                schema_config = WidgetConfig.get(view="_admin_schema", xml=xml)
                options = schema_config.get_display_options(link)
                if not options:
                    schema_config.set_view("_config_schema")
                    options = schema_config.get_display_options(link)

                if not options:
                    return None




            class_name = options.get("class_name")
            widget_key = options.get("widget_key")
            if widget_key:
                class_name = WidgetClassHandler().get_display_handler(widget_key)
            elif not class_name:
                class_name = 'tactic.ui.panel.ViewPanelWdg'


            if key in ["admin", "tab"]:
                use_index = "false"
            else:
                use_index = "true"

            if key in ['admin']:
                use_admin = "true"
            else:
                use_admin = "false"


            xml = []
            xml.append('''<element admin="%s" index="%s">''' % (use_admin, use_index))
            xml.append('''  <display class="%s">''' % class_name)
            for name, value in options.items():
                xml.append("<%s>%s</%s>" % (name, value, name) )
            xml.append('''  </display>''')
            xml.append('''</element>''')

            xml = "\n".join(xml)

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/%s/{value}" % key)
            sobject.set_value("widget", xml )

            return sobject
 
        else:
            return None
Ejemplo n.º 2
0
    def _get_predefined_url(cls, key, hash):

        # make some predefined fake urls
        if key in ["link", "tab", "admin"]:
            # this is called by PageNav
            if key == "admin":
                expression = "/admin/link/{link}"
            else:
                expression = "/%s/{link}" % key
            options = Common.extract_dict(hash, expression)
            link = options.get("link")

            if not link:
                return None


            # test link security
            project_code = Project.get_project_code()
            security = Environment.get_security()
            keys = [
                    { "element": link },
                    { "element": "*" },
                    { "element": link, "project": project_code },
                    { "element": "*", "project": project_code }
            ]
            if not security.check_access("link", keys, "allow", default="deny"):
                return None


            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)
            if not options:

                from pyasm.biz import Schema
                config_xml = []
                config_xml.append( '''
                <config>
                ''')
         
                config_schema = Schema.get_predefined_schema('config')
                SideBarBookmarkMenuWdg.get_schema_snippet("_config_schema", config_schema, config_xml)
                schema = Schema.get_admin_schema()
                SideBarBookmarkMenuWdg.get_schema_snippet("_admin_schema", schema, config_xml)

                config_xml.append( '''
                </config>
                ''')

                xml = "".join(config_xml)

                from pyasm.widget import WidgetConfig
                schema_config = WidgetConfig.get(view="_admin_schema", xml=xml)
                options = schema_config.get_display_options(link)
                if not options:
                    schema_config.set_view("_config_schema")
                    options = schema_config.get_display_options(link)

                if not options:
                    return None




            class_name = options.get("class_name")
            widget_key = options.get("widget_key")
            if widget_key:
                class_name = WidgetClassHandler().get_display_handler(widget_key)
            elif not class_name:
                class_name = 'tactic.ui.panel.ViewPanelWdg'


            if key in ["admin", "tab"]:
                use_index = "false"
            else:
                use_index = "true"

            if key in ['admin']:
                use_admin = "true"
            else:
                use_admin = "false"


            xml = []
            xml.append('''<element admin="%s" index="%s">''' % (use_admin, use_index))
            xml.append('''  <display class="%s">''' % class_name)
            for name, value in options.items():
                xml.append("<%s>%s</%s>" % (name, value, name) )
            xml.append('''  </display>''')
            xml.append('''</element>''')

            xml = "\n".join(xml)

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/%s/{value}" % key)
            sobject.set_value("widget", xml )

            return sobject
 
        else:
            return None
Ejemplo n.º 3
0
    def _get_predefined_url(cls, key, hash):

        # only allow people with site admin
        security = Environment.get_security()
        is_admin = security.is_admin()
        if not is_admin and key == "admin":
            return None
 
 
        # make some predefined fake urls
        if key in ["link", "tab", "admin"]:
            # this is called by PageNav
            if key == "admin":
                expression = "/admin/link/{link}"
            else:
                expression = "/%s/{link}" % key
            options = Common.extract_dict(hash, expression)
            link = options.get("link")
            
            if not link:
                return None


            from tactic.ui.panel import SideBarBookmarkMenuWdg
            personal = False
            if '.' in link:

                # put in a check to ensure this is a user
                parts = link.split(".")

                user = Environment.get_user_name()
                
                def is_personal(user, parts):
                    '''See if parts contains period
                       seperated form of username.'''
                    acc = ""
                    for part in parts:
                        if acc == "":
                            acc = part
                        else:
                            acc = "%s.%s" % (acc, part)
                        if user == acc:
                            return True
                    return False

                personal = is_personal(user, parts) 
                
            # test link security
            project_code = Project.get_project_code()
            security = Environment.get_security()
            keys = [
                    { "element": link },
                    { "element": "*" },
                    { "element": link, "project": project_code },
                    { "element": "*", "project": project_code }
            ]
            if not personal and not security.check_access("link", keys, "allow", default="deny"):
                print "Not allowed"
                return None


            # This is used to find a sub menu (?)
            #view = link
            view = "definition"
            config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", view, personal=personal)

            view = config.get_element_attribute(link, 'view')
            if view:
                options['widget_key'] = 'custom_layout'
                options['view'] = view
                class_name = None
            else:
                options = config.get_display_options(link)
                class_name = config.get_display_handler(link)


            if not options:

                from pyasm.biz import Schema
                config_xml = []
                config_xml.append( '''
                <config>
                ''')
         
                config_schema = Schema.get_predefined_schema('config')
                SideBarBookmarkMenuWdg.get_schema_snippet("_config_schema", config_schema, config_xml)
                schema = Schema.get_admin_schema()
                SideBarBookmarkMenuWdg.get_schema_snippet("_admin_schema", schema, config_xml)

                config_xml.append( '''
                </config>
                ''')

                xml = "".join(config_xml)

                from pyasm.widget import WidgetConfig
                schema_config = WidgetConfig.get(view="_admin_schema", xml=xml)
                options = schema_config.get_display_options(link)
                if not options:
                    schema_config.set_view("_config_schema")
                    options = schema_config.get_display_options(link)

                if not options:
                    return None


            if not class_name or class_name == "LinkWdg":
                class_name = options.get("class_name")

            widget_key = options.get("widget_key")


            if widget_key:
                class_name = WidgetClassHandler().get_display_handler(widget_key)
            elif not class_name:
                class_name = 'tactic.ui.panel.ViewPanelWdg'


            if key in ["admin", "tab"]:
                use_index = "false"
            else:
                use_index = "true"

            if key in ['admin']:
                use_admin = "true"
            else:
                use_admin = "false"


            xml = []
            xml.append('''<element admin="%s" index="%s">''' % (use_admin, use_index))
            xml.append('''  <display class="%s">''' % class_name)
            for name, value in options.items():
                xml.append("<%s>%s</%s>" % (name, value, name) )
            xml.append('''  </display>''')
            xml.append('''</element>''')

            xml = "\n".join(xml)

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/%s/{value}" % key)
            sobject.set_value("widget", xml )

            return sobject


        elif key == "rest":

            xml = '''<element widget='true'>
  <display class='tactic.protocol.APIRestHandler'>
  </display>
</element>'''

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/rest")
            sobject.set_value("widget", xml )

            return sobject


        else:
            return None
Ejemplo n.º 4
0
    def _get_predefined_url(cls, key, hash):

        # make some predefined fake urls
        if key in ["link", "tab", "admin"]:
            # this is called by PageNav
            if key == "admin":
                expression = "/admin/link/{link}"
            else:
                expression = "/%s/{link}" % key
            options = Common.extract_dict(hash, expression)
            link = options.get("link")

            if not link:
                return None

            from tactic.ui.panel import SideBarBookmarkMenuWdg

            personal = False
            if "." in link:

                # put in a check to ensure this is a user
                parts = link.split(".")

                user = Environment.get_user_name()

                def is_personal(user, parts):
                    """See if parts contains period
                       seperated form of username."""
                    acc = ""
                    for part in parts:
                        if acc == "":
                            acc = part
                        else:
                            acc = "%s.%s" % (acc, part)
                        if user == acc:
                            return True
                    return False

                personal = is_personal(user, parts)

            # test link security
            project_code = Project.get_project_code()
            security = Environment.get_security()
            keys = [
                {"element": link},
                {"element": "*"},
                {"element": link, "project": project_code},
                {"element": "*", "project": project_code},
            ]
            if not personal and not security.check_access("link", keys, "allow", default="deny"):
                print "Not allowed"
                return None

            config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", link, personal=personal)
            options = config.get_display_options(link)
            if not options:

                from pyasm.biz import Schema

                config_xml = []
                config_xml.append(
                    """
                <config>
                """
                )

                config_schema = Schema.get_predefined_schema("config")
                SideBarBookmarkMenuWdg.get_schema_snippet("_config_schema", config_schema, config_xml)
                schema = Schema.get_admin_schema()
                SideBarBookmarkMenuWdg.get_schema_snippet("_admin_schema", schema, config_xml)

                config_xml.append(
                    """
                </config>
                """
                )

                xml = "".join(config_xml)

                from pyasm.widget import WidgetConfig

                schema_config = WidgetConfig.get(view="_admin_schema", xml=xml)
                options = schema_config.get_display_options(link)
                if not options:
                    schema_config.set_view("_config_schema")
                    options = schema_config.get_display_options(link)

                if not options:
                    return None

            class_name = options.get("class_name")
            widget_key = options.get("widget_key")
            if widget_key:
                class_name = WidgetClassHandler().get_display_handler(widget_key)
            elif not class_name:
                class_name = "tactic.ui.panel.ViewPanelWdg"

            if key in ["admin", "tab"]:
                use_index = "false"
            else:
                use_index = "true"

            if key in ["admin"]:
                use_admin = "true"
            else:
                use_admin = "false"

            xml = []
            xml.append("""<element admin="%s" index="%s">""" % (use_admin, use_index))
            xml.append("""  <display class="%s">""" % class_name)
            for name, value in options.items():
                xml.append("<%s>%s</%s>" % (name, value, name))
            xml.append("""  </display>""")
            xml.append("""</element>""")

            xml = "\n".join(xml)

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/%s/{value}" % key)
            sobject.set_value("widget", xml)

            return sobject

        else:
            return None