Exemplo n.º 1
0
def populateDefaultUsers():
    userService = support.entityFor(IUserService)
    assert isinstance(userService, IUserService)
    userRbacService = support.entityFor(IUserRbacService)
    assert isinstance(userRbacService, IUserRbacService)

    users = userService.getAll(limit=1, q=QUser(name='Janet'))
    if not users:
        user = User()
        user.FirstName = 'Janet'
        user.LastName = 'Editor'
        user.EMail = '*****@*****.**'
        user.Name = 'admin'
        user.Password = hashlib.sha512(b'a').hexdigest()
        user.Id = userService.insert(user)
    else:
        user = next(iter(users))
    userRbacService.assignRole(user.Id, blogRoleAdministratorId())

    for name in (('Andrew', 'Reporter'), ('Christine', 'Journalist')):
        users = userService.getAll(limit=1, q=QUser(name=name[0]))
        if not users:
            user = User()
            user.FirstName = name[0]
            user.LastName = name[1]
            user.EMail = '*****@*****.**' % name
            user.Name = name[1].lower()
            user.Password = hashlib.sha512(b'a').hexdigest()
            user.Id = userService.insert(user)
        else:
            user = next(iter(users))
        userRbacService.assignRole(user.Id, blogRoleCollaboratorId())
Exemplo n.º 2
0
def populateDefaultUsers():
    userService = support.entityFor(IUserService)
    assert isinstance(userService, IUserService)
    userRbacService = support.entityFor(IUserRbacService)
    assert isinstance(userRbacService, IUserRbacService)

    users = userService.getAll(limit=1, q=QUser(name='admin'))
    if not users:
        user = User()
        user.FirstName = 'Janet'
        user.LastName = 'Editor'
        user.EMail = '*****@*****.**'
        user.Name = 'admin'
        user.Password = hashlib.sha512(b'a').hexdigest()
        user.Id = userService.insert(user)
    else: user = next(iter(users))
    userRbacService.assignRole(user.Id, blogRoleAdministratorId())

    for name in (('Andrew', 'Reporter'), ('Christine', 'Journalist')):
        loginName = name[1].lower()
        users = userService.getAll(limit=1, q=QUser(name=loginName))
        if not users:
            user = User()
            user.FirstName = name[0]
            user.LastName = name[1]
            user.EMail = '*****@*****.**' % name
            user.Name = loginName
            user.Password = hashlib.sha512(b'a').hexdigest()
            user.Id = userService.insert(user)
        else: user = next(iter(users))
        userRbacService.assignRole(user.Id, blogRoleCollaboratorId())
Exemplo n.º 3
0
def createArticles():

    artService = entityFor(IArticleService)
    slug = 'article-demo'
    #assert isinstance(artService, ArticleServiceAlchemy)
    
    try:
        artService.getBySlug(slug)
        return 
    #    session.query(ArticleMapped.Id).filter(ArticleMapped.Id == '1').one()[0]
    except (NoResultFound, InputError):
        theArticle = ArticleMapped()
        theArticle.CreatedOn = current_timestamp()
        theArticle.Slug = slug
        artService.insert(theArticle)
    
    artCtxService = entityFor(IArticleCtxService)

    assert isinstance(artCtxService, ArticleCtxServiceAlchemy)
    
    for typ in [1,2,3,4]:
        ctx = ArticleCtxMapped()
        ctx.Type = typ
        ctx.Content = DATA['article_content']
        ctx.Article = theArticle.Id
        artCtxService.insert(ctx)
Exemplo n.º 4
0
def createArticles():

    artService = entityFor(IArticleService)
    slug = 'article-demo'
    #assert isinstance(artService, ArticleServiceAlchemy)

    try:
        artService.getBySlug(slug)
        return
    #    session.query(ArticleMapped.Id).filter(ArticleMapped.Id == '1').one()[0]
    except (NoResultFound, InputError):
        theArticle = ArticleMapped()
        theArticle.CreatedOn = current_timestamp()
        theArticle.Slug = slug
        artService.insert(theArticle)

    artCtxService = entityFor(IArticleCtxService)

    assert isinstance(artCtxService, ArticleCtxServiceAlchemy)

    for typ in [1, 2, 3, 4]:
        ctx = ArticleCtxMapped()
        ctx.Type = typ
        ctx.Content = DATA['article_content']
        ctx.Article = theArticle.Id
        artCtxService.insert(ctx)
Exemplo n.º 5
0
def populateBlogAdministratorRole():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)
    rightService = support.entityFor(IRightService)
    assert isinstance(rightService, IRightService)
    for right in rightService.getAll():
        assert isinstance(right, Right)
        roleService.assignRight(blogRoleAdministratorId(), right.Id)
    roleService.assignRole(rootRoleId(), blogRoleAdministratorId())
