mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-10 08:57:25 +01:00
Adapt count tags for managers
This commit is contained in:
parent
b2aed2f16b
commit
2590ce7e44
@ -58,7 +58,7 @@ func (r *JobRepository) CreateTag(tagType string, tagName string) (tagId int64,
|
||||
return res.LastInsertId()
|
||||
}
|
||||
|
||||
func (r *JobRepository) CountTags(user *string) (tags []schema.Tag, counts map[string]int, err error) {
|
||||
func (r *JobRepository) CountTags(user *string, project *string) (tags []schema.Tag, counts map[string]int, err error) {
|
||||
tags = make([]schema.Tag, 0, 100)
|
||||
xrows, err := r.DB.Queryx("SELECT * FROM tag")
|
||||
if err != nil {
|
||||
@ -77,9 +77,12 @@ func (r *JobRepository) CountTags(user *string) (tags []schema.Tag, counts map[s
|
||||
From("tag t").
|
||||
LeftJoin("jobtag jt ON t.id = jt.tag_id").
|
||||
GroupBy("t.tag_name")
|
||||
if user != nil {
|
||||
|
||||
if (user != nil && project == nil) { // USER: Only count own jobs
|
||||
q = q.Where("jt.job_id IN (SELECT id FROM job WHERE job.user = ?)", *user)
|
||||
}
|
||||
} else if (user != nil && project != nil) { // MANAGER: Count own jobs plus project's jobs
|
||||
q = q.Where("jt.job_id IN (SELECT id FROM job WHERE job.user = ? OR job.project = ?)", *user, *project)
|
||||
} // else: ADMIN: Count all jobs
|
||||
|
||||
rows, err := q.RunWith(r.stmtCache).Query()
|
||||
if err != nil {
|
||||
|
@ -144,12 +144,19 @@ func setupAnalysisRoute(i InfoType, r *http.Request) InfoType {
|
||||
|
||||
func setupTaglistRoute(i InfoType, r *http.Request) InfoType {
|
||||
var username *string = nil
|
||||
var project *string = nil
|
||||
|
||||
jobRepo := repository.GetJobRepository()
|
||||
if user := auth.GetUser(r.Context()); user != nil && !user.HasRole(auth.RoleAdmin) {
|
||||
user := auth.GetUser(r.Context())
|
||||
|
||||
if (user != nil && user.HasNotRoles([]string{auth.RoleAdmin, auth.RoleManager})) {
|
||||
username = &user.Username
|
||||
} else if (user != nil && user.HasRole(auth.RoleManager)) {
|
||||
username = &user.Username
|
||||
project = &user.Project
|
||||
}
|
||||
|
||||
tags, counts, err := jobRepo.CountTags(username)
|
||||
tags, counts, err := jobRepo.CountTags(username, project)
|
||||
tagMap := make(map[string][]map[string]interface{})
|
||||
if err != nil {
|
||||
log.Errorf("GetTags failed: %s", err.Error())
|
||||
|
Loading…
Reference in New Issue
Block a user