Ejemplo n.º 1
0
def send_request_quotation(newadvertising, request):
    site = get_site_folder(True)
    managers = get_users_with_role(role=('AdvertisingManager', site))
    if not managers:
        managers = get_users_with_role(role=('SiteAdmin', site))

    if managers:
        localizer = request.localizer
        url = request.resource_url(newadvertising, "@@index")
        author = get_current()
        mail_template = site.get_mail_template('request_quotation')
        subject = mail_template['subject'].format(
            advertising_title=newadvertising.title)
        message = mail_template['template'].format(
            author=getattr(author, 'title', author.name),
            user_title=localizer.translate(
                _(getattr(author, 'user_title', 'The user'))),
            url=url,
            lac_title=request.root.title)
        for manager in managers:
            alert('email', [getattr(author, 'email', None)], [manager.email],
                  {'subject': subject, 'body': message})
Ejemplo n.º 2
0
def send_request_quotation(newadvertising, request):
    site = get_site_folder(True)
    managers = get_users_with_role(role=('AdvertisingManager', site))
    if not managers:
        managers = get_users_with_role(role=('SiteAdmin', site))

    if managers:
        localizer = request.localizer
        url = request.resource_url(newadvertising, "@@index")
        author = get_current()
        mail_template = site.get_mail_template('request_quotation')
        subject = mail_template['subject'].format(
            advertising_title=newadvertising.title)
        message = mail_template['template'].format(
            author=getattr(author, 'title', author.name),
            user_title=localizer.translate(
                _(getattr(author, 'user_title', 'The user'))),
            url=url,
            lac_title=request.root.title)
        for manager in managers:
            alert('email', [getattr(author, 'email', None)], [manager.email], {
                'subject': subject,
                'body': message
            })
Ejemplo n.º 3
0
 def start(self, context, request, appstruct, **kw):
     user = get_current()
     report = appstruct['_object_data']
     context.addtoproperty('reports', report)
     report.state.append('pending')
     context.state.append('reported')
     grant_roles(user=user, roles=(('Owner', report), ))
     report.setproperty('author', user)
     report.reindex()
     context.reindex()
     moderators = get_users_with_role(role='Moderator')
     alert(
         'internal', [request.root], moderators,
         internal_kind=InternalAlertKind.moderation_alert,
         subjects=[context], alert_kind='new_report')
     return {}
Ejemplo n.º 4
0
 def start(self, context, request, appstruct, **kw):
     user = get_current()
     report = appstruct['_object_data']
     context.addtoproperty('reports', report)
     report.state.append('pending')
     context.state.append('reported')
     grant_roles(user=user, roles=(('Owner', report), ))
     report.setproperty('author', user)
     report.reindex()
     context.reindex()
     moderators = get_users_with_role(role='Moderator')
     alert('internal', [request.root],
           moderators,
           internal_kind=InternalAlertKind.moderation_alert,
           subjects=[context],
           alert_kind='new_report')
     return {}
Ejemplo n.º 5
0
    def start(self, context, request, appstruct, **kw):
        preregistration = appstruct['_object_data']
        preregistration.__name__ = gen_random_token()
        preregistration.locale = my_locale_negotiator(request)
        root = getSite()
        root.addtoproperty('preregistrations', preregistration)
        deadline = DEADLINE_PREREGISTRATION * 1000
        call_id = 'persistent_' + str(get_oid(preregistration))
        push_callback_after_commit(remove_expired_preregistration_callback,
                                   deadline,
                                   call_id,
                                   root=root,
                                   preregistration=preregistration)
        preregistration.state.append('pending')
        preregistration.reindex()
        transaction.commit()
        if not getattr(root, 'moderate_registration', False):
            accept_preregistration(request, preregistration, root)
        else:
            admins = get_users_with_role(role='SiteAdmin')
            alert('internal', [root],
                  admins,
                  internal_kind=InternalAlertKind.admin_alert,
                  subjects=[preregistration],
                  alert_kind='new_registration')
            url = request.resource_url(preregistration, '@@index')
            for admin in [a for a in admins if getattr(a, 'email', '')]:
                mail_template = root.get_mail_template(
                    'moderate_preregistration', admin.user_locale)
                subject = mail_template['subject'].format(
                    novaideo_title=root.title)
                email_data = get_user_data(admin, 'recipient', request)
                message = mail_template['template'].format(
                    url=url, novaideo_title=root.title, **email_data)
                alert('email', [root.get_site_sender()], [admin.email],
                      subject=subject,
                      body=message)

        request.registry.notify(ActivityExecuted(self, [preregistration],
                                                 None))
        return {'preregistration': preregistration}