Exemplo n.º 6
0
def populateCollaboratorRole():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)
    rightService = support.entityFor(IRightService)
    assert isinstance(rightService, IRightService)
    roleService.assignRight(blogRoleCollaboratorId(), rightService.getByName(aclType().name, rightLivedeskView().name).Id)
    roleService.assignRight(blogRoleCollaboratorId(), rightService.getByName(aclType().name, rightManageOwnPost().name).Id)
    roleService.assignRight(blogRoleCollaboratorId(), rightService.getByName(aclType().name, rightMediaArchiveView().name).Id)
    roleService.assignRole(blogRoleAdministratorId(), blogRoleCollaboratorId())
Exemplo n.º 7
0
def populateRootUser():
    userService = support.entityFor(IUserService)
    assert isinstance(userService, IUserService)
    userRbacService = support.entityFor(IUserRbacService)
    assert isinstance(userRbacService, IUserRbacService)
    
    users = userService.getAll(limit=1, q=QUser(name='Janet'))
    if not users:
        user = User()
        user.Name = 'root'
        user.Password = hashlib.sha512(b'root').hexdigest()
        user.Id = userService.insert(user)
    else: user = users[0]
    
    userRbacService.assignRole(user.Id, rootRoleId())
Exemplo n.º 8
0
def populateBlogAdministratorRole():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)
    rightService = support.entityFor(IRightService)
    assert isinstance(rightService, IRightService)
    for right in rightService.getAll():
        assert isinstance(right, Right)
        if right.Name == rightRequestsInspection().name: continue
        roleService.assignRight(blogRoleAdministratorId(), right.Id)
    roleService.assignRole(rootRoleId(), blogRoleAdministratorId())
    q = QRight()
    q.name = rightRequestsInspection().name
    for right in rightService.getAll(q=q):
        assert isinstance(right, Right)
        roleService.assignRight(rootRoleId(), right.Id)
Exemplo n.º 9
0
def populateBlogAdministratorRole():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)
    rightService = support.entityFor(IRightService)
    assert isinstance(rightService, IRightService)
    for right in rightService.getAll():
        assert isinstance(right, Right)
        if right.Name == rightRequestsInspection().name: continue
        roleService.assignRight(blogRoleAdministratorId(), right.Id)
    roleService.assignRole(rootRoleId(), blogRoleAdministratorId())
    q = QRight()
    q.name = rightRequestsInspection().name
    for right in rightService.getAll(q=q):
        assert isinstance(right, Right)
        roleService.assignRight(rootRoleId(), right.Id)
Exemplo n.º 10
0
def deploy():
    loadPlugins()
    if not os.path.isfile(configurations_file_path()):
        print('The configuration file "%s" doesn\'t exist, create one by running the the application '
              'with "-dump" option' % configurations_file_path())
        sys.exit(1)
    with open(configurations_file_path(), 'r') as f: config = load(f)

    PACKAGE_EXTENDER.addFreezedPackage('__plugin__.')
    pluginModules = aop.modulesIn('__plugin__.**')
    for module in pluginModules.load().asList():
        if not isPackage(module) and re.match('__plugin__\\.[^\\.]+$', module.__name__):
            raise SetupError('The plugin setup module %r is not allowed directly in the __plugin__ package it needs '
                             'to be in a sub package' % module.__name__)

    assembly = ioc.open(pluginModules, config=config)
    try:
        assembly.processStart()
        from __plugin__.plugin.registry import services
        services = services()
    finally: ioc.deactivate()

    try: import application
    except ImportError: raise SetupError('Cannot access the application module')
    resourcesRegister = entityFor(IResourcesRegister, application.assembly)
    assert isinstance(resourcesRegister, IResourcesRegister), 'There is no resource register for the services'

    assert log.debug('Registered REST services:\n\t%s', '\n\t'.join(str(srv) for srv in services)) or True
    for service in services:
        resourcesRegister.register(service)
Exemplo n.º 11
0
def fullAccessIPs():
    if not options.isFlag(FLAG_FULL_IP): return

    serviceGateway = entityFor(IGatewayService)
    assert isinstance(serviceGateway, IGatewayService)

    if options.addIPs:
        for ip in options.addIPs:
            gateway = Custom()
            gateway.Name = 'full_access_%s' % ip
            gateway.Clients = [
                '\.'.join(mark.replace('*', '\d+') for mark in ip.split('.'))
            ]
            try:
                serviceGateway.insert(gateway)
            except:
                log.info('IP \'%s\' already present', ip)
            else:
                log.info('IP \'%s\' added', ip)

    if options.remIPs:
        for ip in options.remIPs:
            if serviceGateway.delete('full_access_%s' % ip):
                log.info('IP \'%s\' removed', ip)
            else:
                log.info('IP \'%s\' is not present', ip)
