Skip to content

Commit

Permalink
Merge branch 'main' into navrework
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind authored Jun 20, 2023
2 parents 02ce207 + feda506 commit ab50a4d
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 60 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/release-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
- run: git fetch --unshallow --quiet --tags --force
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- name: Get cleaned branch name
Expand All @@ -75,12 +78,14 @@ jobs:
- name: build rootful docker image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: gitea/gitea:${{ steps.clean_name.outputs.branch }}
- name: build rootless docker image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
file: Dockerfile.rootless
Expand Down
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ endif
STORED_VERSION_FILE := VERSION
HUGO_VERSION ?= 0.111.3

GITHUB_REF_TYPE ?= branch
GITHUB_REF_NAME ?= $(shell git rev-parse --abbrev-ref HEAD)

ifneq ($(GITHUB_REF_TYPE),branch)
VERSION ?= $(subst v,,$(GITHUB_REF_NAME))
GITEA_VERSION ?= $(GITHUB_REF_NAME)
Expand Down Expand Up @@ -1011,9 +1014,5 @@ docker:
docker build --disable-content-trust=false -t $(DOCKER_REF) .
# support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="bindata sqlite sqlite_unlock_notify" .

.PHONY: docker-build
docker-build:
docker run -ti --rm -v "$(CURDIR):/srv/app/src/code.gitea.io/gitea" -w /srv/app/src/code.gitea.io/gitea -e TAGS="bindata $(TAGS)" LDFLAGS="$(LDFLAGS)" CGO_EXTRA_CFLAGS="$(CGO_EXTRA_CFLAGS)" webhippie/golang:edge make clean build

# This endif closes the if at the top of the file
endif
8 changes: 4 additions & 4 deletions models/issues/tracked_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ func addTime(ctx context.Context, user *user_model.User, issue *Issue, amount in
return tt, db.Insert(ctx, tt)
}

// TotalTimes returns the spent time for each user by an issue
func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]string, error) {
// TotalTimes returns the spent time in seconds for each user by an issue
func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]int64, error) {
trackedTimes, err := GetTrackedTimes(db.DefaultContext, options)
if err != nil {
return nil, err
Expand All @@ -211,7 +211,7 @@ func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]string,
totalTimesByUser[t.UserID] += t.Time
}

totalTimes := make(map[*user_model.User]string)
totalTimes := make(map[*user_model.User]int64)
// Fetching User and making time human readable
for userID, total := range totalTimesByUser {
user, err := user_model.GetUserByID(db.DefaultContext, userID)
Expand All @@ -221,7 +221,7 @@ func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]string,
}
return nil, err
}
totalTimes[user] = util.SecToTime(total)
totalTimes[user] = total
}
return totalTimes, nil
}
Expand Down
12 changes: 6 additions & 6 deletions models/issues/tracked_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ func TestTotalTimes(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, total, 1)
for user, time := range total {
assert.Equal(t, int64(1), user.ID)
assert.Equal(t, "6 minutes 40 seconds", time)
assert.EqualValues(t, 1, user.ID)
assert.EqualValues(t, 400, time)
}

