@@ -75,7 +75,7 @@ def for_provider_and_token(provider_id: str, user_id: int, access_token: str):
7575 @cached_property
7676 def is_authenticated (self ):
7777 """Whether we have a valid VCS API token for the user. Should (almost) always return True."""
78- return self .provider .session_token is not None
78+ return self .provider .remote_token is not None
7979
8080 @property
8181 def user_available_repositories (self ):
@@ -168,30 +168,32 @@ def get_repository(self, repo_id=None, repo_name=None):
168168
169169 return repo
170170
171- def check_repo_access_permissions (self , repo : Repository ):
171+ def check_repo_access_permissions (self , db_repo : Repository ):
172172 """Checks permissions from user on repo.
173173
174174 Repo has access if any of the following is True:
175175
176176 - user is the owner of the repo
177177 - user has access to the repo in the VCS
178178 """
179- if self .provider .user_id and repo :
179+ if self .provider .user_id and db_repo :
180180 user_is_collaborator = any (
181- user .id == self .provider .user_id for user in repo .users
181+ user .id == self .provider .user_id for user in db_repo .users
182182 )
183183 if user_is_collaborator :
184184 return True
185185
186186 if self .provider .remote_account and self .provider .remote_account .extra_data :
187187 user_has_remote_access_count = self .user_available_repositories .filter (
188- Repository .provider_id == repo .provider_id
188+ Repository .provider_id == db_repo .provider_id
189189 ).count ()
190190 if user_has_remote_access_count == 1 :
191191 return True
192192
193193 raise RepositoryAccessError (
194- user = self .provider .user_id , repo = repo .full_name , repo_id = repo .provider_id
194+ user = self .provider .user_id ,
195+ repo = db_repo .full_name ,
196+ repo_id = db_repo .provider_id ,
195197 )
196198
197199 def sync_repo_users (self , db_repo : Repository ):
@@ -428,9 +430,9 @@ def enable_repository(self, repository_id):
428430 Repository .provider_id == repository_id
429431 ).first ()
430432 if db_repo is None :
431- raise RepositoryNotFoundError (
432- repository_id , _ ( "Failed to enable repository." )
433- )
433+ raise RepositoryNotFoundError (repository_id )
434+
435+ # No further access check needed: the repo was already in the user's available repo list.
434436
435437 hook_id = self .provider .create_webhook (repository_id )
436438 if hook_id is None :
@@ -444,11 +446,8 @@ def disable_repository(self, repository_id, hook_id=None):
444446 db_repo = self .user_available_repositories .filter (
445447 Repository .provider_id == repository_id
446448 ).first ()
447-
448449 if db_repo is None :
449- raise RepositoryNotFoundError (
450- repository_id , _ ("Failed to disable repository." )
451- )
450+ raise RepositoryNotFoundError (repository_id )
452451
453452 if not db_repo .enabled :
454453 raise RepositoryDisabledError (repository_id )
0 commit comments