def grant_app_permission(username, repo_name, app_id, app_token): """ Grants SELECT, INSERT, UPDATE, and DELETE on given user's repo to app. Raises exceptions on empty input, if no app matches app_id, if app_token doesn't match, or if there are any database errors. """ if not app_id: raise Exception("Invalid app_id") if not app_token: raise Exception("Invalid app_token") app = None try: app = App.objects.get(app_id=app_id) except App.DoesNotExist: raise Exception("Invalid app_id") if app.app_token != app_token: raise Exception("Invalid app_token") try: manager = DataHubManager(user=username) manager.create_repo(repo_name) manager.add_collaborator( repo_name, app_id, privileges=['SELECT', 'INSERT', 'UPDATE', 'DELETE']) manager.close_connection() except Exception as e: raise e