gitea/templates/repo/settings/tags.tmpl

132 lines
4.9 KiB
Handlebars
Raw Normal View History

{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content repository settings edit">
{{template "repo/header" .}}
{{template "repo/settings/navbar" .}}
<div class="ui container">
{{template "base/alert" .}}
{{if .Repository.IsArchived}}
<div class="ui warning message">
{{.locale.Tr "repo.settings.archive.tagsettings_unavailable"}}
</div>
{{else}}
<h4 class="ui top attached header">
{{.locale.Tr "repo.settings.tags.protection"}}
</h4>
<div class="ui attached segment">
<div class="ui grid">
<div class="eight wide column">
<div class="ui segment">
<form class="ui form" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
<div class="field">
<label>{{.locale.Tr "repo.settings.tags.protection.pattern"}}</label>
<div id="search-tag-box" class="ui search">
<div class="ui input">
<input class="prompt" name="name_pattern" autocomplete="off" value="{{.name_pattern}}" placeholder="v*" autofocus required>
</div>
<div class="help">{{.locale.Tr "repo.settings.tags.protection.pattern.description" | Safe}}</div>
</div>
</div>
<div class="whitelist field">
<label>{{.locale.Tr "repo.settings.tags.protection.allowed.users"}}</label>
<div class="ui multiple search selection dropdown">
<input type="hidden" name="allowlist_users" value="{{.allowlist_users}}">
<div class="default text">{{.locale.Tr "repo.settings.protect_whitelist_search_users"}}</div>
<div class="menu">
{{range .Users}}
<div class="item" data-value="{{.ID}}">
Allow both fullname and username search when `DEFAULT_SHOW_FULL_NAME` is true (#23463) This PR adds the ability to search both fullname and username for assignees, reviewers and author search boxes when the config [`DEFAULT_SHOW_FULL_NAME`](https://github.com/go-gitea/gitea/blob/6ff5400af91aefb02cbc7dd59f6be23cc2bf7865/custom/conf/app.example.ini#L1238) in `app.ini` is set to `true`. Which is originally raised [here](https://projects.blender.org/infrastructure/blender-projects-platform/issues/14) And if `DEFAULT_SHOW_FULL_NAME` is set to `false`(default value), these search boxes will only show username. Example: When `DEFAULT_SHOW_FULL_NAME = true` <img width="1220" alt="截屏2023-03-14 14 28 06" src="https://user-images.githubusercontent.com/17645053/224914546-80ef2837-ab72-4d66-9f00-6eb77ed4baaa.png"> When `DEFAULT_SHOW_FULL_NAME = false` (default value) <img width="1243" alt="截屏2023-03-14 14 29 37" src="https://user-images.githubusercontent.com/17645053/224914798-f69ec8a2-0929-4330-827c-3e30188f9b47.png"> The specific search boxes that adapts these changes include: 1. Author, Assignee search boxes in pull requests tab and issues tab in repository <img width="1283" alt="截屏2023-03-14 14 35 01" src="https://user-images.githubusercontent.com/17645053/224916250-8e452525-71d6-4b48-bf1c-bf7a176abaaa.png"> 2. Assigee and Author on milestones issue page (Added missing search box for author here) <img width="1261" alt="截屏2023-03-14 14 38 20" src="https://user-images.githubusercontent.com/17645053/224916569-d3105619-7824-4bb8-a6d0-1a600eaa9963.png"> 3. Assignee on issues and PR Sidebar, Reviewer on PR Sidebar <img width="976" alt="截屏2023-03-14 14 41 06" src="https://user-images.githubusercontent.com/17645053/224917431-c45d821e-9660-4f58-a196-5979a0bb64ce.png"> <img width="1027" alt="截屏2023-03-14 14 41 58" src="https://user-images.githubusercontent.com/17645053/224917290-ad4dbc52-0c20-45c4-9fce-9dcd59ad7d47.png"> 4. Assignee when creating new issue <img width="961" alt="截屏2023-03-14 14 44 33" src="https://user-images.githubusercontent.com/17645053/224917694-34bee5a7-e975-4f37-8862-56ebc2556808.png"> 5. Whitelisted users for pushing, Whitelisted users for merging and Whitelisted reviewers in Protected branch settings <img width="920" alt="截屏2023-03-14 14 48 56" src="https://user-images.githubusercontent.com/17645053/224918551-9b46b44e-b075-4895-8d33-1aafc7d3c8e5.png"> <img width="901" alt="截屏2023-03-14 14 49 02" src="https://user-images.githubusercontent.com/17645053/224918584-efa66f23-a593-4e26-a3eb-bb1fbc5516ae.png"> <img width="944" alt="截屏2023-03-14 14 49 21" src="https://user-images.githubusercontent.com/17645053/224918591-be60455d-0513-4f66-84f6-b5e1bc40ff91.png"> 6. "Allowed users" in tags settings <img width="935" alt="截屏2023-03-14 14 50 11" src="https://user-images.githubusercontent.com/17645053/224918701-797699aa-c7e5-4290-b3fe-27dcead1c6c7.png">
2023-03-17 03:32:25 +11:00
{{avatar $.Context . 28 "mini"}}{{template "repo/search_name" .}}
</div>
{{end}}
</div>
</div>
</div>
{{if .Owner.IsOrganization}}
<div class="whitelist field">
<label>{{.locale.Tr "repo.settings.tags.protection.allowed.teams"}}</label>
<div class="ui multiple search selection dropdown">
<input type="hidden" name="allowlist_teams" value="{{.allowlist_teams}}">
<div class="default text">{{.locale.Tr "repo.settings.protect_whitelist_search_teams"}}</div>
<div class="menu">
{{range .Teams}}
<div class="item" data-value="{{.ID}}">
{{svg "octicon-people"}}
{{.Name}}
</div>
{{end}}
</div>
</div>
</div>
{{end}}
<div class="field">
{{if .PageIsEditProtectedTag}}
<button class="ui green button">
{{$.locale.Tr "save"}}
</button>
<a class="ui primary button" href="{{$.RepoLink}}/settings/tags">
{{$.locale.Tr "cancel"}}
</a>
{{else}}
<button class="ui green button">
{{$.locale.Tr "repo.settings.tags.protection.create"}}
</button>
{{end}}
</div>
</form>
</div>
</div>
<div class="sixteen wide column">
<table class="ui single line table">
<thead>
<th>{{.locale.Tr "repo.settings.tags.protection.pattern"}}</th>
<th>{{.locale.Tr "repo.settings.tags.protection.allowed"}}</th>
<th></th>
</thead>
<tbody>
{{range .ProtectedTags}}
<tr>
<td><pre>{{.NamePattern}}</pre></td>
<td>
{{if or .AllowlistUserIDs (and $.Owner.IsOrganization .AllowlistTeamIDs)}}
{{$userIDs := .AllowlistUserIDs}}
{{range $.Users}}
{{if SliceUtils.Contains $userIDs .ID}}
Add context cache as a request level cache (#22294) To avoid duplicated load of the same data in an HTTP request, we can set a context cache to do that. i.e. Some pages may load a user from a database with the same id in different areas on the same page. But the code is hidden in two different deep logic. How should we share the user? As a result of this PR, now if both entry functions accept `context.Context` as the first parameter and we just need to refactor `GetUserByID` to reuse the user from the context cache. Then it will not be loaded twice on an HTTP request. But of course, sometimes we would like to reload an object from the database, that's why `RemoveContextData` is also exposed. The core context cache is here. It defines a new context ```go type cacheContext struct { ctx context.Context data map[any]map[any]any lock sync.RWMutex } var cacheContextKey = struct{}{} func WithCacheContext(ctx context.Context) context.Context { return context.WithValue(ctx, cacheContextKey, &cacheContext{ ctx: ctx, data: make(map[any]map[any]any), }) } ``` Then you can use the below 4 methods to read/write/del the data within the same context. ```go func GetContextData(ctx context.Context, tp, key any) any func SetContextData(ctx context.Context, tp, key, value any) func RemoveContextData(ctx context.Context, tp, key any) func GetWithContextCache[T any](ctx context.Context, cacheGroupKey string, cacheTargetID any, f func() (T, error)) (T, error) ``` Then let's take a look at how `system.GetString` implement it. ```go func GetSetting(ctx context.Context, key string) (string, error) { return cache.GetWithContextCache(ctx, contextCacheKey, key, func() (string, error) { return cache.GetString(genSettingCacheKey(key), func() (string, error) { res, err := GetSettingNoCache(ctx, key) if err != nil { return "", err } return res.SettingValue, nil }) }) } ``` First, it will check if context data include the setting object with the key. If not, it will query from the global cache which may be memory or a Redis cache. If not, it will get the object from the database. In the end, if the object gets from the global cache or database, it will be set into the context cache. An object stored in the context cache will only be destroyed after the context disappeared.
2023-02-16 00:37:34 +11:00
<a class="ui basic label" href="{{.HomeLink}}">{{avatar $.Context . 26}} {{.GetDisplayName}}</a>
{{end}}
{{end}}
{{if $.Owner.IsOrganization}}
{{$teamIDs := .AllowlistTeamIDs}}
{{range $.Teams}}
{{if SliceUtils.Contains $teamIDs .ID}}
<a class="ui basic label" href="{{$.Owner.OrganisationLink}}/teams/{{PathEscape .LowerName}}">{{.Name}}</a>
{{end}}
{{end}}
{{end}}
{{else}}
{{$.locale.Tr "repo.settings.tags.protection.allowed.noone"}}
{{end}}
</td>
<td class="right aligned">
<a class="ui tiny primary button" href="{{$.RepoLink}}/settings/tags/{{.ID}}">{{$.locale.Tr "edit"}}</a>
<form class="gt-dib" action="{{$.RepoLink}}/settings/tags/delete" method="post">
{{$.CsrfTokenHtml}}
<input type="hidden" name="id" value="{{.ID}}">
<button class="ui tiny red button">{{$.locale.Tr "remove"}}</button>
</form>
</td>
</tr>
{{else}}
<tr class="center aligned"><td colspan="3">{{.locale.Tr "repo.settings.tags.protection.none"}}</td></tr>
{{end}}
</tbody>
</table>
</div>
</div>
</div>
{{end}}
</div>
</div>
{{template "base/footer" .}}