fix(users): update task log for admins

This commit is contained in:
fiftin 2024-04-02 23:50:52 +02:00
parent 41a95f16f1
commit dafc6590df
No known key found for this signature in database
GPG Key ID: 044381366A5D4731
4 changed files with 25 additions and 1 deletions

View File

@ -203,6 +203,7 @@ type Store interface {
GetSchedule(projectID int, scheduleID int) (Schedule, error) GetSchedule(projectID int, scheduleID int) (Schedule, error)
DeleteSchedule(projectID int, scheduleID int) error DeleteSchedule(projectID int, scheduleID int) error
GetAllAdmins() ([]User, error)
GetProjectUsers(projectID int, params RetrieveQueryParams) ([]UserWithProjectRole, error) GetProjectUsers(projectID int, params RetrieveQueryParams) ([]UserWithProjectRole, error)
CreateProjectUser(projectUser ProjectUser) (ProjectUser, error) CreateProjectUser(projectUser ProjectUser) (ProjectUser, error)
DeleteProjectUser(projectID int, userID int) error DeleteProjectUser(projectID int, userID int) error

View File

@ -198,3 +198,11 @@ func (d *BoltDb) GetUserByLoginOrEmail(login string, email string) (existingUser
err = db.ErrNotFound err = db.ErrNotFound
return return
} }
func (d *BoltDb) GetAllAdmins() (users []db.User, err error) {
err = d.getObjects(0, db.UserProps, db.RetrieveQueryParams{}, func(i interface{}) bool {
user := i.(db.User)
return user.Admin
}, &users)
return
}

View File

@ -2,8 +2,8 @@ package sql
import ( import (
"database/sql" "database/sql"
"github.com/ansible-semaphore/semaphore/db"
"github.com/Masterminds/squirrel" "github.com/Masterminds/squirrel"
"github.com/ansible-semaphore/semaphore/db"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"time" "time"
) )
@ -216,3 +216,9 @@ func (d *SqlDb) GetUserByLoginOrEmail(login string, email string) (existingUser
return return
} }
func (d *SqlDb) GetAllAdmins() (users []db.User, err error) {
_, err = d.selectAll(&users, "select * from "+db.UserProps.TableName+" where admin = true")
return
}

View File

@ -271,6 +271,15 @@ func (t *TaskRunner) populateDetails() error {
t.users = append(t.users, user.ID) t.users = append(t.users, user.ID)
} }
admins, err := t.pool.store.GetAllAdmins()
if err != nil {
return err
}
for _, user := range admins {
t.users = append(t.users, user.ID)
}
// get inventory // get inventory
t.Inventory, err = t.pool.store.GetInventory(t.Template.ProjectID, t.Template.InventoryID) t.Inventory, err = t.pool.store.GetInventory(t.Template.ProjectID, t.Template.InventoryID)
if err != nil { if err != nil {