-
Notifications
You must be signed in to change notification settings - Fork 553
feat: active inactive user phase 1 #4589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 24 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
ebedf11
listing user and group changes
Shivam-nagar23 a628719
default value chnage
Shivam-nagar23 d54de55
group listing optimisation
Shivam-nagar23 a4baf56
wire_gen
Shivam-nagar23 08465d3
order by in group
Shivam-nagar23 2854bf0
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 37ffe40
default values
Shivam-nagar23 a68c624
discard
Shivam-nagar23 e3c482d
updated on
Shivam-nagar23 defe28f
case insensitive
Shivam-nagar23 000a883
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 eac977e
script number change
Shivam-nagar23 8801233
specs
Shivam-nagar23 b50f89c
review chnages
Shivam-nagar23 1cce3af
sql update
Shivam-nagar23 1febba6
id for user
Shivam-nagar23 6603a0a
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 046f47a
script number chnage
Shivam-nagar23 a93a59d
review comments-1
Shivam-nagar23 00cd1d5
review comments
Shivam-nagar23 befeca7
review comments
Shivam-nagar23 5ef0552
rest handler remove methods
Shivam-nagar23 5920a87
validation for delete
Shivam-nagar23 79ea449
delete user handling
Shivam-nagar23 47e0656
review comments
Shivam-nagar23 d1ad254
review comments
Shivam-nagar23 c2c5fb5
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 4448c9e
export csv filters support
Shivam-nagar23 cde92a2
Revert "export csv filters support"
Shivam-nagar23 3b3496f
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 feee76e
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 a61f732
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 2c6f3b7
main-merge
Shivam-nagar23 9dd58b6
Merge branch 'main' into feat-active-inactive-user-phase-1
Shivam-nagar23 9efa163
main-merge
Shivam-nagar23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,8 @@ import ( | |
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "github.com/devtron-labs/devtron/internal/constants" | ||
| "github.com/gorilla/schema" | ||
| "net/http" | ||
| "strconv" | ||
| "strings" | ||
|
|
@@ -44,12 +46,10 @@ type UserRestHandler interface { | |
| GetById(w http.ResponseWriter, r *http.Request) | ||
| GetAll(w http.ResponseWriter, r *http.Request) | ||
| DeleteUser(w http.ResponseWriter, r *http.Request) | ||
| GetAllDetailedUsers(w http.ResponseWriter, r *http.Request) | ||
| FetchRoleGroupById(w http.ResponseWriter, r *http.Request) | ||
| CreateRoleGroup(w http.ResponseWriter, r *http.Request) | ||
| UpdateRoleGroup(w http.ResponseWriter, r *http.Request) | ||
| FetchRoleGroups(w http.ResponseWriter, r *http.Request) | ||
| FetchDetailedRoleGroups(w http.ResponseWriter, r *http.Request) | ||
| FetchRoleGroupsByName(w http.ResponseWriter, r *http.Request) | ||
| DeleteRoleGroup(w http.ResponseWriter, r *http.Request) | ||
| CheckUserRoles(w http.ResponseWriter, r *http.Request) | ||
|
|
@@ -210,20 +210,13 @@ func (handler UserRestHandlerImpl) UpdateUser(w http.ResponseWriter, r *http.Req | |
| // RBAC enforcer applying | ||
| token := r.Header.Get("token") | ||
|
|
||
| if userInfo.EmailId == "admin" { | ||
| userInfo.EmailId = "[email protected]/devtron-labs" | ||
| } | ||
| err = handler.validator.Struct(userInfo) | ||
| if err != nil { | ||
| handler.logger.Errorw("validation err, UpdateUser", "err", err, "payload", userInfo) | ||
| common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
| return | ||
| } | ||
|
|
||
| if userInfo.EmailId == "[email protected]/devtron-labs" { | ||
| userInfo.EmailId = "admin" | ||
| } | ||
|
|
||
| res, rolesChanged, groupsModified, restrictedGroups, err := handler.userService.UpdateUser(&userInfo, token, handler.CheckManagerAuth) | ||
|
|
||
| if err != nil { | ||
|
|
@@ -309,6 +302,7 @@ func (handler UserRestHandlerImpl) GetById(w http.ResponseWriter, r *http.Reques | |
| } | ||
|
|
||
| func (handler UserRestHandlerImpl) GetAll(w http.ResponseWriter, r *http.Request) { | ||
| var decoder = schema.NewDecoder() | ||
| userId, err := handler.userService.GetLoggedInUser(r) | ||
| if userId == 0 || err != nil { | ||
| common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) | ||
|
|
@@ -362,35 +356,16 @@ func (handler UserRestHandlerImpl) GetAll(w http.ResponseWriter, r *http.Request | |
| common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
| return | ||
| } | ||
| res, err := handler.userService.GetAll() | ||
| req := &bean.FetchListingRequest{} | ||
| err = decoder.Decode(req, r.URL.Query()) | ||
| if err != nil { | ||
| handler.logger.Errorw("service err, GetAll", "err", err) | ||
| common.WriteJsonResp(w, err, "Failed to Get", http.StatusInternalServerError) | ||
| return | ||
| } | ||
|
|
||
| common.WriteJsonResp(w, err, res, http.StatusOK) | ||
| } | ||
|
|
||
| func (handler UserRestHandlerImpl) GetAllDetailedUsers(w http.ResponseWriter, r *http.Request) { | ||
| userId, err := handler.userService.GetLoggedInUser(r) | ||
| if userId == 0 || err != nil { | ||
| common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) | ||
| return | ||
| } | ||
|
|
||
| token := r.Header.Get("token") | ||
| isActionUserSuperAdmin := false | ||
| if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); ok { | ||
| isActionUserSuperAdmin = true | ||
| } | ||
| if !isActionUserSuperAdmin { | ||
| common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
| handler.logger.Errorw("request err, GetAll", "err", err, "payload", req) | ||
| common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
| return | ||
| } | ||
| res, err := handler.userService.GetAllDetailedUsers() | ||
| res, err := handler.userService.GetAllWithFilters(req) | ||
| if err != nil { | ||
| handler.logger.Errorw("service err, GetAllDetailedUsers", "err", err) | ||
| handler.logger.Errorw("service err, GetAll", "err", err) | ||
| common.WriteJsonResp(w, err, "Failed to Get", http.StatusInternalServerError) | ||
| return | ||
| } | ||
|
|
@@ -451,7 +426,14 @@ func (handler UserRestHandlerImpl) DeleteUser(w http.ResponseWriter, r *http.Req | |
| } | ||
| } | ||
| //RBAC enforcer Ends | ||
|
|
||
| //validation | ||
| err = checkValidationForSystemOrAdminUser(int32(id)) | ||
| if err != nil { | ||
| handler.logger.Errorw("request err, DeleteUser, validation failed", "id", id, "err", err) | ||
| common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
| return | ||
| } | ||
| //service call | ||
| res, err := handler.userService.DeleteUser(user) | ||
| if err != nil { | ||
| handler.logger.Errorw("service err, DeleteUser", "err", err, "id", id) | ||
|
|
@@ -462,6 +444,13 @@ func (handler UserRestHandlerImpl) DeleteUser(w http.ResponseWriter, r *http.Req | |
| common.WriteJsonResp(w, err, res, http.StatusOK) | ||
| } | ||
|
|
||
| func checkValidationForSystemOrAdminUser(userId int32) error { | ||
| if userId == constants.SystemUserId || userId == constants.AdminUserId { | ||
| return &util.ApiError{Code: "400", HttpStatusCode: 400, UserMessage: "cannot delete system or admin user"} | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
kartik-579 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| func (handler UserRestHandlerImpl) FetchRoleGroupById(w http.ResponseWriter, r *http.Request) { | ||
| vars := mux.Vars(r) | ||
| /* #nosec */ | ||
|
|
@@ -639,6 +628,7 @@ func (handler UserRestHandlerImpl) UpdateRoleGroup(w http.ResponseWriter, r *htt | |
| } | ||
|
|
||
| func (handler UserRestHandlerImpl) FetchRoleGroups(w http.ResponseWriter, r *http.Request) { | ||
| var decoder = schema.NewDecoder() | ||
| userId, err := handler.userService.GetLoggedInUser(r) | ||
| if userId == 0 || err != nil { | ||
| common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) | ||
|
|
@@ -692,32 +682,15 @@ func (handler UserRestHandlerImpl) FetchRoleGroups(w http.ResponseWriter, r *htt | |
| common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
| return | ||
| } | ||
| res, err := handler.roleGroupService.FetchRoleGroups() | ||
| if err != nil { | ||
| handler.logger.Errorw("service err, FetchRoleGroups", "err", err) | ||
| common.WriteJsonResp(w, err, "", http.StatusInternalServerError) | ||
| return | ||
| } | ||
| common.WriteJsonResp(w, err, res, http.StatusOK) | ||
| } | ||
|
|
||
| func (handler UserRestHandlerImpl) FetchDetailedRoleGroups(w http.ResponseWriter, r *http.Request) { | ||
| userId, err := handler.userService.GetLoggedInUser(r) | ||
| if userId == 0 || err != nil { | ||
| common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) | ||
| return | ||
| } | ||
| token := r.Header.Get("token") | ||
| isActionUserSuperAdmin := false | ||
| if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); ok { | ||
| isActionUserSuperAdmin = true | ||
| } | ||
| if !isActionUserSuperAdmin { | ||
| common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
| req := &bean.FetchListingRequest{} | ||
| err = decoder.Decode(req, r.URL.Query()) | ||
| if err != nil { | ||
| handler.logger.Errorw("request err, FetchRoleGroups", "err", err, "payload", req) | ||
| common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
| return | ||
| } | ||
|
|
||
| res, err := handler.roleGroupService.FetchDetailedRoleGroups() | ||
| res, err := handler.roleGroupService.FetchRoleGroupsWithFilters(req) | ||
| if err != nil { | ||
| handler.logger.Errorw("service err, FetchRoleGroups", "err", err) | ||
| common.WriteJsonResp(w, err, "", http.StatusInternalServerError) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package constants | ||
|
|
||
| const ( | ||
| AdminUser string = "admin" | ||
| SystemUser string = "system" | ||
| ) | ||
|
|
||
| const ( | ||
| AdminUserId = 2 // we have established Admin user as 2 while setting up devtron | ||
| SystemUserId = 1 // we have established System user as 1 while setting up devtron, which are being used for auto-trigger operations | ||
kartik-579 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.