Skip to content

Commit a7eecc3

Browse files
committed
Remove Vue scoped-access-token-selector component
1 parent 6c5951d commit a7eecc3

File tree

7 files changed

+50
-114
lines changed

7 files changed

+50
-114
lines changed

models/auth/access_token_scope.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
type AccessTokenScopeCategory int
1515

1616
const (
17-
AccessTokenScopeCategoryActivityPub = iota
17+
AccessTokenScopeCategoryActivityPub AccessTokenScopeCategory = iota
1818
AccessTokenScopeCategoryAdmin
1919
AccessTokenScopeCategoryMisc // WARN: this is now just a placeholder, don't remove it which will change the following values
2020
AccessTokenScopeCategoryNotification
@@ -38,6 +38,32 @@ var AllAccessTokenScopeCategories = []AccessTokenScopeCategory{
3838
AccessTokenScopeCategoryUser,
3939
}
4040

41+
// AccessTokenScopeCategoryNames maps AccessTokenScopeCategory to their string representations
42+
var AccessTokenScopeCategoryNames = map[AccessTokenScopeCategory]string{
43+
AccessTokenScopeCategoryActivityPub: "activitypub",
44+
AccessTokenScopeCategoryAdmin: "admin",
45+
AccessTokenScopeCategoryMisc: "misc",
46+
AccessTokenScopeCategoryNotification: "notification",
47+
AccessTokenScopeCategoryOrganization: "organization",
48+
AccessTokenScopeCategoryPackage: "package",
49+
AccessTokenScopeCategoryIssue: "issue",
50+
AccessTokenScopeCategoryRepository: "repository",
51+
AccessTokenScopeCategoryUser: "user",
52+
}
53+
54+
// AccessTokenScopeCategoryNames is a list of all access token scope category names
55+
var AllAccessTokenScopeCategoryNames = []string{
56+
AccessTokenScopeCategoryNames[AccessTokenScopeCategoryActivityPub],
57+
AccessTokenScopeCategoryNames[AccessTokenScopeCategoryAdmin],
58+
AccessTokenScopeCategoryNames[AccessTokenScopeCategoryMisc],
59+
AccessTokenScopeCategoryNames[AccessTokenScopeCategoryNotification],
60+
AccessTokenScopeCategoryNames[AccessTokenScopeCategoryOrganization],
61+
AccessTokenScopeCategoryNames[AccessTokenScopeCategoryPackage],
62+
AccessTokenScopeCategoryNames[AccessTokenScopeCategoryIssue],
63+
AccessTokenScopeCategoryNames[AccessTokenScopeCategoryRepository],
64+
AccessTokenScopeCategoryNames[AccessTokenScopeCategoryUser],
65+
}
66+
4167
// AccessTokenScopeLevel represents the access levels without a given scope category
4268
type AccessTokenScopeLevel int
4369

models/auth/access_token_scope_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestAccessTokenScope_Normalize(t *testing.T) {
2525
{"write:activitypub,write:admin,write:misc,write:notification,write:organization,write:package,write:issue,write:repository,write:user,public-only", "public-only,all", nil},
2626
}
2727

28-
for _, scope := range []string{"activitypub", "admin", "misc", "notification", "organization", "package", "issue", "repository", "user"} {
28+
for _, scope := range AllAccessTokenScopeCategoryNames {
2929
tests = append(tests,
3030
scopeTestNormalize{AccessTokenScope(fmt.Sprintf("read:%s", scope)), AccessTokenScope(fmt.Sprintf("read:%s", scope)), nil},
3131
scopeTestNormalize{AccessTokenScope(fmt.Sprintf("write:%s", scope)), AccessTokenScope(fmt.Sprintf("write:%s", scope)), nil},
@@ -59,7 +59,7 @@ func TestAccessTokenScope_HasScope(t *testing.T) {
5959
{"public-only", "read:issue", false, nil},
6060
}
6161

62-
for _, scope := range []string{"activitypub", "admin", "misc", "notification", "organization", "package", "issue", "repository", "user"} {
62+
for _, scope := range AllAccessTokenScopeCategoryNames {
6363
tests = append(tests,
6464
scopeTestHasScope{
6565
AccessTokenScope(fmt.Sprintf("read:%s", scope)),

routers/web/user/setting/applications.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func loadApplicationsData(ctx *context.Context) {
9898
return
9999
}
100100
ctx.Data["Tokens"] = tokens
101+
ctx.Data["TokenCategories"] = auth_model.AllAccessTokenScopeCategoryNames
101102
ctx.Data["EnableOAuth2"] = setting.OAuth2.Enabled
102103
ctx.Data["IsAdmin"] = ctx.Doer.IsAdmin
103104
if setting.OAuth2.Enabled {

templates/user/settings/applications.tmpl

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,26 @@
7777
<p class="activity meta">
7878
<i>{{ctx.Locale.Tr "settings.access_token_desc" (HTMLFormat `href="%s/api/swagger" target="_blank"` AppSubUrl) (`href="https://docs.gitea.com/development/oauth2-provider#scopes" target="_blank"`|SafeHTML)}}</i>
7979
</p>
80-
<div id="scoped-access-token-selector"
81-
data-is-admin="{{if .IsAdmin}}true{{else}}false{{end}}"
82-
data-no-access-label="{{ctx.Locale.Tr "settings.permission_no_access"}}"
83-
data-read-label="{{ctx.Locale.Tr "settings.permission_read"}}"
84-
data-write-label="{{ctx.Locale.Tr "settings.permission_write"}}"
85-
data-locale-component-failed-to-load="{{ctx.Locale.Tr "graphs.component_failed_to_load"}}"
86-
>
87-
</div>
80+
{{range $category := .TokenCategories}}
81+
<div class="field tw-pl-1 tw-pb-1 access-token-category">
82+
<label class="category-label" for="access-token-scope-{{$category}}">
83+
{{$category}}
84+
</label>
85+
<div class="gitea-select">
86+
<select class="ui selection access-token-select" name="scope" id="access-token-scope-{{$category}}">
87+
<option value="">
88+
{{ctx.Locale.Tr "settings.permission_no_access"}}
89+
</option>
90+
<option value="read:{{$category}}">
91+
{{ctx.Locale.Tr "settings.permission_read"}}
92+
</option>
93+
<option value="write:{{$category}}">
94+
{{ctx.Locale.Tr "settings.permission_write"}}
95+
</option>
96+
</select>
97+
</div>
98+
</div>
99+
{{end}}
88100
</details>
89101
<button id="scoped-access-submit" class="ui primary button">
90102
{{ctx.Locale.Tr "settings.generate_token"}}

web_src/js/components/ScopedAccessTokenSelector.vue

Lines changed: 0 additions & 81 deletions
This file was deleted.

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

Lines changed: 0 additions & 20 deletions
This file was deleted.

web_src/js/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ import {initColorPickers} from './features/colorpicker.ts';
6868
import {initAdminSelfCheck} from './features/admin/selfcheck.ts';
6969
import {initOAuth2SettingsDisableCheckbox} from './features/oauth2-settings.ts';
7070
import {initGlobalFetchAction} from './features/common-fetch-action.ts';
71-
import {initScopedAccessTokenCategories} from './features/scoped-access-token.ts';
7271
import {
7372
initFootLanguageMenu,
7473
initGlobalDropdown,
@@ -209,7 +208,6 @@ onDomReady(() => {
209208
initUserSettings,
210209
initRepoDiffView,
211210
initPdfViewer,
212-
initScopedAccessTokenCategories,
213211
initColorPickers,
214212

215213
initOAuth2SettingsDisableCheckbox,

0 commit comments

Comments
 (0)