Ejemplo n.º 1
0
def setup(datadir, db):
    user1 = UserFactory.create(username='******')
    user2 = UserFactory.create(username='******')
    user3 = UserFactory.create(username='******')
    user4 = UserFactory.create(username='******')
    user5 = UserFactory.create(username='******')

    PolicyFactory.set_directory(str(datadir))
    def_pol = PolicyFactory.create(name='def', file='default-policy.json')
    org_pol = PolicyFactory.create(name='org', file='org-policy.json')
    prj_pol = PolicyFactory.create(name='prj', file='project-policy.json')
    deny_pol = PolicyFactory.create(name='prj', file='deny-policy.json')

    Action.register(['party.list', 'party.view', 'parcel.list', 'parcel.view',
                     'party.edit', 'parcel.edit'])

    assign_user_policies(None, def_pol)
    user1.assign_policies(def_pol)
    user2.assign_policies(def_pol,
                          (org_pol, {'organisation': 'Cadasta'}))
    user3.assign_policies(def_pol,
                          (org_pol, {'organisation': 'Cadasta'}),
                          (prj_pol, {'organisation': 'Cadasta',
                                     'project': 'TestProj'}),
                          (deny_pol, {'organisation': 'Cadasta',
                                      'project': 'Proj2'}))
    user4.assign_policies(def_pol,
                          (org_pol, {'organisation': 'OtherOrg'}))
    user5.assign_policies(def_pol,
                          (org_pol, {'organisation': 'Cadasta'}),
                          (prj_pol, {'organisation': 'Cadasta',
                                     'project': 'TestProj2'}))

    return (user1, user2, user3, user4, user5,
            def_pol, org_pol, prj_pol, deny_pol)
def setup(datadir, db):
    user1 = UserFactory.create(username="******")
    user2 = UserFactory.create(username="******")

    PolicyFactory.set_directory(str(datadir))
    pol1 = PolicyFactory.create(name="pol1", file="policy-1.json")
    pol2 = PolicyFactory.create(name="pol2", file="policy-2.json")
    pol3 = PolicyFactory.create(name="pol3", file="policy-3.json")

    Action.register(["check.list", "check.create", "check.detail", "check.delete"])

    user1.assign_policies(pol1, pol2)
    user2.assign_policies(pol1, pol3)

    return (user1, user2)
Ejemplo n.º 3
0
def setup(datadir, db):
    user1 = UserFactory.create(username='******')
    user2 = UserFactory.create(username='******')

    PolicyFactory.set_directory(str(datadir))
    pol1 = PolicyFactory.create(name='pol1', file='policy-1.json')
    pol2 = PolicyFactory.create(name='pol2', file='policy-2.json')
    pol3 = PolicyFactory.create(name='pol3', file='policy-3.json')

    Action.register(['check.list', 'check.create',
                     'check.detail', 'check.delete'])

    user1.assign_policies(pol1, pol2)
    user2.assign_policies(pol1, pol3)

    return (user1, user2)
Ejemplo n.º 4
0
def setup(datadir, db):
    user1 = UserFactory.create(username='******')
    user2 = UserFactory.create(username='******')
    user3 = UserFactory.create(username='******')
    user4 = UserFactory.create(username='******')
    user5 = UserFactory.create(username='******')

    PolicyFactory.set_directory(str(datadir))
    def_pol = PolicyFactory.create(name='def', file='default-policy.json')
    org_pol = PolicyFactory.create(name='org', file='org-policy.json')
    prj_pol = PolicyFactory.create(name='prj', file='project-policy.json')
    deny_pol = PolicyFactory.create(name='prj', file='deny-policy.json')

    Action.register(['party.list', 'party.view', 'parcel.list', 'parcel.view',
                     'party.edit', 'parcel.edit'])

    return (user1, user2, user3, user4, user5,
            def_pol, org_pol, prj_pol, deny_pol)
Ejemplo n.º 5
0
        ('policy.edit',   {'description': "Can update existing policies"}),
        ('policy.delete', {'description': "Can delete policies"})
    ]
)
permissioned_model(
    User, perm_type='user', path_fields=['username'],
    actions=[
        ('user.list',   {'permissions_object': None}),
        ('user.create', {'permissions_object': None}),
        'user.detail',
        'user.edit',
        'user.delete'
    ]
)

Action.register('statistics')


class UserPolicyAssignment(models.Model):
    user = models.ForeignKey(User)
    policy = models.ForeignKey(Policy)
    organisation = models.ForeignKey(Organisation, null=True, blank=True)
    project = models.ForeignKey(Project, null=True, blank=True)
    index = models.IntegerField()

    class Meta:
        ordering = ('index',)


def set_user_policies(user):
    def do_one(pol_assign):