Esempio n. 1
0
    def get_organization_projects_with_default_role(self, obj):
        projects = []

        if obj:
            for project in Project.objects.filter(organization__id=obj.organization.id):
                project_map = {}
                project_map["name"] = project.name
                project_map["projectid"] = project.pk
                project_map["default_role"] = get_team_project_default_permissions(obj, project)
                projects.append(project_map)

        return projects
Esempio n. 2
0
    def test_add_project_perms_to_team(self):
        # create an org, user, team
        organization = self._create_organization("test org", self.user)
        user_deno = self._create_user('deno', 'deno')

        # add a member to the team
        team = tools.create_organization_team(organization, "test team")
        tools.add_user_to_team(team, user_deno)

        project = Project.objects.create(name="Test Project",
                                         organization=organization,
                                         created_by=user_deno,
                                         metadata='{}')

        # confirm that the team has no permissions
        self.assertFalse(team.groupobjectpermission_set.all())
        # set DataEntryRole role of project on team
        DataEntryRole.add(team, project)

        content_type = ContentType.objects.get(
            model=project.__class__.__name__.lower(),
            app_label=project.__class__._meta.app_label)

        object_permissions = team.groupobjectpermission_set.filter(
            object_pk=project.pk, content_type=content_type)

        permission_names = sorted(
            [p.permission.codename for p in object_permissions])
        self.assertEqual([
            CAN_EXPORT_PROJECT, CAN_ADD_SUBMISSIONS_PROJECT, CAN_VIEW_PROJECT
        ], permission_names)

        self.assertEqual(get_team_project_default_permissions(team, project),
                         DataEntryRole.name)

        # Add a new user
        user_sam = self._create_user('Sam', 'sammy_')

        self.assertFalse(user_sam.has_perm(CAN_VIEW_PROJECT, project))
        self.assertFalse(user_sam.has_perm(CAN_ADD_XFORM, project))

        # Add the user to the group
        tools.add_user_to_team(team, user_sam)

        # assert that team member has default perm set on team
        self.assertTrue(user_sam.has_perm(CAN_VIEW_PROJECT, project))

        # assert that removing team member revokes perms
        tools.remove_user_from_team(team, user_sam)
        self.assertFalse(user_sam.has_perm(CAN_VIEW_PROJECT, project))
        self.assertFalse(user_sam.has_perm(CAN_ADD_XFORM, project))
Esempio n. 3
0
    def get_organization_projects_with_default_role(self, obj):
        projects = []

        if obj:
            for project in Project.objects.filter(
                    organization__id=obj.organization.id):
                project_map = {}
                project_map['name'] = project.name
                project_map['projectid'] = project.pk
                project_map['default_role'] = \
                    get_team_project_default_permissions(obj, project)
                projects.append(project_map)

        return projects
Esempio n. 4
0
    def get_projects(self, obj):
        """Organization Projects with default role"""
        projects = []

        if obj:
            for project in Project.objects.filter(
                    organization__id=obj.organization.id):
                project_map = {}
                project_map['name'] = project.name
                project_map['projectid'] = project.pk
                project_map['default_role'] = \
                    get_team_project_default_permissions(obj, project)
                projects.append(project_map)

        return projects
Esempio n. 5
0
    def test_add_project_perms_to_team(self):
        # create an org, user, team
        organization = self._create_organization("test org", self.user)
        user_deno = self._create_user("deno", "deno")

        # add a member to the team
        team = tools.create_organization_team(organization, "test team")
        tools.add_user_to_team(team, user_deno)

        project = Project.objects.create(
            name="Test Project", organization=organization, created_by=user_deno, metadata="{}"
        )

        # confirm that the team has no permissions
        self.assertFalse(team.groupobjectpermission_set.all())
        # set DataEntryRole role of project on team
        DataEntryRole.add(team, project)

        content_type = ContentType.objects.get(
            model=project.__class__.__name__.lower(), app_label=project.__class__._meta.app_label
        )

        object_permissions = team.groupobjectpermission_set.filter(object_pk=project.pk, content_type=content_type)

        permission_names = sorted([p.permission.codename for p in object_permissions])
        self.assertEqual([CAN_EXPORT_PROJECT, CAN_ADD_SUBMISSIONS_PROJECT, CAN_VIEW_PROJECT], permission_names)

        self.assertEqual(get_team_project_default_permissions(team, project), DataEntryRole.name)

        # Add a new user
        user_sam = self._create_user("Sam", "sammy_")

        self.assertFalse(user_sam.has_perm(CAN_VIEW_PROJECT, project))
        self.assertFalse(user_sam.has_perm(CAN_ADD_XFORM, project))

        # Add the user to the group
        tools.add_user_to_team(team, user_sam)

        # assert that team member has default perm set on team
        self.assertTrue(user_sam.has_perm(CAN_VIEW_PROJECT, project))

        # assert that removing team member revokes perms
        tools.remove_user_from_team(team, user_sam)
        self.assertFalse(user_sam.has_perm(CAN_VIEW_PROJECT, project))
        self.assertFalse(user_sam.has_perm(CAN_ADD_XFORM, project))
