4teamwork / ftw.builder

Builder pattern for creating Plone objects in tests
3 stars 0 forks source link

Allow to set roles on content object builder #57

Open ghost opened 6 years ago

ghost commented 6 years ago

When setting roles using .manage_setLocalRoles, .reindexObjectSecurity needs to be called.

self.inbox = create(Builder('inbox'))
self.inbox.manage_setLocalRoles('hugo.boss', ('Contributor', 'Editor', 'Reader'))
self.inbox.reindexObjectSecurity()

It would be great if the builder had a method to build objects and automatically called .reindexObjectSecurity():

self.inbox = create(Builder('inbox')
                    .with_roles('hugo.boss', ('Contributor', 'Editor', 'Reader')))

An implementation could look something like this:

def with_roles(self, principle, roles):
    self.local_roles[principle] = roles
    return self

def after_create(self, obj):
    if self.local_roles:
        self.set_roles(obj)
    ....

def set_roles(self, obj):
    for principle, roles in self.local_roles:
        obj.manage_setLocalRoles(principle, roles)
    obj.reindexObjectSecurity()