Ejemplo n.º 6
0
def evolve_files(root, registry):
    from novaideo.views.filter import find_entities
    from novaideo.content.interface import IFile
    from novaideo.content.file import FileSchema, FileEntity
    from dace.objectofcollaboration.principal.util import (
        grant_roles, get_users_with_role)

    contents = find_entities(
        interfaces=[IFile]
        )
    len_entities = str(len(contents))
    schema = FileSchema()
    default_files = [f['name'] for f in DEFAULT_FILES]
    for index, node in enumerate(contents):
        data = node.get_data(schema)
        data.pop('_csrf_token_')
        new_file = FileEntity(**data)
        if not node.state:
            new_file.state = PersistentList(['draft'])
        else:
            new_file.state = node.state

        name = node.__name__
        new_file.__name__ = name
        users = get_users_with_role(('Owner', node))
        root.delfromproperty('files', node)
        root.addtoproperty('files', new_file)
        if users:
            author = users[0]
            grant_roles(user=author, roles=(('Owner', new_file), ))
            new_file.setproperty('author', author)
            new_file.reindex()

        if name in default_files:
            setattr(root, name, new_file)

        log.info(str(index) + "/" + len_entities)

    log.info('Files evolved')
Ejemplo n.º 7
0
    def start(self, context, request, appstruct, **kw):
        preregistration = appstruct['_object_data']
        preregistration.__name__ = gen_random_token()
        preregistration.locale = my_locale_negotiator(request)
        root = getSite()
        root.addtoproperty('preregistrations', preregistration)
        deadline = DEADLINE_PREREGISTRATION * 1000
        call_id = 'persistent_' + str(get_oid(preregistration))
        push_callback_after_commit(
            remove_expired_preregistration_callback, deadline, call_id,
            root=root, preregistration=preregistration)
        preregistration.state.append('pending')
        preregistration.reindex()
        transaction.commit()
        if not getattr(root, 'moderate_registration', False):
            accept_preregistration(request, preregistration, root)
        else:
            admins = get_users_with_role(role='SiteAdmin')
            alert(
                'internal', [root], admins,
                internal_kind=InternalAlertKind.admin_alert,
                subjects=[preregistration], alert_kind='new_registration')
            url = request.resource_url(preregistration, '@@index')
            for admin in [a for a in admins if getattr(a, 'email', '')]:
                mail_template = root.get_mail_template(
                    'moderate_preregistration', admin.user_locale)
                subject = mail_template['subject'].format(
                    novaideo_title=root.title)
                email_data = get_user_data(admin, 'recipient', request)
                message = mail_template['template'].format(
                    url=url,
                    novaideo_title=root.title,
                    **email_data)
                alert('email', [root.get_site_sender()], [admin.email],
                      subject=subject, body=message)

        request.registry.notify(ActivityExecuted(self, [preregistration], None))
        return {'preregistration': preregistration}
Ejemplo n.º 8
0
    def test_grantroles(self):
        object1, object2 = self._create_objects()
        user = self.request.user #Admin
        self.assertEqual(len(get_roles(user)), 1)
        self.assertTrue(has_any_roles(user, roles=('Admin', )))
        grant_roles(user, roles=('Collaborator', ('Owner', object1)))
        self.assertTrue(has_any_roles(user, roles=('Collaborator', 'Owner')))
        self.assertTrue(has_any_roles(user, roles=('Collaborator', ('Owner', object1))))
        self.assertFalse(has_any_roles(user, roles=(('Owner', object2),)))

        roles = get_roles(user)
        self.assertEqual(len(roles), 3)
        self.assertIn('Collaborator',roles)
        self.assertIn('Owner',roles)
        self.assertIn('Admin',roles)

        self.assertTrue(has_all_roles(user, ('Collaborator', 'Owner')))
        self.assertFalse(has_all_roles(user, ('Collaborator', 'Owner', 'Other')))

        users = get_users_with_role(role=('Owner', object1))
        self.assertEqual(len(users), 1)
        self.assertIn(self.request.user,users)

        users = get_users_with_role(role='Owner')
        self.assertEqual(len(users), 1)
        self.assertIn(self.request.user,users)

        objects = get_objects_with_role(user=self.request.user, role='Owner')
        self.assertEqual(len(objects), 1)
        self.assertIn(object1,objects)
        
        revoke_roles(user, roles=(('Owner', object1),))
        self.assertFalse(has_all_roles(user, ('Collaborator', 'Owner')))
        self.assertTrue(has_all_roles(user, ('Collaborator', )))

        revoke_roles(user, roles=('Collaborator', ))
        self.assertEqual(len(get_roles(user)), 1)


        self.request.user = self.users['alice']
        user = self.request.user  #Alice
        roles = get_roles(user)
        self.assertEqual(len(roles), 0)
        grant_roles(user, roles=('Admin',))
        roles = get_roles(user)
        self.assertEqual(len(roles), 1)
        self.assertIn('Admin',roles)
        self.assertTrue(has_any_roles(user, roles=('Collaborator', )))

        revoke_roles(user, roles=('Admin', ))
        self.assertFalse(has_any_roles(user, roles=('Collaborator', )))
        grant_roles(user, roles=('Developer',))
        roles = get_roles(user)
        self.assertEqual(len(roles), 1)
        self.assertIn('Developer',roles)
        self.assertTrue(has_any_roles(user, roles=('Collaborator', )))
        self.assertFalse(has_any_roles(user, ('Collaborator', ), True)) #exclude superiors
 
        #Anonymous
        self.request.user = None
        roles = get_roles()
        self.assertEqual(len(roles), 1)
        self.assertIn('Anonymous',roles)
        self.assertFalse(has_any_roles(roles=('Collaborator', 'Owner')))
        self.assertTrue(has_any_roles(roles=('Anonymous',)))