Esempio n. 6
0
    def test_add_project_perms_to_team(self):
        # create an org, user, team
        organization = self._create_organization("test org", self.user)
        user_deno = self._create_user('deno', 'deno')

        # add a member to the team
        team = tools.create_organization_team(organization, "test team")
        tools.add_user_to_team(team, user_deno)

        project = Project.objects.create(name="Test Project",
                                         organization=organization,
                                         created_by=user_deno,
                                         metadata='{}')

        # confirm that the team has no permissions on project
        self.assertFalse(get_perms(team, project))
        # set DataEntryRole role of project on team
        DataEntryRole.add(team, project)

        self.assertEqual([CAN_EXPORT_PROJECT, CAN_ADD_SUBMISSIONS_PROJECT,
                          CAN_VIEW_PROJECT, CAN_VIEW_PROJECT_ALL,
                          CAN_VIEW_PROJECT_DATA],
                         sorted(get_perms(team, project)))

        self.assertEqual(get_team_project_default_permissions(team, project),
                         DataEntryRole.name)

        # Add a new user
        user_sam = self._create_user('Sam', 'sammy_')

        self.assertFalse(user_sam.has_perm(CAN_VIEW_PROJECT, project))
        self.assertFalse(user_sam.has_perm(CAN_ADD_XFORM, project))

        # Add the user to the group
        tools.add_user_to_team(team, user_sam)

        # assert that team member has default perm set on team
        self.assertTrue(user_sam.has_perm(CAN_VIEW_PROJECT, project))

        # assert that removing team member revokes perms
        tools.remove_user_from_team(team, user_sam)
        self.assertFalse(user_sam.has_perm(CAN_VIEW_PROJECT, project))
        self.assertFalse(user_sam.has_perm(CAN_ADD_XFORM, project))
Esempio n. 7
0
    def test_add_project_perms_to_team(self):
        # create an org, user, team
        organization = self._create_organization("test org", self.user)
        user_deno = self._create_user('deno', 'deno')

        # add a member to the team
        team = tools.create_organization_team(organization, "test team")
        tools.add_user_to_team(team, user_deno)

        project = Project.objects.create(name="Test Project",
                                         organization=organization,
                                         created_by=user_deno,
                                         metadata='{}')

        # confirm that the team has no permissions on project
        self.assertFalse(get_perms(team, project))
        # set DataEntryRole role of project on team
        DataEntryRole.add(team, project)

        self.assertEqual([
            CAN_EXPORT_PROJECT, CAN_ADD_SUBMISSIONS_PROJECT, CAN_VIEW_PROJECT,
            CAN_VIEW_PROJECT_ALL, CAN_VIEW_PROJECT_DATA
        ], sorted(get_perms(team, project)))

        self.assertEqual(get_team_project_default_permissions(team, project),
                         DataEntryRole.name)

        # Add a new user
        user_sam = self._create_user('Sam', 'sammy_')

        self.assertFalse(user_sam.has_perm(CAN_VIEW_PROJECT, project))
        self.assertFalse(user_sam.has_perm(CAN_ADD_XFORM, project))

        # Add the user to the group
        tools.add_user_to_team(team, user_sam)

        # assert that team member has default perm set on team
        self.assertTrue(user_sam.has_perm(CAN_VIEW_PROJECT, project))

        # assert that removing team member revokes perms
        tools.remove_user_from_team(team, user_sam)
        self.assertFalse(user_sam.has_perm(CAN_VIEW_PROJECT, project))
        self.assertFalse(user_sam.has_perm(CAN_ADD_XFORM, project))