コード例 #1
0
def addResourceTarget(module,type,name,kwargs):
    pages.require("/admin/modules.edit")
    
    #Create a permission
    if type == 'permission':
        with modulesLock:
            if kwargs['name'] in ActiveModules[module]:
                raise cherrypy.HTTPRedirect("/errors/alreadyexists")
            else:   
                ActiveModules[module] [kwargs['name']]= {"resource-type":"permission","description":kwargs['description']}
                #has its own lock
                auth.importPermissionsFromModules() #sync auth's list of permissions 
                raise cherrypy.HTTPRedirect("/modules/module/" +util.url(module)+ '/resource/' + util.url(name) )
        
    if type == 'event':
        with modulesLock:
           if kwargs['name'] not in ActiveModules[module]:
                ActiveModules[module] [kwargs['name']]= {"resource-type":"event","trigger":"False","action":"pass",
                "once":True}
                #newevt maintains a cache of precompiled events that must be kept in sync with
                #the modules
                newevt.updateOneEvent(kwargs['name'],module)
                raise cherrypy.HTTPRedirect("/modules/module/"+util.url(module)+'/resource/'+util.url(name))
           else:
                raise cherrypy.HTTPRedirect("/errors/alreadyexists")

    if type == 'page':
        with modulesLock:
            if kwargs['name'] not in ActiveModules[module]:
                ActiveModules[module][kwargs['name']]= {"resource-type":"page","body":"Content here",'no-navheader':True}
                #newevt maintains a cache of precompiled events that must be kept in sync with
                #the modules
                raise cherrypy.HTTPRedirect("/modules/module/"+util.url(module)+'/resource/'+util.url(name))
            else:
                raise cherrypy.HTTPRedirect("/errors/alreadyexists")  
コード例 #2
0
def bookkeeponemodule(module):
    """Given the name of one module that has been copied to activemodules but nothing else,
    let the rest of the system know the module is there."""
    scopes[module] = obj()
    for i in ActiveModules[module]:
        if ActiveModules[module][i]['resource-type'] == 'page':
            usrpages.updateOnePage(i,module)
        if ActiveModules[module][i]['resource-type'] == 'event':
           newevt.updateOneEvent(i,module)
コード例 #3
0
def bookkeeponemodule(module):
    """Given the name of one module that has been copied to activemodules but nothing else,
    let the rest of the system know the module is there."""
    scopes[module] = obj()
    for i in ActiveModules[module]:
        if ActiveModules[module][i]['resource-type'] == 'page':
            usrpages.updateOnePage(i, module)
        if ActiveModules[module][i]['resource-type'] == 'event':
            newevt.updateOneEvent(i, module)
コード例 #4
0
def resourceUpdateTarget(module, resource, kwargs):
    pages.require("/admin/modules.edit")
    global moduleschanged
    moduleschanged = True
    with modulesLock:
        t = ActiveModules[module][resource]['resource-type']
        resourceobj = ActiveModules[module][resource]

        if t == 'permission':
            resourceobj['description'] = kwargs['description']
            #has its own lock
            auth.importPermissionsFromModules(
            )  #sync auth's list of permissions

        if t == 'event':
            e = newevt.Event(kwargs['trigger'], kwargs['action'],
                             {})  #Test compile, throw error on fail.
            resourceobj['trigger'] = kwargs['trigger']
            resourceobj['action'] = kwargs['action']
            resourceobj['setup'] = kwargs['setup']
            resourceobj['priority'] = max([int(kwargs['priority']), 0])
            resourceobj['continual'] = 'continual' in kwargs
            resourceobj['rate-limit'] = float(kwargs['ratelimit'])
            #I really need to do something about this possibly brittle bookkeeping system
            #But anyway, when the active modules thing changes we must update the newevt cache thing.
            newevt.updateOneEvent(resource, module)

        if t == 'page':
            resourceobj['body'] = kwargs['body']
            resourceobj['no-navheader'] = 'no-navheader' in kwargs
            resourceobj['no-header'] = 'no-header' in kwargs
            resourceobj['dont-show-in-index'] = 'dont-show-in-index' in kwargs
            #Method checkboxes
            resourceobj['require-method'] = []
            if 'allow-GET' in kwargs:
                resourceobj['require-method'].append('GET')
            if 'allow-POST' in kwargs:
                resourceobj['require-method'].append('POST')
            #permission checkboxes
            resourceobj['require-permissions'] = []
            for i in kwargs:
                #Since HTTP args don't have namespaces we prefix all the permission checkboxes with permission
                if i[:10] == 'Permission':
                    if kwargs[i] == 'true':
                        resourceobj['require-permissions'].append(i[10:])
            usrpages.updateOnePage(resource, module)

    messagebus.postMessage(
        "/system/notifications", "User " + pages.getAcessingUser() +
        " modified resource " + resource + " of module " + module)
    #Return user to the module page
    raise cherrypy.HTTPRedirect(
        "/modules/module/" +
        util.url(module))  #+'/resource/'+util.url(resource))