Exemplo n.º 12
0
def populateVersionConfig():
    creator = alchemySessionCreator()
    session = creator()
    assert isinstance(session, Session)

    generalSettingService = support.entityFor(IGeneralSettingService)
    assert isinstance(generalSettingService, IGeneralSettingService)

    generalSetting = GeneralSetting()
    generalSetting.Group = "version"

    if session.query(GeneralSettingMapped).filter(GeneralSettingMapped.Key == "major").count() == 0:
        generalSetting.Key = "major"
        generalSetting.Value = "1"
        generalSettingService.insert(generalSetting)

    if session.query(GeneralSettingMapped).filter(GeneralSettingMapped.Key == "minor").count() == 0:
        generalSetting.Key = "minor"
        generalSetting.Value = "6"
        generalSettingService.insert(1, generalSetting)

    if session.query(GeneralSettingMapped).filter(GeneralSettingMapped.Key == "revision").count() == 0:
        generalSetting.Key = "revision"
        generalSetting.Value = "0"
        generalSettingService.insert(1, generalSetting)
Exemplo n.º 13
0
            def followWiring():
                from ally.container.support import entityFor
                wiring = Wiring.wiringOf(value.__class__)
                if wiring:
                    assert isinstance(wiring,
                                      Wiring), 'Invalid wiring %s' % wiring
                    for wentity in wiring.entities:
                        assert isinstance(wentity, WireEntity)
                        if wentity.name not in value.__dict__:
                            try:
                                setattr(value, wentity.name,
                                        entityFor(wentity.type, wentity.name))
                            except:
                                raise SetupError(
                                    'Cannot solve wiring \'%s\' at: %s' %
                                    (wentity.name,
                                     locationStack(value.__class__)))

                    mapping = wirings.get(wiring)
                    if mapping:
                        assert isinstance(mapping,
                                          dict), 'Invalid mapping %s' % mapping
                        for wconfig in wiring.configurations:
                            assert isinstance(wconfig, WireConfig)
                            if wconfig.name not in value.__dict__:
                                name = mapping.get(wconfig.name)
                                if name is not None:
                                    setattr(value, wconfig.name,
                                            assembly.processForName(name))

                if followUp: followUp()
Exemplo n.º 14
0
def userServiceUpdate():
    class AutoRolesProxy(IProxyHandler):
        ''' Automatically assign roles to new created users.'''
         
        def __init__(self, userRbacService):
            self.userRbacService = userRbacService
         
        def handle(self, execution):
            userId = execution.invoke()
            self.userRbacService.addRole(userId, 'Admin')
            return userId
             
    userService = support.entityFor(IUserService)
    handler = AutoRolesProxy(support.entityFor(IUserRbacService))
    handler = ProxyFilter(handler, 'insert')
    registerProxyHandler(handler, userService)
Exemplo n.º 15
0
def populateVersionConfig(): 
    creator = alchemySessionCreator()
    session = creator()
    assert isinstance(session, Session)
    
    generalSettingService = support.entityFor(IGeneralSettingService)
    assert isinstance(generalSettingService, IGeneralSettingService)    
    
    generalSetting = GeneralSetting()
    generalSetting.Group = 'version'
    
    
    if session.query(GeneralSettingMapped).filter(GeneralSettingMapped.Key == 'major').count() == 0:
        generalSetting.Key = 'major'
        generalSetting.Value = '1'
        generalSettingService.insert(generalSetting)  
    
    if session.query(GeneralSettingMapped).filter(GeneralSettingMapped.Key == 'minor').count() == 0:
        generalSetting.Key = 'minor'
        generalSetting.Value = '6'
        generalSettingService.insert(generalSetting) 
    
    if session.query(GeneralSettingMapped).filter(GeneralSettingMapped.Key == 'revision').count() == 0:
        generalSetting.Key = 'revision'
        generalSetting.Value = '0'
        generalSettingService.insert(generalSetting)    
Exemplo n.º 16
0
def populateVersionConfig():
    creator = alchemySessionCreator()
    session = creator()
    assert isinstance(session, Session)

    generalSettingService = support.entityFor(IGeneralSettingService)
    assert isinstance(generalSettingService, IGeneralSettingService)

    generalSetting = GeneralSetting()
    generalSetting.Group = 'version'

    if session.query(GeneralSettingMapped).filter(
            GeneralSettingMapped.Key == 'major').count() == 0:
        generalSetting.Key = 'major'
        generalSetting.Value = '1'
        generalSettingService.insert(generalSetting)

    if session.query(GeneralSettingMapped).filter(
            GeneralSettingMapped.Key == 'minor').count() == 0:
        generalSetting.Key = 'minor'
        generalSetting.Value = '6'
        generalSettingService.insert(generalSetting)

    if session.query(GeneralSettingMapped).filter(
            GeneralSettingMapped.Key == 'revision').count() == 0:
        generalSetting.Key = 'revision'
        generalSetting.Value = '0'
        generalSettingService.insert(generalSetting)
