-
Notifications
You must be signed in to change notification settings - Fork 25
feat(vcs): support for new VCS integration #554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
palkerecsenyi
wants to merge
2
commits into
CERNDocumentServer:master
Choose a base branch
from
palkerecsenyi:gitlab
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| {# | ||
| Copyright (C) 2026 CERN. | ||
|
|
||
| CDS-RDM is free software; you can redistribute it and/or modify it | ||
| under the terms of the GPL-2.0 License; see LICENSE file for more details. | ||
| #} | ||
|
|
||
| {%- extends "invenio_vcs/rdm-index.html" %} | ||
|
|
||
| {%- block get_started %} | ||
| <div class="ui grid"> | ||
| <div class="sixteen wide centered column"> | ||
| <h3 class="ui large header mt-10"> | ||
| <i class="{{ vocabulary["icon"] }} icon" aria-hidden="true"></i>{{ _("Get started") }} | ||
| </h3> | ||
| </div> | ||
|
|
||
| <div class="three column stackable tablet-mobile row"> | ||
| <div class="column"> | ||
| <h4 class="ui medium header">1 {{ _("Flip the switch") }}</h4> | ||
| <div class="ui divider"></div> | ||
| <p> | ||
| {{ _('Select the repository you want to preserve, and toggle | ||
| the switch below to turn on automatic preservation of your software.') }} | ||
| </p> | ||
| </div> | ||
|
|
||
| <div class="column"> | ||
| <h4 class="ui medium header">2 {{ _("Create a release") }}</h4> | ||
| <div class="ui divider"></div> | ||
| <p> | ||
| {{ | ||
| _( | ||
| 'Go to %(name)s and <a href="%(release_docs_link)s" target="_blank">create a release <i class="small icon external" aria-hidden="true"></i></a>. %(site_name)s will automatically download a .zip-ball of each new release and publish a record.', | ||
| name=vocabulary["name"], | ||
| site_name=config.THEME_SITENAME | default('System'), | ||
| release_docs_link=vocabulary["release_docs_link"] | ||
| ) | ||
| }} | ||
| </p> | ||
| </div> | ||
|
|
||
| <div class="column"> | ||
| <h4 class="ui medium header">3 {{ _("Customize the metadata") }}</h4> | ||
| <div class="ui divider"></div> | ||
| <p> | ||
| {{ _( | ||
| "On your first release, you'll need to manually assign a community to your %(repository_name)s by following the link in your email. You can also change other metadata or request a DOI.", | ||
| repository_name=vocabulary["repository_name"] | ||
| ) }} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {%- endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (C) 2026 CERN. | ||
| # | ||
| # CDS-RDM is free software; you can redistribute it and/or modify it | ||
| # under the terms of the GPL-2.0 License; see LICENSE file for more details. | ||
|
|
||
| """GitLab OAuth handler override.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from flask_login import current_user | ||
| from invenio_cern_sync.sso import cern_remote_app_name | ||
| from invenio_oauthclient import current_oauthclient | ||
|
|
||
| from cds_rdm.errors import ( | ||
| GitLabIdentityNotFoundError, | ||
| KeycloakGitLabMismatchError, | ||
| KeycloakIdentityNotFoundError, | ||
| ) | ||
|
|
||
|
|
||
| def gitlab_account_info_serializer(original_serializer): | ||
| """An OAuthClient account_info_serializer override for GitLab. | ||
|
|
||
| This ensures that users who are logged into CDS with CERN Keycloak OAuth | ||
| are also logged into GitLab with the same CERN Keycloak account to prevent | ||
| an account mismatch that could cause bugs or security issues. | ||
| """ | ||
|
|
||
| def inner(remote, resp, user_info, **kwargs): | ||
| """Account info serializer.""" | ||
| # RemoteAccount only contains the application's OAuth Client ID so we need to find it | ||
| cern_client_id = current_oauthclient.oauth.remote_apps.get( | ||
| cern_remote_app_name | ||
| ).consumer_key | ||
|
|
||
| user_keycloak_id: str | None = None | ||
| for remote_account in current_user.remote_accounts: | ||
| if remote_account.client_id == cern_client_id: | ||
| # This is the user's ID as stored in Keycloak, which is equivalent to the | ||
| # CERN username of the person or their secondary account. | ||
| user_keycloak_id = remote_account.extra_data.get("keycloak_id") | ||
|
|
||
| if user_keycloak_id is None: | ||
| # All non-administrative users are expected to have one. | ||
| raise KeycloakIdentityNotFoundError(current_user.id) | ||
|
|
||
| gl_user_id = str(user_info["id"]) | ||
| gl_identities = user_info["identities"] | ||
| gl_extern_uid: str | None = None | ||
| for identity in gl_identities: | ||
| prov = identity["provider"] | ||
|
|
||
| # On CERN GitLab, you have one GitLab account for each Keycloak account, with secondary accounts | ||
| # being separate GitLab accounts. You can sign in to one account with either openid_connect or | ||
| # kereberos, with the latter being used e.g. on CERN-provisioned computers. | ||
| # If a user has only ever signed in on a CERN device they might only have the kerberos method | ||
| # available, so we need to ensure we accept it. | ||
| if prov == "openid_connect": | ||
| gl_extern_uid = identity["extern_uid"] | ||
| elif prov == "kerberos": | ||
| # {'provider': 'kerberos', 'extern_uid': 'username@CERN.CH', 'saml_provider_id': None} | ||
| gl_extern_uid = identity["extern_uid"].removesuffix("@CERN.CH") | ||
| else: | ||
| continue | ||
|
|
||
| if gl_extern_uid is None: | ||
| raise GitLabIdentityNotFoundError(gl_user_id) | ||
|
|
||
| if user_keycloak_id != gl_extern_uid: | ||
| raise KeycloakGitLabMismatchError( | ||
| gl_user_id, gl_extern_uid, current_user.id, user_keycloak_id | ||
| ) | ||
|
|
||
| # Continue with the rest of the account info serializer chain. | ||
| return original_serializer(remote, resp, user_info, **kwargs) | ||
|
|
||
| return inner | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I dont understand this case, can you login to your Gitlab account via kerberos? how would a GL identity exist if you havent logged in on the GL interface?