コード例 #5
0
def addResourceTarget(module, type, name, kwargs):
    pages.require("/admin/modules.edit")
    global moduleschanged
    moduleschanged = True

    def insertResource(r):
        ActiveModules[module][kwargs['name']] = r

    with modulesLock:
        #Check if a resource by that name is already there
        if kwargs['name'] in ActiveModules[module]:
            raise cherrypy.HTTPRedirect("/errors/alreadyexists")

        #Create a permission
        if type == 'permission':
            insertResource({
                "resource-type": "permission",
                "description": kwargs['description']
            })
            #has its own lock
            auth.importPermissionsFromModules(
            )  #sync auth's list of permissions

        if type == 'event':
            insertResource({
                "resource-type": "event",
                "trigger": "False",
                "action": "pass",
                "once": True
            })
            #newevt maintains a cache of precompiled events that must be kept in sync with
            #the modules
            newevt.updateOneEvent(kwargs['name'], module)

        if type == 'page':
            insertResource({
                "resource-type": "page",
                "body": "Content here",
                'no-navheader': True
            })
            usrpages.updateOnePage(kwargs['name'], module)

        messagebus.postMessage(
            "/system/notifications",
            "User " + pages.getAcessingUser() + " added resource " +
            kwargs['name'] + " of type " + type + " to module " + module)

        #Take the user straight to the resource page
        raise cherrypy.HTTPRedirect("/modules/module/" + util.url(module) +
                                    '/resource/' + util.url(name))
コード例 #6
0
def resourceUpdateTarget(module,resource,kwargs):
    pages.require("/admin/modules.edit")
    global moduleschanged
    moduleschanged = True
    with modulesLock:
        t = ActiveModules[module][resource]['resource-type']
        resourceobj = ActiveModules[module][resource]
        
        if t == 'permission': 
            resourceobj['description'] = kwargs['description']
            #has its own lock
            auth.importPermissionsFromModules() #sync auth's list of permissions 
    
        if t == 'event':
            e = newevt.Event(kwargs['trigger'],kwargs['action'],{})#Test compile, throw error on fail.
            resourceobj['trigger'] = kwargs['trigger']
            resourceobj['action'] = kwargs['action']
            resourceobj['setup'] = kwargs['setup']
            resourceobj['priority'] = max([int(kwargs['priority']),0])
            resourceobj['continual'] = 'continual' in kwargs
            resourceobj['rate-limit'] = float(kwargs['ratelimit'])
            #I really need to do something about this possibly brittle bookkeeping system
            #But anyway, when the active modules thing changes we must update the newevt cache thing.
            newevt.updateOneEvent(resource,module)
    
        if t == 'page':
            resourceobj['body'] = kwargs['body']
            resourceobj['no-navheader'] = 'no-navheader' in kwargs
            resourceobj['no-header'] = 'no-header' in kwargs
            resourceobj['dont-show-in-index'] = 'dont-show-in-index' in kwargs
            #Method checkboxes
            resourceobj['require-method'] = []
            if 'allow-GET' in kwargs:
                resourceobj['require-method'].append('GET')
            if 'allow-POST' in kwargs:
                resourceobj['require-method'].append('POST')                
            #permission checkboxes
            resourceobj['require-permissions'] = []
            for i in kwargs:
                #Since HTTP args don't have namespaces we prefix all the permission checkboxes with permission
                if i[:10] == 'Permission':
                    if kwargs[i] == 'true':
                        resourceobj['require-permissions'].append(i[10:])
            usrpages.updateOnePage(resource,module)
            
    messagebus.postMessage("/system/notifications", "User "+ pages.getAcessingUser() + " modified resource " +
                           resource + " of module " + module)
    #Return user to the module page       
    raise cherrypy.HTTPRedirect("/modules/module/"+util.url(module))#+'/resource/'+util.url(resource))