Ejemplo n.º 9
0
 def _get(self):
     return get_users_with_role(role=('OrganizationResponsible', self))
Ejemplo n.º 10
0
 def managers(self):
     return get_users_with_role(role=('OrganizationResponsible', self))
Ejemplo n.º 11
0
    def test_grantroles(self):
        object1, object2 = self._create_objects()
        user = self.request.user #Admin
        self.assertEqual(len(get_roles(user)), 1)
        self.assertTrue(has_any_roles(user, roles=('Admin', )))
        grant_roles(user, roles=('Collaborator', ('Owner', object1)))
        self.assertTrue(has_any_roles(user, roles=('Collaborator', 'Owner')))
        self.assertTrue(has_any_roles(user, roles=('Collaborator', ('Owner', object1))))
        self.assertFalse(has_any_roles(user, roles=(('Owner', object2),)))

        roles = get_roles(user)
        self.assertEqual(len(roles), 3)
        self.assertIn('Collaborator',roles)
        self.assertIn('Owner',roles)
        self.assertIn('Admin',roles)

        self.assertTrue(has_all_roles(user, ('Collaborator', 'Owner')))
        self.assertFalse(has_all_roles(user, ('Collaborator', 'Owner', 'Other')))

        users = get_users_with_role(role=('Owner', object1))
        self.assertEqual(len(users), 1)
        self.assertIn(self.request.user,users)

        users = get_users_with_role(role='Owner')
        self.assertEqual(len(users), 1)
        self.assertIn(self.request.user,users)

        objects = get_objects_with_role(user=self.request.user, role='Owner')
        self.assertEqual(len(objects), 1)
        self.assertIn(object1,objects)
        
        revoke_roles(user, roles=(('Owner', object1),))
        self.assertFalse(has_all_roles(user, ('Collaborator', 'Owner')))
        self.assertTrue(has_all_roles(user, ('Collaborator', )))

        revoke_roles(user, roles=('Collaborator', ))
        self.assertEqual(len(get_roles(user)), 1)


        self.request.user = self.users['alice']
        user = self.request.user  #Alice
        roles = get_roles(user)
        self.assertEqual(len(roles), 0)
        grant_roles(user, roles=('Admin',))
        roles = get_roles(user)
        self.assertEqual(len(roles), 1)
        self.assertIn('Admin',roles)
        self.assertTrue(has_any_roles(user, roles=('Collaborator', )))

        revoke_roles(user, roles=('Admin', ))
        self.assertFalse(has_any_roles(user, roles=('Collaborator', )))
        grant_roles(user, roles=('Developer',))
        roles = get_roles(user)
        self.assertEqual(len(roles), 1)
        self.assertIn('Developer',roles)
        self.assertTrue(has_any_roles(user, roles=('Collaborator', )))
        self.assertFalse(has_any_roles(user, ('Collaborator', ), True)) #exclude superiors
 
        #Anonymous
        self.request.user = None
        roles = get_roles()
        self.assertEqual(len(roles), 1)
        self.assertIn('Anonymous',roles)
        self.assertFalse(has_any_roles(roles=('Collaborator', 'Owner')))
        self.assertTrue(has_any_roles(roles=('Anonymous',)))