diff --git a/api/bean/UserRequest.go b/api/bean/UserRequest.go index 3b56044aaf..bc670469c7 100644 --- a/api/bean/UserRequest.go +++ b/api/bean/UserRequest.go @@ -19,6 +19,7 @@ package bean import ( "encoding/json" "github.com/devtron-labs/devtron/pkg/auth/user/bean" + "github.com/devtron-labs/devtron/pkg/sql" "time" ) @@ -168,3 +169,40 @@ type BulkDeleteRequest struct { type UserRoleGroup struct { RoleGroup *RoleGroup `json:"roleGroup"` } + +type GroupPermissionsAuditDto struct { + RoleGroupInfo *RoleGroup `json:"roleGroupInfo,omitempty"` + EntityAudit sql.AuditLog `json:"entityAudit,omitempty"` +} + +func NewGroupPermissionsAuditDto() *GroupPermissionsAuditDto { + return &GroupPermissionsAuditDto{} +} + +func (pa *GroupPermissionsAuditDto) WithRoleGroupInfo(roleGroupInfo *RoleGroup) *GroupPermissionsAuditDto { + pa.RoleGroupInfo = roleGroupInfo + return pa +} +func (pa *GroupPermissionsAuditDto) WithEntityAudit(entityAudit sql.AuditLog) *GroupPermissionsAuditDto { + pa.EntityAudit = entityAudit + return pa +} + +type UserPermissionsAuditDto struct { + UserInfo *UserInfo `json:"userInfo,omitempty"` + EntityAudit sql.AuditLog `json:"entityAudit,omitempty"` +} + +func NewUserPermissionsAuditDto() *UserPermissionsAuditDto { + return &UserPermissionsAuditDto{} +} + +func (pa *UserPermissionsAuditDto) WithUserInfo(userInfo *UserInfo) *UserPermissionsAuditDto { + pa.UserInfo = userInfo + return pa +} + +func (pa *UserPermissionsAuditDto) WithEntityAudit(entityAudit sql.AuditLog) *UserPermissionsAuditDto { + pa.EntityAudit = entityAudit + return pa +} diff --git a/internal/util/adapter.go b/internal/util/adapter.go new file mode 100644 index 0000000000..2a2a3a0f62 --- /dev/null +++ b/internal/util/adapter.go @@ -0,0 +1,10 @@ +package util + +func GetApiErrorAdapter(httpStatusCode int, code, userMessage, internalMessage string) *ApiError { + return &ApiError{ + HttpStatusCode: httpStatusCode, + Code: code, + UserMessage: userMessage, + InternalMessage: internalMessage, + } +} diff --git a/pkg/auth/user/RoleGroupService.go b/pkg/auth/user/RoleGroupService.go index 664521276d..d0d4c71f73 100644 --- a/pkg/auth/user/RoleGroupService.go +++ b/pkg/auth/user/RoleGroupService.go @@ -89,11 +89,15 @@ func (impl RoleGroupServiceImpl) CreateRoleGroup(request *bean.RoleGroup) (*bean defer tx.Rollback() if request.Id > 0 { - _, err := impl.roleGroupRepository.GetRoleGroupById(request.Id) + roleGroup, err := impl.roleGroupRepository.GetRoleGroupById(request.Id) if err != nil { impl.logger.Errorw("error while fetching user from db", "error", err) return nil, err } + if roleGroup != nil && len(roleGroup.Name) > 0 { + return nil, util.GetApiErrorAdapter(400, "400", "role group already exist with the given id", "role group already exist with the given id") + } + return nil, util.GetApiErrorAdapter(400, "400", "id not supported in create request", "id not supported in create request") } else { //loading policy for safety casbin2.LoadPolicy() diff --git a/scripts/sql/31902800_operation_audit.down.sql b/scripts/sql/31902800_operation_audit.down.sql new file mode 100644 index 0000000000..9088fbe9d8 --- /dev/null +++ b/scripts/sql/31902800_operation_audit.down.sql @@ -0,0 +1,5 @@ +-- Drop Table: operation_audit +DROP TABLE IF EXISTS "public"."operation_audit"; + +-- Drop Sequence: id_seq_operation_audit +DROP SEQUENCE IF EXISTS id_seq_operation_audit; \ No newline at end of file diff --git a/scripts/sql/31902800_operation_audit.up.sql b/scripts/sql/31902800_operation_audit.up.sql new file mode 100644 index 0000000000..05d1744d8f --- /dev/null +++ b/scripts/sql/31902800_operation_audit.up.sql @@ -0,0 +1,21 @@ +BEGIN; + +-- Create Sequence for operation_audit +CREATE SEQUENCE IF NOT EXISTS id_seq_operation_audit; + +-- Table Definition: operation_audit +CREATE TABLE IF NOT EXISTS "public"."operation_audit" ( + "id" int NOT NULL DEFAULT nextval('id_seq_operation_audit'::regclass), + "entity_id" int NOT NULL, + "entity_type" VARCHAR(50) NOT NULL , + "operation_type" VARCHAR(20) NOT NULL, + "entity_value_json" jsonb NOT NULL, + "entity_value_schema_type" VARCHAR(20) NOT NULL, + "created_on" timestamptz NOT NULL, + "created_by" int4 NOT NULL, + "updated_on" timestamptz NOT NULL, + "updated_by" int4 NOT NULL, + PRIMARY KEY ("id") + ); + +COMMIT; \ No newline at end of file diff --git a/wire_gen.go b/wire_gen.go index b59e017b53..07018678d2 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -1,6 +1,6 @@ // Code generated by Wire. DO NOT EDIT. -//go:generate go run -mod=mod github.com/google/wire/cmd/wire +//go:generate go run github.com/google/wire/cmd/wire //go:build !wireinject // +build !wireinject