Skip to content
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

Frontend/Backend: Allow users to install from custom extension tags #2848

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
W
  • Loading branch information
JoaoMario109 committed Jul 30, 2024
commit edb282faec458ee6599b66db73760c323892d822
9 changes: 1 addition & 8 deletions core/frontend/src/components/common/JsonEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<v-divider />

<slot name="controls" />
<v-btn
v-tooltip="save_tooltip"
class="editor-control"
Expand Down Expand Up @@ -43,14 +44,6 @@ export default {
type: Object,
required: true,
},
schema: {
type: Object,
default: () => ({}),
},
schemaRefs: {
type: Object,
default: () => ({}),
},
},
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

v-bind="attrs"
v-on="on"
@click="$emit('clicked', extension.identifier, selected_version, is_installed)"
@click="performAction"
>
{{ is_installed ? 'Uninstall' : 'Install' }}
</v-btn>
Expand Down Expand Up @@ -115,7 +115,22 @@
v-model="editing_permissions"
style="width:100%; height:100%"
@save="onEditingPermissionsSave"
/>
>
<template
v-if="is_reset_editing_permissions_visible"
#controls
>
<v-btn
v-tooltip="'Reset to default permissions'"
class="editor-control"
icon
color="white"
@click="onResetToDefaultPermissions"
>
<v-icon>mdi-restore</v-icon>
</v-btn>
</template>
</json-editor>
</v-card>
</v-expansion-panel-content>
</v-expansion-panel>
Expand Down Expand Up @@ -162,6 +177,7 @@ export default Vue.extend({
return {
selected_version: '' as string | null | undefined,
editing_permissions: '' as string | JSONValue,
custom_permissions: {} as Record<string, JSONValue>,
}
},
computed: {
Expand Down Expand Up @@ -213,11 +229,19 @@ export default Vue.extend({
),
]
},
is_reset_editing_permissions_visible(): boolean {
if (!this.selected_version) {
return false
}

return JSON.stringify(this.editing_permissions) !== JSON.stringify(this.selected?.permissions)
},
},
watch: {
extension() {
this.selected_version = this.getLatestTag()
this.editing_permissions = this.getVersionPermissions()
this.custom_permissions = {}
},
selected_version() {
this.editing_permissions = this.getVersionPermissions()
Expand All @@ -238,15 +262,36 @@ export default Vue.extend({
return 'Select a version to view permissions'
}

const versions = this.extension?.versions
if (versions && this.selected_version in versions) {
return versions[this.selected_version].permissions
if (this.selected) {
return this.custom_permissions[this.selected_version] ?? this.selected.permissions
}

return 'No permissions required'
},
onEditingPermissionsSave() {
console.log('Permissions saved')
onEditingPermissionsSave(json: JSONValue) {
if (this.selected_version) {
this.editing_permissions = json
this.custom_permissions[this.selected_version] = json
}
},
onResetToDefaultPermissions() {
if (this.selected_version) {
delete this.custom_permissions[this.selected_version]
this.editing_permissions = this.getVersionPermissions()
}
},
performAction() {
if (!this.selected_version) {
return
}

this.$emit(
'clicked',
this.extension.identifier,
this.selected_version,
JSON.stringify(this.custom_permissions[this.selected_version]),
this.is_installed,
)
},
},
})
Expand Down Expand Up @@ -280,6 +325,11 @@ div.readme ul {
margin-left: 20px;
}

.editor-control {
margin: 0;
opacity: 0.7;
}

.extension-creators {
flex-grow: 1;
margin-left: 10px;
Expand Down
13 changes: 9 additions & 4 deletions core/frontend/src/views/ExtensionManagerView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,12 @@ export default Vue.extend({
this.status_text = ''
})
},
async performActionFromModal(identifier: string, tag: string, isInstalled: boolean) {
async performActionFromModal(
identifier: string,
tag: string,
permissions: string | undefined,
isInstalled: boolean,
) {
if (isInstalled) {
const ext = this.installed_extensions[identifier]
if (!ext) {
Expand All @@ -541,10 +546,10 @@ export default Vue.extend({
this.show_dialog = false
await this.uninstall(ext)
} else {
await this.installFromSelected(tag)
await this.installFromSelected(tag, permissions)
}
},
async installFromSelected(tag: string) {
async installFromSelected(tag: string, permissions: string | undefined) {
if (!this.selected_extension) {
return
}
Expand All @@ -555,7 +560,7 @@ export default Vue.extend({
tag,
true,
JSON.stringify(this.selected_extension?.versions[tag].permissions),
'',
permissions ?? '',
)
},
async uninstall(extension: InstalledExtensionData) {
Expand Down
Loading