Skip to content

Commit 14e44d2

Browse files
committed
Fix pre-complete PAT permissions
1 parent 9e75c54 commit 14e44d2

File tree

4 files changed

+107
-18
lines changed

4 files changed

+107
-18
lines changed

routers/web/user/setting/applications.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package setting
66

77
import (
8+
"encoding/json"
89
"net/http"
910

1011
auth_model "code.gitea.io/gitea/models/auth"
@@ -42,6 +43,14 @@ func ApplicationsPost(ctx *context.Context) {
4243
if ctx.HasError() {
4344
loadApplicationsData(ctx)
4445

46+
// Send back the previously selected scopes as a JSON string
47+
scopes, err := json.Marshal(form.Scope)
48+
if err != nil {
49+
ctx.ServerError("json.Marshal", err)
50+
return
51+
}
52+
ctx.Data["Scopes"] = string(scopes)
53+
4554
ctx.HTML(http.StatusOK, tplSettingsApplications)
4655
return
4756
}

templates/user/settings/applications.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
data-no-access-label="{{ctx.Locale.Tr "settings.permission_no_access"}}"
8383
data-read-label="{{ctx.Locale.Tr "settings.permission_read"}}"
8484
data-write-label="{{ctx.Locale.Tr "settings.permission_write"}}"
85+
data-scopes="{{.Scopes}}"
8586
data-locale-component-failed-to-load="{{ctx.Locale.Tr "graphs.component_failed_to_load"}}"
8687
>
8788
</div>

web_src/js/components/ScopedAccessTokenSelector.vue

Lines changed: 96 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,104 @@ const props = defineProps<{
77
noAccessLabel: string;
88
readLabel: string;
99
writeLabel: string;
10+
scopes: string[];
1011
}>();
1112
1213
const categories = computed(() => {
13-
const categories = [
14-
'activitypub',
15-
];
14+
const categories = {
15+
'activitypub': {
16+
read: {
17+
value: 'read:activitypub',
18+
selected: props.scopes.includes('read:activitypub'),
19+
},
20+
write: {
21+
value: 'write:activitypub',
22+
selected: props.scopes.includes('write:activitypub'),
23+
},
24+
},
25+
};
1626
if (props.isAdmin) {
17-
categories.push('admin');
27+
categories['admin'] = {
28+
read: {
29+
value: 'read:admin',
30+
selected: props.scopes.includes('read:admin'),
31+
},
32+
write: {
33+
value: 'write:admin',
34+
selected: props.scopes.includes('write:admin'),
35+
},
36+
};
1837
}
19-
categories.push(
20-
'issue',
21-
'misc',
22-
'notification',
23-
'organization',
24-
'package',
25-
'repository',
26-
'user');
38+
categories['issue'] = {
39+
read: {
40+
value: 'read:issue',
41+
selected: props.scopes.includes('read:issue'),
42+
},
43+
write: {
44+
value: 'write:issue',
45+
selected: props.scopes.includes('write:issue'),
46+
},
47+
};
48+
categories['misc'] = {
49+
read: {
50+
value: 'read:misc',
51+
selected: props.scopes.includes('read:misc'),
52+
},
53+
write: {
54+
value: 'write:misc',
55+
selected: props.scopes.includes('write:misc'),
56+
},
57+
};
58+
categories['notification'] = {
59+
read: {
60+
value: 'read:notification',
61+
selected: props.scopes.includes('read:notification'),
62+
},
63+
write: {
64+
value: 'write:notification',
65+
selected: props.scopes.includes('write:notification'),
66+
},
67+
};
68+
categories['organization'] = {
69+
read: {
70+
value: 'read:organization',
71+
selected: props.scopes.includes('read:organization'),
72+
},
73+
write: {
74+
value: 'write:organization',
75+
selected: props.scopes.includes('write:organization'),
76+
},
77+
};
78+
categories['package'] = {
79+
read: {
80+
value: 'read:package',
81+
selected: props.scopes.includes('read:package'),
82+
},
83+
write: {
84+
value: 'write:package',
85+
selected: props.scopes.includes('write:package'),
86+
},
87+
};
88+
categories['repository'] = {
89+
read: {
90+
value: 'read:repository',
91+
selected: props.scopes.includes('read:repository'),
92+
},
93+
write: {
94+
value: 'write:repository',
95+
selected: props.scopes.includes('write:repository'),
96+
},
97+
};
98+
categories['user'] = {
99+
read: {
100+
value: 'read:user',
101+
selected: props.scopes.includes('read:user'),
102+
},
103+
write: {
104+
value: 'write:user',
105+
selected: props.scopes.includes('write:user'),
106+
},
107+
};
27108
return categories;
28109
});
29110
@@ -56,7 +137,7 @@ function onClickSubmit(e: Event) {
56137
</script>
57138

58139
<template>
59-
<div v-for="category in categories" :key="category" class="field tw-pl-1 tw-pb-1 access-token-category">
140+
<div v-for="(permissions, category) in categories" :key="category" class="field tw-pl-1 tw-pb-1 access-token-category">
60141
<label class="category-label" :for="'access-token-scope-' + category">
61142
{{ category }}
62143
</label>
@@ -69,11 +150,8 @@ function onClickSubmit(e: Event) {
69150
<option value="">
70151
{{ noAccessLabel }}
71152
</option>
72-
<option :value="'read:' + category">
73-
{{ readLabel }}
74-
</option>
75-
<option :value="'write:' + category">
76-
{{ writeLabel }}
153+
<option v-for="(permission, action) in permissions" :key="permission.value" :value="permission.value" :selected="permission.selected">
154+
{{ action === 'read' ? readLabel : writeLabel }}
77155
</option>
78156
</select>
79157
</div>

web_src/js/features/scoped-access-token.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export async function initScopedAccessTokenCategories() {
1111
noAccessLabel: el.getAttribute('data-no-access-label'),
1212
readLabel: el.getAttribute('data-read-label'),
1313
writeLabel: el.getAttribute('data-write-label'),
14+
scopes: JSON.parse(el.getAttribute('data-scopes')),
1415
});
1516
View.mount(el);
1617
} catch (err) {

0 commit comments

Comments
 (0)