-
Notifications
You must be signed in to change notification settings - Fork 3
Publisher Command Center: One-click add integration for first-deploy workflow #146
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7a95a8e
implement better first deploy flow for publisher command center
toph-allen 0d1faa8
update manifest
toph-allen 72c0dfd
respond to feedback
toph-allen 35916d9
improve view layout
toph-allen 2011ede
update manifest
toph-allen 93c5b0a
Merge branch 'main' into toph/pcc-auto-add-integration
toph-allen 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
129 changes: 129 additions & 0 deletions
129
extensions/publisher-command-center/src/components/UnauthorizedView.js
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,129 @@ | ||
| import m from "mithril"; | ||
|
|
||
| const UnauthorizedView = { | ||
| oninit: function (vnode) { | ||
| vnode.state.integration = null; | ||
| vnode.state.loading = true; | ||
|
|
||
| // Check for available integration | ||
| m.request({ method: "GET", url: "api/integrations" }) | ||
| .then(response => { | ||
| vnode.state.integration = response; | ||
| vnode.state.loading = false; | ||
| m.redraw(); | ||
| }) | ||
| .catch(err => { | ||
| console.error("Failed to fetch integrations", err); | ||
| vnode.state.loading = false; | ||
| m.redraw(); | ||
| }); | ||
| }, | ||
|
|
||
| addIntegration: function (vnode) { | ||
| if (!vnode.state.integration) return; | ||
|
|
||
| m.request({ | ||
| method: "PUT", | ||
| url: "api/visitor-auth", | ||
| body: { integration_guid: vnode.state.integration.guid } | ||
| }) | ||
| .then(() => { | ||
| // Reload the top-most window to check authorization again | ||
| window.top.location.reload(); | ||
| }) | ||
| .catch(err => { | ||
| console.error("Failed to add integration", err); | ||
| }); | ||
| }, | ||
|
|
||
| view: function (vnode) { | ||
| // Show loading state | ||
| if (vnode.state.loading) { | ||
| return m("div.d-flex.justify-content-center", { style: { margin: "3rem" } }, [ | ||
| m("div.spinner-border.text-primary", { role: "status" }, | ||
| m("span.visually-hidden", "Loading...") | ||
| ) | ||
| ]); | ||
| } | ||
|
|
||
| // We have an integration ready to add | ||
| if (vnode.state.integration) { | ||
| return m("div.alert.alert-info", { | ||
| style: { | ||
| margin: "1rem auto", | ||
| maxWidth: "640px", | ||
| width: "calc(100% - 2rem)" | ||
| } | ||
| }, [ | ||
| m("div", { style: { marginBottom: "1rem" } }, [ | ||
| m("p", [ | ||
| "This content uses a ", | ||
| m("strong", "Visitor API Key"), | ||
| " integration to show users the content they have access to. A compatible integration is displayed below." | ||
| ]), | ||
| m("p", [ | ||
| "For more information, see ", | ||
| m("a", { | ||
| href: "https://docs.posit.co/connect/user/oauth-integrations/#obtaining-a-visitor-api-key", | ||
| target: "_blank" | ||
| }, "documentation on Visitor API Key integrations") | ||
| ]) | ||
| ]), | ||
| m("button.btn.btn-primary", { | ||
| onclick: () => this.addIntegration(vnode) | ||
| }, [ | ||
| m("i.fas.fa-plus.me-2"), | ||
| "Add the ", | ||
| m("strong", vnode.state.integration.title || vnode.state.integration.name || "Connect API"), | ||
| " Integration" | ||
| ]) | ||
| ]); | ||
| } | ||
|
|
||
| // No integration available | ||
| const baseUrl = window.location.origin; | ||
| const integrationSettingsUrl = `${baseUrl}/connect/#/system/integrations`; | ||
|
|
||
| return m("div.alert.alert-warning", { | ||
| style: { | ||
| margin: "1rem auto", | ||
| maxWidth: "640px", | ||
| width: "calc(100% - 2rem)" | ||
| } | ||
| }, [ | ||
| m("div", { style: { marginBottom: "1rem" } }, [ | ||
| m("p", "This content needs permission to show users the content they have access to."), | ||
| m("p", [ | ||
| "To allow this, an Administrator must configure a ", | ||
| m("strong", "Connect API"), | ||
| " integration on the ", | ||
| m("strong", [ | ||
| m("a", { href: integrationSettingsUrl, target: "_blank" }, "Integration Settings") | ||
| ]), | ||
| " page." | ||
| ]), | ||
| m("p", [ | ||
| "On that page, select ", | ||
| m("strong", "+ Add Integration"), | ||
| ". In the 'Select Integration' dropdown, choose ", | ||
| m("strong", "Connect API"), | ||
| ". The 'Max Role' field must be set to ", | ||
| m("strong", "Administrator"), | ||
| " or ", | ||
| m("strong", "Publisher"), | ||
| "; 'Viewer' will not work." | ||
| ]), | ||
| m("p", [ | ||
| "See the ", | ||
| m("a", { | ||
| href: "https://docs.posit.co/connect/admin/integrations/oauth-integrations/connect/", | ||
| target: "_blank" | ||
| }, "Connect API section of the Admin Guide"), | ||
| " for more detailed setup instructions." | ||
| ]) | ||
| ]) | ||
| ]); | ||
| } | ||
| }; | ||
|
|
||
| export default UnauthorizedView; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.