Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
ebedf11
listing user and group changes
Shivam-nagar23 Jan 25, 2024
a628719
default value chnage
Shivam-nagar23 Jan 25, 2024
d54de55
group listing optimisation
Shivam-nagar23 Jan 25, 2024
a4baf56
wire_gen
Shivam-nagar23 Jan 25, 2024
08465d3
order by in group
Shivam-nagar23 Jan 25, 2024
2854bf0
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 Jan 27, 2024
37ffe40
default values
Shivam-nagar23 Jan 29, 2024
a68c624
discard
Shivam-nagar23 Jan 29, 2024
e3c482d
updated on
Shivam-nagar23 Jan 29, 2024
defe28f
case insensitive
Shivam-nagar23 Jan 29, 2024
000a883
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 Jan 29, 2024
eac977e
script number change
Shivam-nagar23 Jan 29, 2024
8801233
specs
Shivam-nagar23 Jan 29, 2024
b50f89c
review chnages
Shivam-nagar23 Jan 30, 2024
1cce3af
sql update
Shivam-nagar23 Jan 30, 2024
1febba6
id for user
Shivam-nagar23 Jan 30, 2024
6603a0a
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 Jan 31, 2024
046f47a
script number chnage
Shivam-nagar23 Jan 31, 2024
a93a59d
review comments-1
Shivam-nagar23 Jan 31, 2024
00cd1d5
review comments
Shivam-nagar23 Jan 31, 2024
befeca7
review comments
Shivam-nagar23 Jan 31, 2024
5ef0552
rest handler remove methods
Shivam-nagar23 Jan 31, 2024
5920a87
validation for delete
Shivam-nagar23 Jan 31, 2024
79ea449
delete user handling
Shivam-nagar23 Jan 31, 2024
47e0656
review comments
Shivam-nagar23 Feb 1, 2024
d1ad254
review comments
Shivam-nagar23 Feb 1, 2024
9b2c4fa
bulk delete user and permission group
Shivam-nagar23 Feb 2, 2024
9e26f82
legacy code fix from loop in query to bulk query
Shivam-nagar23 Feb 2, 2024
c2c5fb5
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 Feb 5, 2024
4448c9e
export csv filters support
Shivam-nagar23 Feb 5, 2024
cde92a2
Revert "export csv filters support"
Shivam-nagar23 Feb 5, 2024
3861eb1
export csv filters
Shivam-nagar23 Feb 5, 2024
7f6baec
Merge branch 'main' into feat-active-inactive-user-phase-2
Shivam-nagar23 Feb 5, 2024
37968ec
Merge branch 'feat-active-inactive-user-phase-1' into feat-active-ina…
Shivam-nagar23 Feb 5, 2024
d61c150
bulk delete support with filters
Shivam-nagar23 Feb 5, 2024
5be6cb7
validation
Shivam-nagar23 Feb 5, 2024
af0e9b1
method break
Shivam-nagar23 Feb 5, 2024
f5b1ddf
refactor the method
Shivam-nagar23 Feb 5, 2024
a5ba2f8
condition
Shivam-nagar23 Feb 5, 2024
8c6c574
open api specs
Shivam-nagar23 Feb 5, 2024
3b3496f
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 Feb 5, 2024
c4d455c
specs
Shivam-nagar23 Feb 5, 2024
feee76e
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 Feb 5, 2024
a61f732
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 Feb 6, 2024
1ebee74
refactoring filters in bulk delete rolegroup
Shivam-nagar23 Feb 6, 2024
8ee364a
comments
Shivam-nagar23 Feb 6, 2024
cbd5400
comments
Shivam-nagar23 Feb 6, 2024
72ed56e
Merge branch 'feat-active-inactive-user-phase-1' into feat-active-ina…
Shivam-nagar23 Feb 6, 2024
2c6f3b7
main-merge
Shivam-nagar23 Feb 6, 2024
9dd58b6
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 Feb 7, 2024
5200661
Merge branch 'feat-active-inactive-user-phase-1' into feat-active-ina…
Shivam-nagar23 Feb 7, 2024
8ddfef6
main-merge
Shivam-nagar23 Feb 8, 2024
2f83b41
script
Shivam-nagar23 Feb 9, 2024
e67a73c
Merge branch 'feat-active-inactive-user-phase-2' into feat-active-ina…
Shivam-nagar23 Feb 9, 2024
9e14845
group listing
Shivam-nagar23 Feb 9, 2024
0a8a53e
Merge branch 'main' into feat-active-inactive-user-phase-2
Shivam-nagar23 Feb 12, 2024
565c180
Merge branch 'feat-active-inactive-user-phase-2' into feat-active-ina…
Shivam-nagar23 Feb 12, 2024
0e50351
review comments
Shivam-nagar23 Feb 12, 2024
154bf61
review comments
Shivam-nagar23 Feb 12, 2024
0e64fad
review comments
Shivam-nagar23 Feb 12, 2024
35cc304
review comments
Shivam-nagar23 Feb 12, 2024
82e63cc
user delete self-review
Shivam-nagar23 Feb 12, 2024
8977bcb
error handling
Shivam-nagar23 Feb 12, 2024
cfabca3
Merge branch 'feat-active-inactive-user-phase-2' into feat-active-ina…
Shivam-nagar23 Feb 12, 2024
250535e
Merge branch 'main' into feat-active-inactive-user-phase-2
Shivam-nagar23 Feb 13, 2024
2ca1bec
renaming helpers
Shivam-nagar23 Feb 14, 2024
7b6feb6
commets
Shivam-nagar23 Feb 14, 2024
e19fba8
checks and renaming
Shivam-nagar23 Feb 14, 2024
f71dd4f
Merge branch 'main' into feat-active-inactive-user-phase-2
Shivam-nagar23 Feb 19, 2024
2ab83cf
main-merge
Shivam-nagar23 Feb 19, 2024
c6062c7
Merge branch 'feat-active-inactive-user-phase-2' into feat-active-ina…
Shivam-nagar23 Feb 19, 2024
c5ead47
Merge branch 'main' into feat-active-inactive-user-phase-3
Shivam-nagar23 Feb 20, 2024
162ed23
Merge branch 'main' into feat-active-inactive-user-phase-3
Shivam-nagar23 Feb 20, 2024
0df1c21
last login order
Shivam-nagar23 Feb 21, 2024
0b88bc0
Merge branch 'main' into feat-active-inactive-user-phase-3
Shivam-nagar23 Feb 22, 2024
ebc908b
script number change
Shivam-nagar23 Feb 22, 2024
fab60ec
rolegroup migration
Shivam-nagar23 Feb 23, 2024
fe1b16d
Merge branch 'main' into feat-active-inactive-user-phase-3
Shivam-nagar23 Feb 26, 2024
0593c1a
Merge branch 'main' into feat-active-inactive-user-phase-3
Shivam-nagar23 Feb 27, 2024
4bfde9e
name change
Shivam-nagar23 Feb 27, 2024
289a50a
backward compatibility handling
Shivam-nagar23 Feb 28, 2024
25a48bb
self review name change
Shivam-nagar23 Feb 28, 2024
eb22065
chart-group -manager-fix
Shivam-nagar23 Feb 28, 2024
28a0346
userrolegroups
Shivam-nagar23 Feb 28, 2024
ef069bc
change chnage operation
Shivam-nagar23 Feb 28, 2024
e10b892
specs update
Shivam-nagar23 Feb 28, 2024
f30cfc7
groups
Shivam-nagar23 Feb 28, 2024
35889bf
find by componet id
Shivam-nagar23 Feb 29, 2024
93debc7
job project id
Shivam-nagar23 Feb 29, 2024
d158814
Merge branch 'main' into feat-active-inactive-user-phase-3
Shivam-nagar23 Mar 1, 2024
8dec45a
Merge branch 'main' into feat-active-inactive-user-phase-3
Shivam-nagar23 Mar 8, 2024
bcdf0e9
sql script chnage
Shivam-nagar23 Mar 8, 2024
d4a49e3
Merge branch 'main' into feat-active-inactive-user-phase-3
Shivam-nagar23 Mar 13, 2024
0c503a3
script number change
Shivam-nagar23 Mar 13, 2024
fe01256
Merge branch 'main' into feat-active-inactive-user-phase-3
Shivam-nagar23 Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 40 additions & 22 deletions api/auth/user/UserRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"errors"
"fmt"
util2 "github.com/devtron-labs/devtron/api/auth/user/util"
"github.com/devtron-labs/devtron/pkg/auth/user/helper"
"github.com/gorilla/schema"
"net/http"
Expand Down Expand Up @@ -110,6 +111,23 @@ func (handler UserRestHandlerImpl) CreateUser(w http.ResponseWriter, r *http.Req
userInfo.UserId = userId
handler.logger.Infow("request payload, CreateUser", "payload", userInfo)

// struct Validations
handler.logger.Infow("request payload, CreateUser ", "payload", userInfo)
err = handler.validator.Struct(userInfo)
if err != nil {
handler.logger.Errorw("validation err, CreateUser", "err", err, "payload", userInfo)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
// Doing this as api is not compatible with previous release of dashboard, groups has been migrated to userRoleGroups
isGroupsPresent := util2.IsGroupsPresent(userInfo.Groups)
if isGroupsPresent {
handler.logger.Errorw("validation error , createUser ", "err", err, "payload", userInfo)
err := &util.ApiError{Code: "406", HttpStatusCode: 406, UserMessage: "Not compatible with request", InternalMessage: "Not compatible with the request payload, as groups has been migrated to userRoleGroups"}
common.WriteJsonResp(w, err, nil, http.StatusNotAcceptable)
return
}

// RBAC enforcer applying
token := r.Header.Get("token")
isActionUserSuperAdmin := false
Expand Down Expand Up @@ -143,8 +161,8 @@ func (handler UserRestHandlerImpl) CreateUser(w http.ResponseWriter, r *http.Req
}

// auth check inside groups
if len(userInfo.Groups) > 0 {
groupRoles, err := handler.roleGroupService.FetchRolesForGroups(userInfo.Groups)
if len(userInfo.UserRoleGroup) > 0 {
groupRoles, err := handler.roleGroupService.FetchRolesForUserRoleGroups(userInfo.UserRoleGroup)
if err != nil && err != pg.ErrNoRows {
handler.logger.Errorw("service err, UpdateUser", "err", err, "payload", userInfo)
common.WriteJsonResp(w, err, "", http.StatusInternalServerError)
Expand Down Expand Up @@ -173,14 +191,6 @@ func (handler UserRestHandlerImpl) CreateUser(w http.ResponseWriter, r *http.Req
}
//RBAC enforcer Ends

handler.logger.Infow("request payload, CreateUser ", "payload", userInfo)
err = handler.validator.Struct(userInfo)
if err != nil {
handler.logger.Errorw("validation err, CreateUser", "err", err, "payload", userInfo)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}

res, err := handler.userService.CreateUser(&userInfo, token, handler.CheckManagerAuth)
if err != nil {
handler.logger.Errorw("service err, CreateUser", "err", err, "payload", userInfo)
Expand Down Expand Up @@ -222,6 +232,14 @@ func (handler UserRestHandlerImpl) UpdateUser(w http.ResponseWriter, r *http.Req
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
// Doing this as api is not compatible with previous release of dashboard,groups has been migrated to userRoleGroups
isGroupsPresent := util2.IsGroupsPresent(userInfo.Groups)
if isGroupsPresent {
handler.logger.Errorw("validation error , createUser ", "err", err, "payload", userInfo)
err := &util.ApiError{Code: "406", HttpStatusCode: 406, UserMessage: "Not compatible with request, please update to latest version", InternalMessage: "Not compatible with the request payload, as groups has been migrated to userRoleGroups"}
common.WriteJsonResp(w, err, nil, http.StatusNotAcceptable)
return
}

res, rolesChanged, groupsModified, restrictedGroups, err := handler.userService.UpdateUser(&userInfo, token, handler.CheckManagerAuth)

Expand Down Expand Up @@ -327,10 +345,10 @@ func (handler UserRestHandlerImpl) GetAllV2(w http.ResponseWriter, r *http.Reque
return
}
var roleFilters []bean.RoleFilter
if len(user.Groups) > 0 {
groupRoleFilters, err := handler.userService.GetRoleFiltersByGroupNames(user.Groups)
if len(user.UserRoleGroup) > 0 {
groupRoleFilters, err := handler.userService.GetRoleFiltersByUserRoleGroups(user.UserRoleGroup)
if err != nil {
handler.logger.Errorw("Error in getting role filters by group names", "err", err, "groupNames", user.Groups)
handler.logger.Errorw("Error in getting role filters by group names", "err", err, "UserRoleGroup", user.UserRoleGroup)
common.WriteJsonResp(w, err, "", http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -397,10 +415,10 @@ func (handler UserRestHandlerImpl) GetAll(w http.ResponseWriter, r *http.Request
return
}
var roleFilters []bean.RoleFilter
if len(user.Groups) > 0 {
groupRoleFilters, err := handler.userService.GetRoleFiltersByGroupNames(user.Groups)
if len(user.UserRoleGroup) > 0 {
groupRoleFilters, err := handler.userService.GetRoleFiltersByUserRoleGroups(user.UserRoleGroup)
if err != nil {
handler.logger.Errorw("Error in getting role filters by group names", "err", err, "groupNames", user.Groups)
handler.logger.Errorw("Error in getting role filters by group names", "err", err, "UserRoleGroup", user.UserRoleGroup)
common.WriteJsonResp(w, err, "", http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -784,10 +802,10 @@ func (handler UserRestHandlerImpl) FetchRoleGroupsV2(w http.ResponseWriter, r *h
return
}
var roleFilters []bean.RoleFilter
if len(user.Groups) > 0 {
groupRoleFilters, err := handler.userService.GetRoleFiltersByGroupNames(user.Groups)
if len(user.UserRoleGroup) > 0 {
groupRoleFilters, err := handler.userService.GetRoleFiltersByUserRoleGroups(user.UserRoleGroup)
if err != nil {
handler.logger.Errorw("Error in getting role filters by group names", "err", err, "groupNames", user.Groups)
handler.logger.Errorw("Error in getting role filters by group names", "err", err, "UserRoleGroup", user.UserRoleGroup)
common.WriteJsonResp(w, err, "", http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -855,10 +873,10 @@ func (handler UserRestHandlerImpl) FetchRoleGroups(w http.ResponseWriter, r *htt
return
}
var roleFilters []bean.RoleFilter
if len(user.Groups) > 0 {
groupRoleFilters, err := handler.userService.GetRoleFiltersByGroupNames(user.Groups)
if len(user.UserRoleGroup) > 0 {
groupRoleFilters, err := handler.userService.GetRoleFiltersByUserRoleGroups(user.UserRoleGroup)
if err != nil {
handler.logger.Errorw("Error in getting role filters by group names", "err", err, "groupNames", user.Groups)
handler.logger.Errorw("Error in getting role filters by group names", "err", err, "UserRoleGroup", user.UserRoleGroup)
common.WriteJsonResp(w, err, "", http.StatusInternalServerError)
return
}
Expand Down
8 changes: 8 additions & 0 deletions api/auth/user/util/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package util

func IsGroupsPresent(groups []string) bool {
if len(groups) > 0 {
return true
}
return false
}
2 changes: 2 additions & 0 deletions api/bean/AppView.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type JobContainer struct {
JobActualName string `json:"appName""`
Description GenericNoteResponseBean `json:"description"`
JobCiPipelines []JobCIPipeline `json:"ciPipelines"'`
ProjectId int `json:"projectId"`
}

type JobCIPipeline struct {
Expand All @@ -98,6 +99,7 @@ type JobListingContainer struct {
EnvironmentName string `sql:"environment_name" json:"environmentName"`
LastTriggeredEnvironmentName string `sql:"last_triggered_environment_name" json:"lastTriggeredEnvironmentName"`
LastTriggeredEnvironmentId int `sql:"last_triggered_environment_id" json:"lastEnvironmentId"`
ProjectId int `sql:"team_id" json:"projectId"`
}

type CiPipelineLastSucceededTime struct {
Expand Down
33 changes: 19 additions & 14 deletions api/bean/UserRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ type UserRole struct {
}

type UserInfo struct {
Id int32 `json:"id" validate:"number,not-system-admin-userid"`
EmailId string `json:"email_id" validate:"required,not-system-admin-user"` // TODO : have to migrate json key to emailId and also handle backward compatibility
Roles []string `json:"roles,omitempty"`
AccessToken string `json:"access_token,omitempty"`
RoleFilters []RoleFilter `json:"roleFilters"`
Status string `json:"status,omitempty"`
Groups []string `json:"groups"` // this will be deprecated in future do not use
SuperAdmin bool `json:"superAdmin,notnull"`
LastLoginTime time.Time `json:"lastLoginTime"`
UserType string `json:"-"`
LastUsedAt time.Time `json:"-"`
LastUsedByIp string `json:"-"`
Exist bool `json:"-"`
UserId int32 `json:"-"` // created or modified user id
Id int32 `json:"id" validate:"number,not-system-admin-userid"`
EmailId string `json:"email_id" validate:"required,not-system-admin-user"` // TODO : have to migrate json key to emailId and also handle backward compatibility
Roles []string `json:"roles,omitempty"`
AccessToken string `json:"access_token,omitempty"`
RoleFilters []RoleFilter `json:"roleFilters"`
Status string `json:"status,omitempty"`
Groups []string `json:"groups"` // this will be deprecated in future do not use
UserRoleGroup []UserRoleGroup `json:"userRoleGroups"` // role group with metadata
SuperAdmin bool `json:"superAdmin,notnull"`
LastLoginTime time.Time `json:"lastLoginTime"`
UserType string `json:"-"`
LastUsedAt time.Time `json:"-"`
LastUsedByIp string `json:"-"`
Exist bool `json:"-"`
UserId int32 `json:"-"` // created or modified user id
}

type RoleGroup struct {
Expand Down Expand Up @@ -145,3 +146,7 @@ type BulkDeleteRequest struct {
ListingRequest *ListingRequest `json:"listingRequest,omitempty"`
LoggedInUserId int32 `json:"-"`
}

type UserRoleGroup struct {
RoleGroup *RoleGroup `json:"roleGroup"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ func (impl AppWorkflowRepositoryImpl) FindByComponentId(componentId int) ([]*App
Where("app_workflow_mapping.component_id= ?", componentId).
Where("app_workflow.active = ?", true).
Where("app_workflow_mapping.active = ?", true).
Where("app_workflow_mapping.type = ?", CIPIPELINE).
Select()
return appWorkflowsMapping, err
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const (

func (impl AppListingRepositoryQueryBuilder) BuildJobListingQuery(appIDs []int, statuses []string, environmentIds []int, sortOrder string) string {
query := "select ci_pipeline.name as ci_pipeline_name,ci_pipeline.id as ci_pipeline_id,app.id as job_id,app.display_name " +
"as job_name, app.app_name,app.description,cwr.started_on,cwr.status,cem.environment_id,cwr.environment_id as last_triggered_environment_id from app left join ci_pipeline on" +
"as job_name, app.app_name,app.description,app.team_id,cwr.started_on,cwr.status,cem.environment_id,cwr.environment_id as last_triggered_environment_id from app left join ci_pipeline on" +
" app.id = ci_pipeline.app_id and ci_pipeline.active=true left join (select cw.ci_pipeline_id, cw.status, cw.started_on, cw.environment_id " +
" from ci_workflow cw inner join (select ci_pipeline_id, MAX(started_on) max_started_on from ci_workflow group by ci_pipeline_id ) " +
"cws on cw.ci_pipeline_id = cws.ci_pipeline_id " +
Expand Down
1 change: 1 addition & 0 deletions pkg/app/AppListingService.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ func BuildJobListingResponse(jobContainers []*bean.JobListingContainer, JobsLast
val.JobId = jobContainer.JobId
val.JobName = jobContainer.JobName
val.JobActualName = jobContainer.JobActualName
val.ProjectId = jobContainer.ProjectId
}

if len(val.JobCiPipelines) == 0 {
Expand Down
8 changes: 6 additions & 2 deletions pkg/auth/user/RoleGroupService.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type RoleGroupService interface {
FetchRoleGroupsByName(name string) ([]*bean.RoleGroup, error)
DeleteRoleGroup(model *bean.RoleGroup) (bool, error)
BulkDeleteRoleGroups(request *bean.BulkDeleteRequest) (bool, error)
FetchRolesForGroups(groupNames []string) ([]*bean.RoleFilter, error)
FetchRolesForUserRoleGroups(userRoleGroups []bean.UserRoleGroup) ([]*bean.RoleFilter, error)
}

type RoleGroupServiceImpl struct {
Expand Down Expand Up @@ -938,7 +938,11 @@ func (impl RoleGroupServiceImpl) deleteMappingsFromCasbin(groupCasbinNames []str
return nil
}

func (impl RoleGroupServiceImpl) FetchRolesForGroups(groupNames []string) ([]*bean.RoleFilter, error) {
func (impl RoleGroupServiceImpl) FetchRolesForUserRoleGroups(userRoleGroups []bean.UserRoleGroup) ([]*bean.RoleFilter, error) {
groupNames := make([]string, 0)
for _, userRoleGroup := range userRoleGroups {
groupNames = append(groupNames, userRoleGroup.RoleGroup.Name)
}
if len(groupNames) == 0 {
return nil, nil
}
Expand Down
Loading