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

Fix pre-complete Access Token permissions #33691

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions routers/web/user/setting/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package setting
import (
"net/http"

"code.gitea.io/gitea/modules/json"

auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
Expand Down Expand Up @@ -42,6 +44,14 @@ func ApplicationsPost(ctx *context.Context) {
if ctx.HasError() {
loadApplicationsData(ctx)

// Send back the previously selected scopes as a JSON string
scopes, err := json.Marshal(form.Scope)
if err != nil {
ctx.ServerError("json.Marshal", err)
return
}
ctx.Data["Scopes"] = string(scopes)

ctx.HTML(http.StatusOK, tplSettingsApplications)
return
}
Expand Down
1 change: 1 addition & 0 deletions templates/user/settings/applications.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
data-no-access-label="{{ctx.Locale.Tr "settings.permission_no_access"}}"
data-read-label="{{ctx.Locale.Tr "settings.permission_read"}}"
data-write-label="{{ctx.Locale.Tr "settings.permission_write"}}"
data-scopes="{{.Scopes}}"
data-locale-component-failed-to-load="{{ctx.Locale.Tr "graphs.component_failed_to_load"}}"
>
</div>
Expand Down
114 changes: 96 additions & 18 deletions web_src/js/components/ScopedAccessTokenSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,104 @@
noAccessLabel: string;
readLabel: string;
writeLabel: string;
scopes: string[];
}>();

const categories = computed(() => {
const categories = [
'activitypub',
];
const categories = {
'activitypub': {
read: {
value: 'read:activitypub',
selected: props.scopes.includes('read:activitypub'),
},
write: {
value: 'write:activitypub',
selected: props.scopes.includes('write:activitypub'),
},
},
};
if (props.isAdmin) {
categories.push('admin');
categories['admin'] = {

Check failure on line 27 in web_src/js/components/ScopedAccessTokenSelector.vue

View workflow job for this annotation

GitHub Actions / frontend

Element implicitly has an 'any' type because expression of type '"admin"' can't be used to index type '{ activitypub: { read: { value: string; selected: boolean; }; write: { value: string; selected: boolean; }; }; }'.
read: {
value: 'read:admin',
selected: props.scopes.includes('read:admin'),
},
write: {
value: 'write:admin',
selected: props.scopes.includes('write:admin'),
},
};
}
categories.push(
'issue',
'misc',
'notification',
'organization',
'package',
'repository',
'user');
categories['issue'] = {

Check failure on line 38 in web_src/js/components/ScopedAccessTokenSelector.vue

View workflow job for this annotation

GitHub Actions / frontend

Element implicitly has an 'any' type because expression of type '"issue"' can't be used to index type '{ activitypub: { read: { value: string; selected: boolean; }; write: { value: string; selected: boolean; }; }; }'.
read: {
value: 'read:issue',
selected: props.scopes.includes('read:issue'),
},
write: {
value: 'write:issue',
selected: props.scopes.includes('write:issue'),
},
};
categories['misc'] = {

Check failure on line 48 in web_src/js/components/ScopedAccessTokenSelector.vue

View workflow job for this annotation

GitHub Actions / frontend

Element implicitly has an 'any' type because expression of type '"misc"' can't be used to index type '{ activitypub: { read: { value: string; selected: boolean; }; write: { value: string; selected: boolean; }; }; }'.
read: {
value: 'read:misc',
selected: props.scopes.includes('read:misc'),
},
write: {
value: 'write:misc',
selected: props.scopes.includes('write:misc'),
},
};
categories['notification'] = {

Check failure on line 58 in web_src/js/components/ScopedAccessTokenSelector.vue

View workflow job for this annotation

GitHub Actions / frontend

Element implicitly has an 'any' type because expression of type '"notification"' can't be used to index type '{ activitypub: { read: { value: string; selected: boolean; }; write: { value: string; selected: boolean; }; }; }'.
read: {
value: 'read:notification',
selected: props.scopes.includes('read:notification'),
},
write: {
value: 'write:notification',
selected: props.scopes.includes('write:notification'),
},
};
categories['organization'] = {

Check failure on line 68 in web_src/js/components/ScopedAccessTokenSelector.vue

View workflow job for this annotation

GitHub Actions / frontend

Element implicitly has an 'any' type because expression of type '"organization"' can't be used to index type '{ activitypub: { read: { value: string; selected: boolean; }; write: { value: string; selected: boolean; }; }; }'.
read: {
value: 'read:organization',
selected: props.scopes.includes('read:organization'),
},
write: {
value: 'write:organization',
selected: props.scopes.includes('write:organization'),
},
};
categories['package'] = {

Check failure on line 78 in web_src/js/components/ScopedAccessTokenSelector.vue

View workflow job for this annotation

GitHub Actions / frontend

Element implicitly has an 'any' type because expression of type '"package"' can't be used to index type '{ activitypub: { read: { value: string; selected: boolean; }; write: { value: string; selected: boolean; }; }; }'.
read: {
value: 'read:package',
selected: props.scopes.includes('read:package'),
},
write: {
value: 'write:package',
selected: props.scopes.includes('write:package'),
},
};
categories['repository'] = {

Check failure on line 88 in web_src/js/components/ScopedAccessTokenSelector.vue

View workflow job for this annotation

GitHub Actions / frontend

Element implicitly has an 'any' type because expression of type '"repository"' can't be used to index type '{ activitypub: { read: { value: string; selected: boolean; }; write: { value: string; selected: boolean; }; }; }'.
read: {
value: 'read:repository',
selected: props.scopes.includes('read:repository'),
},
write: {
value: 'write:repository',
selected: props.scopes.includes('write:repository'),
},
};
categories['user'] = {

Check failure on line 98 in web_src/js/components/ScopedAccessTokenSelector.vue

View workflow job for this annotation

GitHub Actions / frontend

Element implicitly has an 'any' type because expression of type '"user"' can't be used to index type '{ activitypub: { read: { value: string; selected: boolean; }; write: { value: string; selected: boolean; }; }; }'.
read: {
value: 'read:user',
selected: props.scopes.includes('read:user'),
},
write: {
value: 'write:user',
selected: props.scopes.includes('write:user'),
},
};
return categories;
});

Expand Down Expand Up @@ -56,7 +137,7 @@
</script>

<template>
<div v-for="category in categories" :key="category" class="field tw-pl-1 tw-pb-1 access-token-category">
<div v-for="(permissions, category) in categories" :key="category" class="field tw-pl-1 tw-pb-1 access-token-category">
<label class="category-label" :for="'access-token-scope-' + category">
{{ category }}
</label>
Expand All @@ -69,11 +150,8 @@
<option value="">
{{ noAccessLabel }}
</option>
<option :value="'read:' + category">
{{ readLabel }}
</option>
<option :value="'write:' + category">
{{ writeLabel }}
<option v-for="(permission, action) in permissions" :key="permission.value" :value="permission.value" :selected="permission.selected">
{{ action === 'read' ? readLabel : writeLabel }}
</option>
</select>
</div>
Expand Down
1 change: 1 addition & 0 deletions web_src/js/features/scoped-access-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export async function initScopedAccessTokenCategories() {
noAccessLabel: el.getAttribute('data-no-access-label'),
readLabel: el.getAttribute('data-read-label'),
writeLabel: el.getAttribute('data-write-label'),
scopes: JSON.parse(el.getAttribute('data-scopes').length > 0 ? el.getAttribute('data-scopes') : '[]'),
});
View.mount(el);
} catch (err) {
Expand Down
Loading