-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Push new gems to organizations #6762
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
Draft
anton-bondaronok
wants to merge
8
commits into
master
Choose a base branch
from
ab/push-new-gems-to-organizations
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.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f662d03
Add organization scope data model for API keys
anton-bondaronok b031b9f
Allow assigning an organization scope to API keys
anton-bondaronok 65d99d4
Push new gems directly into an organization with org-scoped keys
anton-bondaronok 0e33fff
Let users create organization-scoped API keys in the profile UI
anton-bondaronok 0732c62
Accept organization scope when creating API keys via the HTTP API
anton-bondaronok 2abc417
Revoke organization-scoped API keys when membership changes
anton-bondaronok a54c689
Support organization scope in OIDC API key roles
anton-bondaronok 611b6f5
Allow pending trusted publishers to target an organization
anton-bondaronok 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class Avo::Resources::ApiKeyOrganizationScope < Avo::BaseResource | ||
| self.title = :cache_key | ||
| self.includes = [] | ||
|
|
||
| def fields | ||
| field :id, as: :id | ||
|
|
||
| field :api_key, as: :belongs_to | ||
| field :membership, as: :belongs_to | ||
| end | ||
| end |
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
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
6 changes: 6 additions & 0 deletions
6
app/controllers/avo/api_key_organization_scopes_controller.rb
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,6 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # This controller has been generated to enable Rails' resource routes. | ||
| # More information on https://docs.avohq.io/2.0/controllers.html | ||
| class Avo::ApiKeyOrganizationScopesController < Avo::ResourcesController | ||
| end |
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 |
|---|---|---|
| @@ -1,44 +1,79 @@ | ||
| import { Controller } from "@hotwired/stimulus"; | ||
|
|
||
| export default class extends Controller { | ||
| static targets = ["checkbox", "selector"]; | ||
| static targets = ["checkbox", "gemSelector", "orgSelector"]; | ||
|
|
||
| connect() { | ||
| this.toggleSelector(); | ||
| this.hiddenFields = {}; | ||
| this.toggleSelectors(); | ||
| } | ||
|
|
||
| checkboxTargetConnected(el) { | ||
| el.addEventListener("change", () => this.toggleSelector()); | ||
| el.addEventListener("change", () => this.toggleSelectors()); | ||
| } | ||
|
|
||
| toggleSelector() { | ||
| gemSelectorTargetConnected(el) { | ||
| el.addEventListener("change", () => { | ||
| if (el.value && this.hasOrgSelectorTarget) { | ||
| this.orgSelectorTarget.value = ""; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| orgSelectorTargetConnected(el) { | ||
| el.addEventListener("change", () => { | ||
| if (el.value && this.hasGemSelectorTarget) { | ||
| this.gemSelectorTarget.value = ""; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| toggleSelectors() { | ||
| const selected = this.checkboxTargets.find((target) => target.checked); | ||
|
|
||
| if (selected) { | ||
| this.selectorTarget.disabled = false; | ||
| this.removeHiddenRubygemField(); | ||
| if (this.hasGemSelectorTarget) { | ||
| this.toggleSelector( | ||
| "api_key[rubygem_id]", | ||
| this.gemSelectorTarget, | ||
| selected, | ||
| ); | ||
| } | ||
| if (this.hasOrgSelectorTarget) { | ||
| this.toggleSelector( | ||
| "api_key[organization_id]", | ||
| this.orgSelectorTarget, | ||
| selected, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| toggleSelector(fieldName, selectorTarget, enabled) { | ||
| if (enabled) { | ||
| selectorTarget.disabled = false; | ||
| this.removeHiddenField(fieldName); | ||
| } else { | ||
| this.selectorTarget.value = ""; | ||
| this.selectorTarget.disabled = true; | ||
| this.addHiddenRubygemField(); | ||
| selectorTarget.value = ""; | ||
| selectorTarget.disabled = true; | ||
| this.addHiddenField(fieldName); | ||
| } | ||
| } | ||
|
|
||
| addHiddenRubygemField() { | ||
| if (this.hiddenField) { | ||
| addHiddenField(fieldName) { | ||
| if (this.hiddenFields[fieldName]) { | ||
| return; | ||
| } | ||
| this.hiddenField = document.createElement("input"); | ||
| this.hiddenField.type = "hidden"; | ||
| this.hiddenField.name = "api_key[rubygem_id]"; | ||
| this.hiddenField.value = ""; | ||
| this.element.appendChild(this.hiddenField); | ||
|
|
||
| this.hiddenFields[fieldName] = document.createElement("input"); | ||
| this.hiddenFields[fieldName].type = "hidden"; | ||
| this.hiddenFields[fieldName].name = fieldName; | ||
| this.hiddenFields[fieldName].value = ""; | ||
| this.element.appendChild(this.hiddenFields[fieldName]); | ||
| } | ||
|
|
||
| removeHiddenRubygemField() { | ||
| if (this.hiddenField) { | ||
| this.hiddenField.remove(); | ||
| this.hiddenField = null; | ||
| removeHiddenField(fieldName) { | ||
| if (this.hiddenFields[fieldName]) { | ||
| this.hiddenFields[fieldName].remove(); | ||
| this.hiddenFields[fieldName] = null; | ||
| } | ||
| } | ||
| } | ||
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.
Should this be
initialize()instead of connect? I think initialize is called first and only once and connect is called every time the controller is added to the DOM