total, err = issues_model.TotalTimes(&issues_model.FindTrackedTimesOptions{IssueID: 2})
assert.NoError(t, err)
assert.Len(t, total, 2)
for user, time := range total {
if user.ID == 2 {
assert.Equal(t, "1 hour 1 minute", time)
assert.EqualValues(t, 3662, time)
} else if user.ID == 1 {
assert.Equal(t, "20 seconds", time)
assert.EqualValues(t, 20, time)
} else {
assert.Error(t, assert.AnError)
}
Expand All @@ -107,8 +107,8 @@ func TestTotalTimes(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, total, 1)
for user, time := range total {
assert.Equal(t, int64(2), user.ID)
assert.Equal(t, "1 second", time)
assert.EqualValues(t, 2, user.ID)
assert.EqualValues(t, 1, time)
}

total, err = issues_model.TotalTimes(&issues_model.FindTrackedTimesOptions{IssueID: 4})
Expand Down
2 changes: 1 addition & 1 deletion routers/api/actions/runner/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func generateTaskContext(t *actions_model.ActionTask) *structpb.Struct {
"head_ref": headRef, // string, The head_ref or source branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is either pull_request or pull_request_target.
"job": fmt.Sprint(t.JobID), // string, The job_id of the current job.
"ref": t.Job.Run.Ref, // string, The fully-formed ref of the branch or tag that triggered the workflow run. For workflows triggered by push, this is the branch or tag ref that was pushed. For workflows triggered by pull_request, this is the pull request merge branch. For workflows triggered by release, this is the release tag created. For other triggers, this is the branch or tag ref that triggered the workflow run. This is only set if a branch or tag is available for the event type. The ref given is fully-formed, meaning that for branches the format is refs/heads/<branch_name>, for pull requests it is refs/pull/<pr_number>/merge, and for tags it is refs/tags/<tag_name>. For example, refs/heads/feature-branch-1.
"ref_name": refName.String(), // string, The short ref name of the branch or tag that triggered the workflow run. This value matches the branch or tag name shown on GitHub. For example, feature-branch-1.
"ref_name": refName.ShortName(), // string, The short ref name of the branch or tag that triggered the workflow run. This value matches the branch or tag name shown on GitHub. For example, feature-branch-1.
"ref_protected": false, // boolean, true if branch protections are configured for the ref that triggered the workflow run.
"ref_type": refName.RefType(), // string, The type of ref that triggered the workflow run. Valid values are branch or tag.
"path": "", // string, Path on the runner to the file that sets system PATH variables from workflow commands. This file is unique to the current step and is a different file for each step in a job. For more information, see "Workflow commands for GitHub Actions."
Expand Down
62 changes: 32 additions & 30 deletions services/auth/source/ldap/source_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package ldap
import (
"context"
"fmt"
"sort"
"strings"

asymkey_model "code.gitea.io/gitea/models/asymkey"
Expand All @@ -24,7 +23,6 @@ import (
func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
log.Trace("Doing: SyncExternalUsers[%s]", source.authSource.Name)

var existingUsers []int
isAttributeSSHPublicKeySet := len(strings.TrimSpace(source.AttributeSSHPublicKey)) > 0
var sshKeysNeedUpdate bool

Expand All @@ -41,9 +39,14 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
default:
}

sort.Slice(users, func(i, j int) bool {
return users[i].LowerName < users[j].LowerName
})
usernameUsers := make(map[string]*user_model.User, len(users))
mailUsers := make(map[string]*user_model.User, len(users))
keepActiveUsers := make(map[int64]struct{})

for _, u := range users {
usernameUsers[u.LowerName] = u
mailUsers[strings.ToLower(u.Email)] = u
}

sr, err := source.SearchEntries()
if err != nil {
Expand All @@ -59,11 +62,6 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
log.Warn("LDAP search found no entries but did not report an error. All users will be deactivated as per settings")
}

sort.Slice(sr, func(i, j int) bool {
return sr[i].LowerName < sr[j].LowerName
})

userPos := 0
orgCache := make(map[string]*organization.Organization)
teamCache := make(map[string]*organization.Team)

Expand All @@ -86,21 +84,27 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
return db.ErrCancelledf("During update of %s before completed update of users", source.authSource.Name)
default:
}
if len(su.Username) == 0 {
if len(su.Username) == 0 && len(su.Mail) == 0 {
continue
}

if len(su.Mail) == 0 {
su.Mail = fmt.Sprintf("%s@localhost", su.Username)
var usr *user_model.User
if len(su.Username) > 0 {
usr = usernameUsers[su.LowerName]
}
if usr == nil && len(su.Mail) > 0 {
usr = mailUsers[strings.ToLower(su.Mail)]
}

var usr *user_model.User
for userPos < len(users) && users[userPos].LowerName < su.LowerName {
userPos++
if usr != nil {
keepActiveUsers[usr.ID] = struct{}{}
} else if len(su.Username) == 0 {
// we cannot create the user if su.Username is empty
continue
}
if userPos < len(users) && users[userPos].LowerName == su.LowerName {
usr = users[userPos]
existingUsers = append(existingUsers, userPos)

if len(su.Mail) == 0 {
su.Mail = fmt.Sprintf("%s@localhost", su.Username)
}

fullName := composeFullName(su.Name, su.Surname, su.Username)
Expand Down Expand Up @@ -203,19 +207,17 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {

// Deactivate users not present in LDAP
if updateExisting {
existPos := 0
for i, usr := range users {
for existPos < len(existingUsers) && i > existingUsers[existPos] {
existPos++
for _, usr := range users {
if _, ok := keepActiveUsers[usr.ID]; ok {
continue
}
if usr.IsActive && (existPos >= len(existingUsers) || i < existingUsers[existPos]) {
log.Trace("SyncExternalUsers[%s]: Deactivating user %s", source.authSource.Name, usr.Name)

usr.IsActive = false
err = user_model.UpdateUserCols(ctx, usr, "is_active")
if err != nil {
log.Error("SyncExternalUsers[%s]: Error deactivating user %s: %v", source.authSource.Name, usr.Name, err)
}
log.Trace("SyncExternalUsers[%s]: Deactivating user %s", source.authSource.Name, usr.Name)

usr.IsActive = false
err = user_model.UpdateUserCols(ctx, usr, "is_active")
if err != nil {
log.Error("SyncExternalUsers[%s]: Error deactivating user %s: %v", source.authSource.Name, usr.Name, err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion templates/base/head_script.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly.
notificationSettings: {{NotificationSettings}}, {{/*a map provided by NewFuncMap in helper.go*/}}
enableTimeTracking: {{EnableTimetracking}},
{{if or .Participants .Assignees .MentionableTeams}}
tributeValues: Array.from(new Map([
mentionValues: Array.from(new Map([
{{- range .Participants -}}
['{{.Name}}', {key: '{{.Name}} {{.FullName}}', value: '{{.Name}}', name: '{{.Name}}', fullname: '{{.FullName}}', avatar: '{{.AvatarLink $.Context}}'}],
{{- end -}}
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/issue/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
{{template "repo/issue/openclose" .}}
</div>
<div class="issue-list-toolbar-right">
<div class="ui secondary filter stackable menu labels">
<div class="ui secondary filter menu labels">
<!-- Label -->
<div class="ui {{if not .Labels}}disabled{{end}} dropdown jump item label-filter">
<span class="text">
Expand Down Expand Up @@ -278,7 +278,7 @@
{{template "repo/issue/openclose" .}}
</div>
<div class="issue-list-toolbar-right">
<div class="ui secondary filter stackable menu">
<div class="ui secondary filter menu">
{{if not .Repository.IsArchived}}
<!-- Action Button -->
{{if .IsShowClosed}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/issue/view_content/sidebar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
<div class="content">
{{template "shared/user/authorlink" $user}}
<div class="text">
{{$trackedtime}}
{{$trackedtime|Sec2Time}}
</div>
</div>
</div>
Expand Down
51 changes: 51 additions & 0 deletions tests/integration/auth_ldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,57 @@ func TestLDAPUserSync(t *testing.T) {
}
}

func TestLDAPUserSyncWithEmptyUsernameAttribute(t *testing.T) {
if skipLDAPTests() {
t.Skip()
return
}
defer tests.PrepareTestEnv(t)()

session := loginUser(t, "user1")
csrf := GetCSRF(t, session, "/admin/auths/new")
payload := buildAuthSourceLDAPPayload(csrf, "", "", "", "")
payload["attribute_username"] = ""
req := NewRequestWithValues(t, "POST", "/admin/auths/new", payload)
session.MakeRequest(t, req, http.StatusSeeOther)

for _, u := range gitLDAPUsers {
req := NewRequest(t, "GET", "/admin/users?q="+u.UserName)
resp := session.MakeRequest(t, req, http.StatusOK)

htmlDoc := NewHTMLParser(t, resp.Body)

tr := htmlDoc.doc.Find("table.table tbody tr")
assert.True(t, tr.Length() == 0)
}

for _, u := range gitLDAPUsers {
req := NewRequestWithValues(t, "POST", "/user/login", map[string]string{
"_csrf": csrf,
"user_name": u.UserName,
"password": u.Password,
})
MakeRequest(t, req, http.StatusSeeOther)
}

auth.SyncExternalUsers(context.Background(), true)

authSource := unittest.AssertExistsAndLoadBean(t, &auth_model.Source{
Name: payload["name"],
})
unittest.AssertCount(t, &user_model.User{
LoginType: auth_model.LDAP,
LoginSource: authSource.ID,
}, len(gitLDAPUsers))

for _, u := range gitLDAPUsers {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{
Name: u.UserName,
})
assert.True(t, user.IsActive)
}
}

func TestLDAPUserSyncWithGroupFilter(t *testing.T) {
if skipLDAPTests() {
t.Skip()
Expand Down
13 changes: 8 additions & 5 deletions web_src/css/repo/issue-list.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.issue-list-toolbar {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: flex-start;
gap: 1rem;
margin-top: 1rem;
Expand All @@ -10,17 +11,19 @@
display: flex;
}

.issue-list-toolbar-right {
margin-left: auto;
.issue-list-toolbar-right .filter.menu {
flex-direction: row;
flex-wrap: wrap;
gap: 8px;
}

@media (max-width: 767.98px) {
.issue-list-toolbar {
flex-direction: column-reverse;
}
.issue-list-toolbar-right {
margin-right: auto;
width: 100%;
.issue-list-toolbar-right .dropdown .menu {
left: auto !important;
right: auto !important;
}
.issue-list-navbar {
order: 0;
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/repo-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function initRepoIssueSidebarList() {
}
}
});
$('.ui.dropdown.label-filter').dropdown('setting', {'hideDividers': 'empty'}).dropdown('refreshItems');
$('.ui.dropdown.label-filter, .ui.dropdown.select-label').dropdown('setting', {'hideDividers': 'empty'}).dropdown('refreshItems');
}

export function initRepoIssueCommentDelete() {
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/tribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function makeCollections({mentions, emoji}) {

if (mentions) {
collections.push({
values: window.config.tributeValues,
values: window.config.mentionValues,
requireLeadingSpace: true,
menuItemTemplate: (item) => {
return `
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ window.config = {
pageData: {},
i18n: {},
appSubUrl: '',
tributeValues: [
mentionValues: [
{key: 'user1 User 1', value: 'user1', name: 'user1', fullname: 'User 1', avatar: 'https://avatar1.com'},
{key: 'user2 User 2', value: 'user2', name: 'user2', fullname: 'User 2', avatar: 'https://avatar2.com'},
{key: 'user3 User 3', value: 'user3', name: 'user3', fullname: 'User 3', avatar: 'https://avatar3.com'},
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/utils/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function matchMention(queryText) {

// results is a map of weights, lower is better
const results = new Map();
for (const obj of window.config.tributeValues) {
for (const obj of window.config.mentionValues) {
const index = obj.key.toLowerCase().indexOf(query);
if (index === -1) continue;
const existing = results.get(obj);
Expand Down
Loading

0 comments on commit ab50a4d

Please sign in to comment.