コード例 #7
0
def addResourceTarget(module,type,name,kwargs):
    pages.require("/admin/modules.edit")
    global moduleschanged
    moduleschanged = True
    def insertResource(r):
        ActiveModules[module][kwargs['name']] = r
    
    with modulesLock:
        #Check if a resource by that name is already there
        if kwargs['name'] in ActiveModules[module]:
            raise cherrypy.HTTPRedirect("/errors/alreadyexists")
        
        #Create a permission
        if type == 'permission':
            insertResource({
                "resource-type":"permission",
                "description":kwargs['description']})
            #has its own lock
            auth.importPermissionsFromModules() #sync auth's list of permissions 
            
        if type == 'event':
            insertResource({
                "resource-type":"event",
                "trigger":"False",
                "action":"pass",
                "once":True})
            #newevt maintains a cache of precompiled events that must be kept in sync with
            #the modules
            newevt.updateOneEvent(kwargs['name'],module)
        
        if type == 'page':
                insertResource({
                    "resource-type":"page",
                    "body":"Content here",
                    'no-navheader':True})
                usrpages.updateOnePage(kwargs['name'],module)

        messagebus.postMessage("/system/notifications", "User "+ pages.getAcessingUser() + " added resource " +
                           kwargs['name'] + " of type " + type+" to module " + module)
        
        #Take the user straight to the resource page
        raise cherrypy.HTTPRedirect("/modules/module/"+util.url(module)+'/resource/'+util.url(name))
コード例 #8
0
def resourceUpdateTarget(module,resource,kwargs):
    pages.require("/admin/modules.edit")
    t = ActiveModules[module][resource]['resource-type']
    
    if t == 'permission': 
        with modulesLock:
            ActiveModules[module][resource]['description'] = kwargs['description']
        #has its own lock
        auth.importPermissionsFromModules() #sync auth's list of permissions 

    if t == 'event':
        with modulesLock:
            e = newevt.Event(kwargs['trigger'],kwargs['action'],{})#Test compile, throw error on fail.
            ActiveModules[module][resource]['trigger'] = kwargs['trigger']
            ActiveModules[module][resource]['action'] = kwargs['action']
            #I really need to do something about this possibly brittle bookkeeping system
            #But anyway, when the active modules thing changes we must update the newevt cache thing.
            newevt.updateOneEvent(resource,module)

    if t == 'page':
        with modulesLock:
            pageinquestion = ActiveModules[module][resource]
            pageinquestion['body'] = kwargs['body']
            pageinquestion['no-navheader'] = 'no-navheader' in kwargs
            #Method checkboxes
            pageinquestion['require-method'] = []
            if 'allow-GET' in kwargs:
                pageinquestion['require-method'].append('GET')
            if 'allow-POST' in kwargs:
                pageinquestion['require-method'].append('POST')                
            #permission checkboxes
            pageinquestion['require-permissions'] = []
            for i in kwargs:
                #Since HTTP args don't have namespaces we prefix all the permission checkboxes with permission
                if i[:10] == 'Permission':
                    if kwargs[i] == 'true':
                        pageinquestion['require-permissions'].append(i[10:])
    #Return user to the module page       
    raise cherrypy.HTTPRedirect("/modules/module/"+util.url(module))#+'/resource/'+util.url(resource))