Exemplo n.º 17
0
def populateCollaboratorRole():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)
    roleService.assignRight(blogRoleCollaboratorId(), rightId(rightLivedeskView()))
    roleService.assignRight(blogRoleCollaboratorId(), rightId(rightManageOwnPost()))
    roleService.assignRight(blogRoleCollaboratorId(), rightId(rightMediaArchiveView()))
    roleService.assignRight(blogRoleCollaboratorId(), rightId(rightMediaArchiveUpload()))
    roleService.assignRole(blogRoleAdministratorId(), blogRoleCollaboratorId())
Exemplo n.º 18
0
def populateCollaboratorRole():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)
    roleService.assignRight(blogRoleCollaboratorId(), rightId(rightLivedeskView()))
    roleService.assignRight(blogRoleCollaboratorId(), rightId(rightManageOwnPost()))
    roleService.assignRight(blogRoleCollaboratorId(), rightId(rightMediaArchiveView()))
    roleService.assignRight(blogRoleCollaboratorId(), rightId(rightMediaArchiveUpload()))
    roleService.assignRole(blogRoleAdministratorId(), blogRoleCollaboratorId())
Exemplo n.º 19
0
def populateDefaulyGateways():
    serviceGateway = entityFor(IGatewayService)
    assert isinstance(serviceGateway, IGatewayService)
    
    for data in defaultGateways():
        custom = copyContainer(data, Custom())
        assert isinstance(custom, Custom)
        try: serviceGateway.insert(custom)
        except InputError: log.info('Gateway \'%s\' already exists' % custom.Name)
Exemplo n.º 20
0
def populateRootUser():
    userService = support.entityFor(IUserService)
    assert isinstance(userService, IUserService)
    userRbacService = support.entityFor(IUserRbacService)
    assert isinstance(userRbacService, IUserRbacService)
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)

    users = userService.getAll(limit=1, q=QUser(name='root'))
    if not users:
        user = User()
        user.Name = 'root'
        user.Password = hashlib.sha512(b'root').hexdigest()
        user.Id = userService.insert(user)
    else:
        user = users[0]

    userRbacService.assignRole(user.Id, roleService.getByName(NAME_ROOT).Id)
Exemplo n.º 21
0
def insertSource(name):
    sourcesService = entityFor(ISourceService)
    assert isinstance(sourcesService, ISourceService)
    srcs = sourcesService.getAll(q=QSource(name=name))
    if srcs: src = next(iter(srcs)).Id
    else:
        src = Source()
        src.Name = name
        src.IsModifiable, src.URI, src.Type, src.Key = False, '', '', ''
        src = sourcesService.insert(src)

    collaboratorService = entityFor(ICollaboratorService)
    assert isinstance(collaboratorService, ICollaboratorService)
    colls = collaboratorService.getAll(qs=QSource(name=name))
    if not colls:
        coll = Collaborator()
        coll.User = None
        coll.Source = src
        collaboratorService.insert(coll)
Exemplo n.º 22
0
def createBlogAdmins():
    blogAdminService = entityFor(IBlogAdminService)
    assert isinstance(blogAdminService, IBlogAdminService)
    for name, blog in BLOG_ADMINS.items():
        blogId, userId = getBlogsIds()[blog], getUsersIds()[name]
        blgs = blogAdminService.getAll(blogId)
        for blg in blgs:
            if blg.Id == userId: break
        else:
            blogAdminService.addAdmin(blogId, userId)
Exemplo n.º 23
0
def createBlogAdmins():
    blogAdminService = entityFor(IBlogAdminService)
    assert isinstance(blogAdminService, IBlogAdminService)
    for name, blog in BLOG_ADMINS.items():
        blogId, userId = getBlogsIds()[blog], getUsersIds()[name]
        blgs = blogAdminService.getAll(blogId)
        for blg in blgs:
            if blg.Id == userId: break
        else:
            blogAdminService.addAdmin(blogId, userId)
Exemplo n.º 24
0
def getLanguagesIds():
    languageService = entityFor(ILanguageService)
    assert isinstance(languageService, ILanguageService)
    languages = { lang.Code: lang.Id for lang in languageService.getAll() }
    for code in LANGUAGES:
        if code not in languages:
            lang = LanguageEntity()
            lang.Code = code
            languages[code] = languageService.insert(lang)
    return languages
Exemplo n.º 25
0
def insertSource(name):
    sourcesService = entityFor(ISourceService)
    assert isinstance(sourcesService, ISourceService)
    srcs = sourcesService.getAll(q=QSource(name=name))
    if srcs: src = next(iter(srcs)).Id
    else:
        src = Source()
        src.Name = name
        src.IsModifiable, src.URI, src.Type, src.Key = False, '', '', ''
        src = sourcesService.insert(src)

    collaboratorService = entityFor(ICollaboratorService)
    assert isinstance(collaboratorService, ICollaboratorService)
    colls = collaboratorService.getAll(qs=QSource(name=name))
    if not colls:
        coll = Collaborator()
        coll.User = None
        coll.Source = src
        collaboratorService.insert(coll)
