parameters: (
              self, repo, collaborator, db_privileges,
              file_privileges)
return_statement: return self.user_con.add_collaborator(
              repo=repo,
              collaborator=collaborator,
              db_privileges=db_privileges)
docstring: Grants a user or app privileges on a repo.
  
          - collaborator must match an existing User's username or an existing
          App's app_id.
          - db_privileges must be an array of SQL privileges as strings.
            e.g. ['SELECT', 'UPDATE', 'INSERT']
          - file_privileges must be an array of file privileges.
            e.g. ['read', 'write']
  
          Returns True on success.
  
          Raises ValueError if collaborator owns or is already a collaborator of
          repo or if db_privileges or file_privileges are invalid.
          Raises LookupError if repo does not exist.
          Raises User.DoesNotExist if collaborator does not exist.
          Raises PermissionDenied on insufficient permissions.
docstring_summary: Grants a user or app privileges on a repo.
docstring_tokens: Grants a user or app privileges on a repo .
function: def add_collaborator(
              self, repo, collaborator, db_privileges,
              file_privileges):
          """
          Grants a user or app privileges on a repo.
  
          - collaborator must match an existing User's username or an existing
          App's app_id.
          - db_privileges must be an array of SQL privileges as strings.
            e.g. ['SELECT', 'UPDATE', 'INSERT']
          - file_privileges must be an array of file privileges.
            e.g. ['read', 'write']
  
          Returns True on success.
  
          Raises ValueError if collaborator owns or is already a collaborator of
          repo or if db_privileges or file_privileges are invalid.
          Raises LookupError if repo does not exist.
          Raises User.DoesNotExist if collaborator does not exist.
          Raises PermissionDenied on insufficient permissions.
          """
          # Usage is probably not the right check, but neither is CREATE.
          # The trouble is that roles INHERIT permissions from one another
          # depending on whether that flag was set during creation... and I
          # haven't figured out a way to check on whether a user can grant
          # permission to another without actually doing it.
          # For now, we limit adding_collaborators to the actual owner, who has
          # create privileges
          DataHubManager.has_repo_db_privilege(
              self.username, self.repo_base, repo, 'CREATE')
  
          # you can't add yourself as a collaborator
          if self.username == collaborator:
              raise ValueError(
                  "Can't add a repository's owner as a collaborator.")
  
          collaborators = self.list_collaborators(repo)
          if collaborator in (c['username'] for c in collaborators):
              raise ValueError(
                  "{0} is already a collaborator of {1}.".format(
                      collaborator, repo))
  
          db_privileges = [p.upper() for p in db_privileges]
          file_privileges = [p.lower() for p in file_privileges]
  
          invalid_db_privileges = set(db_privileges) - {
              'SELECT', 'INSERT', 'UPDATE', 'DELETE',
              'TRUNCATE', 'REFERENCES', 'TRIGGER'}
          if len(invalid_db_privileges) > 0:
              raise ValueError(
                  "Unsupported db privileges: \"{0}\"".format(
                      ','.join(invalid_db_privileges)))
          invalid_file_privileges = set(file_privileges) - {'read', 'write'}
          if len(invalid_file_privileges) > 0:
              raise ValueError(
                  "Unsupported file privileges: \"{0}\"".format(
                      ','.join(invalid_file_privileges)))
  
          try:
              app = App.objects.get(app_id=collaborator)
              collaborator_obj, _ = Collaborator.objects.get_or_create(
                  app=app, repo_name=repo, repo_base=self.repo_base)
          except App.DoesNotExist:
              user = User.objects.get(username=collaborator)
              collaborator_obj, _ = Collaborator.objects.get_or_create(
                  user=user, repo_name=repo, repo_base=self.repo_base)
  
          # convert privileges list to string and save the object
          db_privilege_str = ', '.join(db_privileges).upper()
          file_privilege_str = ', '.join(file_privileges).lower()
  
          collaborator_obj.permission = db_privilege_str
          collaborator_obj.file_permission = file_privilege_str
  
          collaborator_obj.save()
  
          # if license_id != -1:
          #     # for view in views from license id:
          #     #     add collab to to view
          #     for view_id in self.list_views():
          #         self.user_conn.add_collaborator_to_license_view(
          #             repo=repo,
          #             collborator=collaborator,
          #             db_privileges=db_privileges,
          #             view="licenseview{}".format(str(view_id))
          #         )
  
          #     return self.user_con.add_collaborator(
          #         repo=repo,
          #         collaborator=collaborator,
          #         db_privileges=db_privileges,
          #         license_id=license_id)
          # else:
          return self.user_con.add_collaborator(
              repo=repo,
              collaborator=collaborator,
              db_privileges=db_privileges)
function_tokens: def add_collaborator ( self , repo , collaborator , db_privileges , file_privileges ) : # Usage is probably not the right check, but neither is CREATE. # The trouble is that roles INHERIT permissions from one another # depending on whether that flag was set during creation... and I # haven't figured out a way to check on whether a user can grant # permission to another without actually doing it. # For now, we limit adding_collaborators to the actual owner, who has # create privileges DataHubManager . has_repo_db_privilege ( self . username , self . repo_base , repo , 'CREATE' ) # you can't add yourself as a collaborator if self . username == collaborator : raise ValueError ( "Can't add a repository's owner as a collaborator." ) collaborators = self . list_collaborators ( repo ) if collaborator in ( c [ 'username' ] for c in collaborators ) : raise ValueError ( "{0} is already a collaborator of {1}." . format ( collaborator , repo ) ) db_privileges = [ p . upper ( ) for p in db_privileges ] file_privileges = [ p . lower ( ) for p in file_privileges ] invalid_db_privileges = set ( db_privileges ) - { 'SELECT' , 'INSERT' , 'UPDATE' , 'DELETE' , 'TRUNCATE' , 'REFERENCES' , 'TRIGGER' } if len ( invalid_db_privileges ) > 0 : raise ValueError ( "Unsupported db privileges: \"{0}\"" . format ( ',' . join ( invalid_db_privileges ) ) ) invalid_file_privileges = set ( file_privileges ) - { 'read' , 'write' } if len ( invalid_file_privileges ) > 0 : raise ValueError ( "Unsupported file privileges: \"{0}\"" . format ( ',' . join ( invalid_file_privileges ) ) ) try : app = App . objects . get ( app_id = collaborator ) collaborator_obj , _ = Collaborator . objects . get_or_create ( app = app , repo_name = repo , repo_base = self . repo_base ) except App . DoesNotExist : user = User . objects . get ( username = collaborator ) collaborator_obj , _ = Collaborator . objects . get_or_create ( user = user , repo_name = repo , repo_base = self . repo_base ) # convert privileges list to string and save the object db_privilege_str = ', ' . join ( db_privileges ) . upper ( ) file_privilege_str = ', ' . join ( file_privileges ) . lower ( ) collaborator_obj . permission = db_privilege_str collaborator_obj . file_permission = file_privilege_str collaborator_obj . save ( ) # if license_id != -1: #     # for view in views from license id: #     #     add collab to to view #     for view_id in self.list_views(): #         self.user_conn.add_collaborator_to_license_view( #             repo=repo, #             collborator=collaborator, #             db_privileges=db_privileges, #             view="licenseview{}".format(str(view_id)) #         ) #     return self.user_con.add_collaborator( #         repo=repo, #         collaborator=collaborator, #         db_privileges=db_privileges, #         license_id=license_id) # else: return self . user_con . add_collaborator ( repo = repo , collaborator = collaborator , db_privileges = db_privileges )