This commit is contained in:
Christoph Kluge 2023-02-22 16:57:15 +01:00
parent 365888c645
commit d30dba109d
2 changed files with 3 additions and 3 deletions

View File

@ -55,7 +55,7 @@ func TestFindById(t *testing.T) {
func TestGetTags(t *testing.T) {
r := setup(t)
tags, counts, err := r.CountTags(nil, nil)
tags, counts, err := r.CountTags(nil)
if err != nil {
t.Fatal(err)
}

View File

@ -88,9 +88,9 @@ func (r *JobRepository) CountTags(user *auth.User) (tags []schema.Tag, counts ma
LeftJoin("jobtag jt ON t.id = jt.tag_id").
GroupBy("t.tag_name")
if user.HasRole(auth.RoleUser) { // USER: Only count own jobs
if user != nil && user.HasRole(auth.RoleUser) { // USER: Only count own jobs
q = q.Where("jt.job_id IN (SELECT id FROM job WHERE job.user = ?)", user.Username)
} else if user.HasRole(auth.RoleManager) { // MANAGER: Count own jobs plus project's jobs
} else if user != nil && user.HasRole(auth.RoleManager) { // MANAGER: Count own jobs plus project's jobs
// Build ("project1", "project2", ...) list of variable length directly in SQL string
q = q.Where("jt.job_id IN (SELECT id FROM job WHERE job.user = ? OR job.project IN (\""+strings.Join(user.Projects, "\",\"")+"\"))", user.Username)
} // else: ADMIN || SUPPORT: Count all jobs