Exemplo n.º 26
0
def createBlogCollaborators():
    blogCollaboratorService = entityFor(IBlogCollaboratorService)
    assert isinstance(blogCollaboratorService, IBlogCollaboratorService)
    for name, blog in BLOG_COLLABORATORS.items():
        blogId, collId = getBlogsIds()[blog], getCollaboratorsIds()[name]
        blgs = blogCollaboratorService.getAll(blogId)
        for blg in blgs:
            if blg.Id == collId: break
        else:
            blogCollaboratorService.addCollaboratorAsDefault(blogId, collId)
Exemplo n.º 27
0
def createBlogAdmins():
    blogCollaboratorService = entityFor(IBlogCollaboratorService)
    assert isinstance(blogCollaboratorService, IBlogCollaboratorService)
    for name, blog in BLOG_ADMINS.items():
        blogId, collId = getBlogsIds()[blog], getCollaboratorsIds()[name]
        blgs = blogCollaboratorService.getAll(blogId)
        for blg in blgs:
            if blg.Id == collId: break
        else:
            blogCollaboratorService.addCollaborator(blogId, collId, 'Administrator')
Exemplo n.º 28
0
def populateRootRole():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)

    roles = roleService.getAll(limit=1, q=QRole(name=NAME_ROOT))
    if not roles:
        rootRole = Role()
        rootRole.Name = NAME_ROOT
        rootRole.Description = NC_('security role', 'Default role that provides access to all available roles and rights')
        roleService.insert(rootRole)
Exemplo n.º 29
0
def createBlogCollaborators():
    blogCollaboratorService = entityFor(IBlogCollaboratorService)
    assert isinstance(blogCollaboratorService, IBlogCollaboratorService)
    for name, blog in BLOG_COLLABORATORS.items():
        blogId, collId = getBlogsIds()[blog], getCollaboratorsIds()[name]
        blgs = blogCollaboratorService.getAll(blogId)
        for blg in blgs:
            if blg.Id == collId: break
        else:
            blogCollaboratorService.addCollaborator(blogId, collId)
Exemplo n.º 30
0
def getLanguagesIds():
    languageService = entityFor(ILanguageService)
    assert isinstance(languageService, ILanguageService)
    languages = {lang.Code: lang.Id for lang in languageService.getAll()}
    for code in LANGUAGES:
        if code not in languages:
            lang = LanguageEntity()
            lang.Code = code
            languages[code] = languageService.insert(lang)
    return languages
Exemplo n.º 31
0
def populateRights():
    '''
    Synchronize the active acl rights with the database rights.
    '''
    rightTypeService = support.entityFor(IRightTypeService)
    assert isinstance(rightTypeService, IRightTypeService)
    rightService = support.entityFor(IRightService)
    assert isinstance(rightService, IRightService)
    for aclType in acl().activeTypes(resourcesRoot()):
        assert isinstance(aclType, TypeAcl), 'Invalid acl type %s' % aclType
        
        try: rightType = rightTypeService.getByName(aclType.name)
        except InputError:
            rightType = RightType()
            rightType.Name = aclType.name
            rightType.Description = aclType.description
            rightTypeId = rightTypeService.insert(rightType)
        else:
            # Update the description if is the case
            assert isinstance(rightType, RightType)
            if rightType.Description != aclType.description:
                rightType.Description = aclType.description
                rightTypeService.update(rightType)
            rightTypeId = rightType.Id
        
        aclRights = {right.name: right for right in aclType.activeRights(resourcesRoot())}
        for right in rightService.getAll(rightTypeId):
            assert isinstance(right, Right), 'Invalid right %s' % right
        
            aclRight = aclRights.pop(right.Name, None)
            if aclRight:
                assert isinstance(aclRight, RightBase)
                # Update the description if is the case
                if right.Description != aclRight.description:
                    right.Description = aclRight.description
                    rightService.update(right)
        
        for aclRight in aclRights.values():
            right = Right()
            right.Type = rightTypeId
            right.Name = aclRight.name
            right.Description = aclRight.description
            rightService.insert(right)
Exemplo n.º 32
0
def populateDefaulyGateways():
    serviceGateway = entityFor(IGatewayService)
    assert isinstance(serviceGateway, IGatewayService)

    for data in defaultGateways():
        custom = copyContainer(data, Custom())
        assert isinstance(custom, Custom)
        try:
            serviceGateway.insert(custom)
        except InputError:
            log.info('Gateway \'%s\' already exists' % custom.Name)
