コード例 #1
0
    def create_defaults(self):
        def save_version(table_name, version):
            db.table_version.update_or_insert(
                db.table_version.table_name == table_name, **dict(table_name=table_name, version=version))
            return

        for table, version, on_update_data in self.table_defaults:
            if version == 0:
                continue

            old_version = db(db.table_version.table_name == table._tablename).select().first()
            if old_version and old_version.version >= version:
                continue

            try:
                if db(table).isempty():
                    if on_update_data:
                        on_update_data(table, version)
                else:
                    defs = table_default_values(table)
                    for k in defs:
                        if db(table[k] == None).count() > 0:
                            db(table[k] == None).update(**{k:defs[k]})

                    if on_update_data:
                        on_update_data(table, version)
                save_version(table._tablename, version)
            except Exception, e:
                from onx_log import onx_logger
                onx_logger().error(str(e))
コード例 #2
0
def auth_has_access(c=request.controller, f=request.function):
    try:
        if auth.user.username == Settings.SUPER_USER:
            return True

        #valida se menu selecionda é de algum produto contratado
        menu_name = '%s_%s' % (c, f)
        menu = response.unique_menu.get(menu_name)
        if not menu:
            auth.settings.on_failed_authorization = URL(c='activity', f='menu_access', vars=dict(menu=menu_name))
            return False

        #valida o contrato
        if response.contract:
            if response.contract['result']['code'] > 100:
                auth.settings.on_failed_authorization = URL(c='activity', f='licence')
                return False

            is_valid = False
            for menu_prj in menu.projects:
                product = response.contract['items'].get(menu_prj)
                if product:
                    is_valid = product['result']['code'] == 100

            if not is_valid:
                auth.settings.on_failed_authorization = URL(c='activity', f='licence', vars=dict(menu=menu_name))
                return False

        if auth.has_membership(role=Settings.ADMIN_ROLE):
            return True
        # é o contrario de permitido, se tiver significa bloqueado
        return not auth.has_permission(c,f)
    except Exception, e:
        from onx_log import onx_logger
        onx_logger().error(str(e))
        return True
コード例 #3
0
    def load_contract():
        try:
            registry = PainelModel.company().registry
            contract_id = request.application
            if contract_id == 'soupport':
                contract_id = '150002'

            if registry == Settings.ONNIX_REGISTRY:
                return None

            print registry, contract_id
            url = '%(host)s:%(port)s%(endpoint)s' % dict(
                host=Settings.LICENCE_HOSTNAME,
                port=Settings.LICENCE_HOSTPORT,
                endpoint=Settings.LICENCE_ENDPOINT)

            from xmlrpclib import ServerProxy
            server = ServerProxy(url)
            contract = server.contract(registry, contract_id)
            return contract
        except Exception, e:
            from onx_log import onx_logger
            onx_logger().error(str(e))
            return None