Esempio n. 1
0
    def delete_collaborator(self, repo, collaborator):
        superuser_con = DataHubConnection(
            user=settings.DATABASES['default']['USER'],
            password=settings.DATABASES['default']['USER'],
            repo_base=self.repo_base)
        repo_collaborators = superuser_con.list_collaborators(repo=repo)

        # The reason we're enforcing permission checks this way is to deal
        # with the edge case where a user removes himself as a collaborator
        # from another user's repo.
        if collaborator not in repo_collaborators:
            raise Exception('Failed to delete collaborator.'
                            ' %s is not a collaborator in the specified'
                            'repository.' % collaborator)
        if self.username != collaborator and self.username != self.repo_base:
            raise PermissionDenied(
                'Access denied. Missing required privileges')

        collab = User.objects.get(username=collaborator)
        Collaborator.objects.get(user=collab,
                                 repo_name=repo,
                                 repo_base=self.repo_base).delete()

        return superuser_con.delete_collaborator(repo=repo,
                                                 collaborator=collaborator)
Esempio n. 2
0
 def list_collaborators(repo_base, repo):
     superuser_con = DataHubConnection(
         user=settings.DATABASES["default"]["USER"],
         password=settings.DATABASES["default"]["USER"],
         repo_base=repo_base,
     )
     return superuser_con.list_collaborators(repo_base=repo_base, repo=repo)
Esempio n. 3
0
    def delete_collaborator(self, repo, collaborator):
        superuser_con = DataHubConnection(
            user=settings.DATABASES['default']['USER'],
            password=settings.DATABASES['default']['USER'],
            repo_base=self.repo_base)
        repo_collaborators = superuser_con.list_collaborators(repo=repo)

        # The reason we're enforcing permission checks this way is to deal
        # with the edge case where a user removes himself as a collaborator
        # from another user's repo.
        if collaborator not in repo_collaborators:
            raise Exception('Failed to delete collaborator.'
                            ' %s is not a collaborator in the specified'
                            'repository.' % collaborator)
        if self.username != collaborator and self.username != self.repo_base:
            raise PermissionDenied(
                'Access denied. Missing required privileges')

        collab = User.objects.get(username=collaborator)
        Collaborator.objects.get(
            user=collab, repo_name=repo, repo_base=self.repo_base).delete()

        return superuser_con.delete_collaborator(
            repo=repo, collaborator=collaborator)
Esempio n. 4
0
 def list_collaborators(self, repo):
     superuser_con = DataHubConnection(
         user=settings.DATABASES['default']['USER'],
         password=settings.DATABASES['default']['USER'],
         repo_base=self.repo_base)
     return superuser_con.list_collaborators(repo=repo)
Esempio n. 5
0
 def list_collaborators(self, repo):
     superuser_con = DataHubConnection(
         user=settings.DATABASES['default']['USER'],
         password=settings.DATABASES['default']['USER'],
         repo_base=self.repo_base)
     return superuser_con.list_collaborators(repo=repo)