Exemplo n.º 33
0
def populateUsersRoles():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)
    
    try: roleService.getById('Admin')
    except InputError:
        role = Role()
        role.Name = 'Admin'
        role.Description = 'Full access role'
        roleService.insert(role)
        
Exemplo n.º 34
0
def getBlogTypesIds():
    blogTypeService = entityFor(IBlogTypeService)
    assert isinstance(blogTypeService, IBlogTypeService)
    blogTypes = {}
    for name in BLOG_TYPES:
        blgTypes = blogTypeService.getAll(q=QBlogType(name=name))
        if blgTypes: blogTypes[name] = next(iter(blgTypes)).Id
        else:
            blgType = BlogType()
            blgType.Name = name
            blogTypes[name] = blogTypeService.insert(blgType)
    return blogTypes
Exemplo n.º 35
0
def blogRoleEditorId():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)

    roles = roleService.getAll(limit=1, q=QRole(name='Editor'))
    try: editor = next(iter(roles))
    except StopIteration:
        editor = Role()
        editor.Name = NC_('security role', 'Editor')
        editor.Description = NC_('security role', 'Role that allows editor stuff')
        return roleService.insert(editor)
    return editor.Id
Exemplo n.º 36
0
def insertTheme():
    s = entityFor(IBlogThemeService)
    assert isinstance(s, IBlogThemeService)
    for name in ("big-screen",):
        q = QBlogTheme(name=name)
        l = s.getAll(q=q)
        if not l:
            t = BlogTheme()
            t.Name = name
            t.URL = cdmGUI().getURI(themes_path() + "/" + name, "http")
            t.IsLocal = True
            s.insert(t)
Exemplo n.º 37
0
def rootRoleId():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)

    roles = roleService.getAll(limit=1, q=QRole(name='ROOT'))
    try: rootRole = next(iter(roles))
    except StopIteration:
        rootRole = Role()
        rootRole.Name = NC_('security role', 'ROOT')
        rootRole.Description = NC_('security role', 'Default role that provides access to all available roles and rights')
        return roleService.insert(rootRole)
    return rootRole.Id
Exemplo n.º 38
0
def getBlogTypesIds():
    blogTypeService = entityFor(IBlogTypeService)
    assert isinstance(blogTypeService, IBlogTypeService)
    blogTypes = {}
    for name in BLOG_TYPES:
        blgTypes = blogTypeService.getAll(q=QBlogType(name=name))
        if blgTypes: blogTypes[name] = next(iter(blgTypes)).Id
        else:
            blgType = BlogType()
            blgType.Name = name
            blogTypes[name] = blogTypeService.insert(blgType)
    return blogTypes
Exemplo n.º 39
0
def blogRoleAdministratorId():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)

    roles = roleService.getAll(limit=1, q=QRole(name='Administrator'))
    try: admin = next(iter(roles))
    except StopIteration:
        admin = Role()
        admin.Name = NC_('security role', 'Administrator')
        admin.Description = NC_('security role', 'Role that allows all rights')
        return roleService.insert(admin)
    return admin.Id
Exemplo n.º 40
0
def cleanup():
    timeout, cleanup = cleanup_timeout(), support.entityFor(IAuthenticationService)
    # TODO: fix this after merge with devel

    schedule = scheduler(time.time, time.sleep)
    def executeCleanup():
        assert isinstance(cleanup, ICleanupService)
        cleanup.cleanExpired()
        schedule.enter(timeout, 1, executeCleanup, ())

    schedule.enter(timeout, 1, executeCleanup, ())
    Thread(target=schedule.run, name='Cleanup authentications/sessions thread').start()
Exemplo n.º 41
0
def blogRoleCollaboratorId():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)

    roles = roleService.getAll(limit=1, q=QRole(name='Collaborator'))
    try: collaborator = next(iter(roles))
    except StopIteration:
        collaborator = Role()
        collaborator.Name = NC_('security role', 'Collaborator')
        collaborator.Description = NC_('security role', 'Role that allows submit to desk and edit his own posts')
        return roleService.insert(collaborator)
    return collaborator.Id
Exemplo n.º 42
0
def blogRoleCollaboratorId():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)

    roles = roleService.getAll(limit=1, q=QRole(name='Collaborator'))
    try: collaborator = next(iter(roles))
    except StopIteration:
        collaborator = Role()
        collaborator.Name = NC_('security role', 'Collaborator')
        collaborator.Description = NC_('security role', 'Role that allows submit to desk and edit his own posts')
        return roleService.insert(collaborator)
    return collaborator.Id
Exemplo n.º 43
0
def insertTheme():
    s = entityFor(IBlogThemeService)
    assert isinstance(s, IBlogThemeService)
    for name in ('big-screen', ):
        q = QBlogTheme(name=name)
        l = s.getAll(q=q)
        if not l:
            t = BlogTheme()
            t.Name = name
            t.URL = cdmGUI().getURI(themes_path() + '/' + name, 'http')
            t.IsLocal = True
            s.insert(t)
