Skip to content

Commit d7eba10

Browse files
committed
fix(vcs): minor renames/fixes
1 parent 273eda4 commit d7eba10

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

invenio_vcs/oauth/handlers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def disconnect_handler(self, remote):
5757
oauth_unlink_external_id(dict(id=external_ids[0], method=external_method))
5858

5959
svc = VCSService(self.provider_factory.for_user(current_user.id))
60-
token = svc.provider.session_token
60+
token = svc.provider.remote_token
6161

6262
if token:
6363
extra_data = token.remote_account.extra_data
@@ -70,9 +70,9 @@ def disconnect_handler(self, remote):
7070
repos = svc.user_enabled_repositories.all()
7171
repos_with_hooks = []
7272
for repo in repos:
73-
if repo.hook:
73+
if repo.hook is not None:
7474
repos_with_hooks.append((repo.provider_id, repo.hook))
75-
svc.disable_repository(repo.provider_id)
75+
svc.mark_repo_disabled(repo.provider_id)
7676

7777
# Commit any changes before running the ascynhronous task
7878
db.session.commit()

invenio_vcs/service.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)