Exemplo n.º 44
0
def blogRoleAdministratorId():
    roleService = support.entityFor(IRoleService)
    assert isinstance(roleService, IRoleService)

    roles = roleService.getAll(limit=1, q=QRole(name='Administrator'))
    try: admin = next(iter(roles))
    except StopIteration:
        admin = Role()
        admin.Name = NC_('security role', 'Administrator')
        admin.Description = NC_('security role', 'Role that allows all rights')
        return roleService.insert(admin)
    return admin.Id
Exemplo n.º 45
0
def insertThemes():
    s = entityFor(IBlogThemeService)
    assert isinstance(s, IBlogThemeService)
    for name in ('default', 'tageswoche','tageswoche-multi', 'tageswoche-solo','stt', 'genapp', 'big-screen', 'zeit', 'ctkepr', 'ctkeu', 'ctkih', 'ctkno', 'ctkr', 'aamulehti', 'satakansa', 'okfn', 'sasa', 'sasa-light', 'ksml', 'ksml-light', 'sz', 'rp'):
        q = QBlogTheme()
        q.name = name
        l = s.getAll(q=q)
        if not l:
            t = BlogTheme()
            t.Name = name
            t.URL = cdmGUI().getURI(embed_themes_path() + '/' + name, 'http')
            t.IsLocal = True
            s.insert(t)
Exemplo n.º 46
0
def insertThemes():
    s = entityFor(IBlogThemeService)
    assert isinstance(s, IBlogThemeService)
    for name in ('default', 'tageswoche','tageswoche-multi', 'tageswoche-solo','stt', 'genapp', 'big-screen', 'zeit', 'ctkepr', 'ctkeu', 'ctkih', 'ctkno', 'ctkr', 'aamulehti', 'satakansa', 'okfn', 'sasa', 'sasa-light', 'ksml', 'ksml-light', 'sz', 'rp'):
        q = QBlogTheme()
        q.name = name
        l = s.getAll(q=q)
        if not l:
            t = BlogTheme()
            t.Name = name
            t.URL = cdmGUI().getURI(themes_path() + '/' + name, 'http')
            t.IsLocal = True
            s.insert(t)
Exemplo n.º 47
0
def insertThemes():
    s = entityFor(IBlogThemeService)
    assert isinstance(s, IBlogThemeService)
    for name in ('default', 'generic'):
        q = QBlogTheme()
        q.name = name
        l = s.getAll(q=q)
        if not l:
            t = BlogTheme()
            t.Name = name
            t.URL = cdmGUI().getURI(embed_themes_path() + '/' + name, 'http')
            t.IsLocal = True
            s.insert(t)
Exemplo n.º 48
0
def insertThemes():
    s = entityFor(IBlogThemeService)
    assert isinstance(s, IBlogThemeService)
    for name in ('default', 'tageswoche', 'stt'):
        q = QBlogTheme()
        q.name = name
        l = s.getAll(q=q)
        if not l:
            t = BlogTheme()
            t.Name = name
            t.URL = cdmGUI().getURI(themes_path() + '/' + name, 'http')
            t.IsLocal = True
            s.insert(t)
Exemplo n.º 49
0
def insertThemes():
    s = entityFor(IBlogThemeService)
    assert isinstance(s, IBlogThemeService)
    for name in ("default", "generic"):
        q = QBlogTheme()
        q.name = name
        l = s.getAll(q=q)
        if not l:
            t = BlogTheme()
            t.Name = name
            t.URL = cdmGUI().getURI(embed_themes_path() + "/" + name, "http")
            t.IsLocal = True
            s.insert(t)
Exemplo n.º 50
0
def createBlogTypePosts():
    blogTypePostService = entityFor(IBlogTypePostService)
    assert isinstance(blogTypePostService, IBlogTypePostService)
    for data in BLOG_TYPE_POSTS:
        pst = BlogTypePostPersist()
        blogType, pst.Type, creator, author, pst.Name, pst.Content = data
        blogTypeId = getBlogTypesIds()[blogType]
        exists = False
        for post in blogTypePostService.getAll(blogTypeId):
            if post.Content == pst.Content: exists = True; break
        if not exists:
            pst.Creator = getUsersIds()[creator]
            if author: pst.Author = getCollaboratorsIds()[author]
            blogTypePostService.insert(blogTypeId, pst)
Exemplo n.º 51
0
def getSourcesIds():
    sourcesService = entityFor(ISourceService)
    assert isinstance(sourcesService, ISourceService)
    sources = {}
    for name in SOURCES:
        srcs = sourcesService.getAll(q=QSource(name=name))
        if srcs: sources[name] = next(iter(srcs)).Id
        else:
            src = Source()
            src.Name = name
            src.IsModifiable, src.URI, src.Type, src.Key = SOURCES[name]
            createSourceType(src.Type)
            sources[name] = sourcesService.insert(src)
    return sources
Exemplo n.º 52
0
def getUsersIds():
    userService = entityFor(IUserService)
    assert isinstance(userService, IUserService)
    if not _cache_users:
        users = _cache_users
        for name in USERS:
            usrs = userService.getAll(adminId=None, q=QUser(name=name))
            if usrs: users[name] = next(iter(usrs)).Id
            else:
                usr = User()
                usr.Name = name
                usr.Password = hashlib.sha512(b'a').hexdigest()
                usr.FirstName, usr.LastName, usr.EMail = USERS[name]
                users[name] = userService.insert(adminId=None, user=usr)
    return _cache_users
Exemplo n.º 53
0
def getBlogsIds():
    blogService = entityFor(IBlogService)
    assert isinstance(blogService, IBlogService)
    blogs = {}
    for name, data in defaultBlogs().items():
        blgs = blogService.getAll(q=QBlog(title=name))
        if blgs: blogs[name] = next(iter(blgs)).Id
        else:
            blg = Blog()
            blg.Title = name
            blogType, usrName, langCode, blg.Description, blg.CreatedOn, blg.LiveOn = data
            blg.Type = getBlogTypesIds()[blogType]
            blg.Creator = getUsersIds()[usrName]
            blg.Language = getLanguagesIds()[langCode]
            blogs[name] = blogService.insert(blg)
    return blogs
Exemplo n.º 54
0
def cleanup():
    if not perform_cleanup(): return
    timeout, cleanup = cleanup_timeout(), support.entityFor(ICleanupService)

    schedule = scheduler(time.time, time.sleep)

    def executeCleanup():
        assert isinstance(cleanup, ICleanupService)
        cleanup.cleanExpired()
        schedule.enter(timeout, 1, executeCleanup, ())

    schedule.enter(timeout, 1, executeCleanup, ())
    scheduleRunner = Thread(name='Cleanup authentications/sessions thread',
                            target=schedule.run)
    scheduleRunner.daemon = True
    scheduleRunner.start()
Exemplo n.º 55
0
    def rightId(aclRight):
        '''
        Provides the security right id for the provided acl right.
        
        @param aclRight: RightAcl
            The acl right to provide the id for.
        @return: integer
            The id of the security right.
        '''
        assert isinstance(aclRight, RightAcl), 'Invalid right %s' % aclRight
        assert isinstance(aclRight.type,
                          TypeAcl), 'Invalid right %s, has no type' % aclRight

        rightService = support.entityFor(IRightService)
        assert isinstance(rightService, IRightService)

        return rightService.getByName(aclRight.type.name, aclRight.name).Id
Exemplo n.º 56
0
def cleanup():
    if not perform_group_cleanup(): return
    timeout, cleanup = cleanup_group_timeout(), support.entityFor(
        IBlogCollaboratorGroupCleanupService)

    schedule = scheduler(time.time, time.sleep)

    def executeCleanup():
        assert isinstance(cleanup, IBlogCollaboratorGroupCleanupService)
        cleanup.cleanExpired()
        schedule.enter(timeout, 1, executeCleanup, ())

    schedule.enter(timeout, 1, executeCleanup, ())
    scheduleRunner = Thread(name='Cleanup blog collaborator groups thread',
                            target=schedule.run)
    scheduleRunner.daemon = True
    scheduleRunner.start()
Exemplo n.º 57
0
def populateVersionConfig():
    generalSettingService = support.entityFor(IGeneralSettingService)
    assert isinstance(generalSettingService, IGeneralSettingService)

    generalSetting = GeneralSetting()
    generalSetting.Group = 'version'

    generalSetting.Key = 'major'
    generalSetting.Value = '1'
    generalSettingService.insert(generalSetting)

    generalSetting.Key = 'minor'
    generalSetting.Value = '6'
    generalSettingService.insert(generalSetting)

    generalSetting.Key = 'revision'
    generalSetting.Value = '0'
    generalSettingService.insert(generalSetting)
Exemplo n.º 58
0
def getBlogsIds():
    blogService = entityFor(IBlogService)
    assert isinstance(blogService, IBlogService)
    if not _cache_blogs:
        blogs = _cache_blogs
        for name in BLOGS:
            blgs = blogService.getAll(q=QBlog(title=name))
            if blgs: blogs[name] = next(iter(blgs)).Id
            else:
                blg = Blog()
                blg.Title = name
                blogType, usrName, langCode, blg.Description, blg.CreatedOn, blg.LiveOn = BLOGS[
                    name]
                blg.Type = getBlogTypesIds()[blogType]
                blg.Creator = getUsersIds()[usrName]
                blg.Language = getLanguagesIds()[langCode]
                blogs[name] = blogService.insert(blg)
    return _cache_blogs