Skip to content

Commit 67ed0de

Browse files
feat: sql script changes for operation audit (#6342)
* permissions audit * adpater and repo changes * save audit * audits for user and role group * permissions audit * permissions schema for * generic operation audit repo adn service * renaming * operations audit service * schema added * opeartions audit * audit generic changes * audit struct change * permissions chanages * sql script * sql script * sql fetch * role grouplisting fix * role group validation * removed opeartion audit pkg from oss * column change
1 parent e7b1858 commit 67ed0de

File tree

6 files changed

+80
-2
lines changed

6 files changed

+80
-2
lines changed

api/bean/UserRequest.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package bean
1919
import (
2020
"encoding/json"
2121
"github.com/devtron-labs/devtron/pkg/auth/user/bean"
22+
"github.com/devtron-labs/devtron/pkg/sql"
2223
"time"
2324
)
2425

@@ -168,3 +169,40 @@ type BulkDeleteRequest struct {
168169
type UserRoleGroup struct {
169170
RoleGroup *RoleGroup `json:"roleGroup"`
170171
}
172+
173+
type GroupPermissionsAuditDto struct {
174+
RoleGroupInfo *RoleGroup `json:"roleGroupInfo,omitempty"`
175+
EntityAudit sql.AuditLog `json:"entityAudit,omitempty"`
176+
}
177+
178+
func NewGroupPermissionsAuditDto() *GroupPermissionsAuditDto {
179+
return &GroupPermissionsAuditDto{}
180+
}
181+
182+
func (pa *GroupPermissionsAuditDto) WithRoleGroupInfo(roleGroupInfo *RoleGroup) *GroupPermissionsAuditDto {
183+
pa.RoleGroupInfo = roleGroupInfo
184+
return pa
185+
}
186+
func (pa *GroupPermissionsAuditDto) WithEntityAudit(entityAudit sql.AuditLog) *GroupPermissionsAuditDto {
187+
pa.EntityAudit = entityAudit
188+
return pa
189+
}
190+
191+
type UserPermissionsAuditDto struct {
192+
UserInfo *UserInfo `json:"userInfo,omitempty"`
193+
EntityAudit sql.AuditLog `json:"entityAudit,omitempty"`
194+
}
195+
196+
func NewUserPermissionsAuditDto() *UserPermissionsAuditDto {
197+
return &UserPermissionsAuditDto{}
198+
}
199+
200+
func (pa *UserPermissionsAuditDto) WithUserInfo(userInfo *UserInfo) *UserPermissionsAuditDto {
201+
pa.UserInfo = userInfo
202+
return pa
203+
}
204+
205+
func (pa *UserPermissionsAuditDto) WithEntityAudit(entityAudit sql.AuditLog) *UserPermissionsAuditDto {
206+
pa.EntityAudit = entityAudit
207+
return pa
208+
}

internal/util/adapter.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package util
2+
3+
func GetApiErrorAdapter(httpStatusCode int, code, userMessage, internalMessage string) *ApiError {
4+
return &ApiError{
5+
HttpStatusCode: httpStatusCode,
6+
Code: code,
7+
UserMessage: userMessage,
8+
InternalMessage: internalMessage,
9+
}
10+
}

pkg/auth/user/RoleGroupService.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,15 @@ func (impl RoleGroupServiceImpl) CreateRoleGroup(request *bean.RoleGroup) (*bean
8989
defer tx.Rollback()
9090

9191
if request.Id > 0 {
92-
_, err := impl.roleGroupRepository.GetRoleGroupById(request.Id)
92+
roleGroup, err := impl.roleGroupRepository.GetRoleGroupById(request.Id)
9393
if err != nil {
9494
impl.logger.Errorw("error while fetching user from db", "error", err)
9595
return nil, err
9696
}
97+
if roleGroup != nil && len(roleGroup.Name) > 0 {
98+
return nil, util.GetApiErrorAdapter(400, "400", "role group already exist with the given id", "role group already exist with the given id")
99+
}
100+
return nil, util.GetApiErrorAdapter(400, "400", "id not supported in create request", "id not supported in create request")
97101
} else {
98102
//loading policy for safety
99103
casbin2.LoadPolicy()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Drop Table: operation_audit
2+
DROP TABLE IF EXISTS "public"."operation_audit";
3+
4+
-- Drop Sequence: id_seq_operation_audit
5+
DROP SEQUENCE IF EXISTS id_seq_operation_audit;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
BEGIN;
2+
3+
-- Create Sequence for operation_audit
4+
CREATE SEQUENCE IF NOT EXISTS id_seq_operation_audit;
5+
6+
-- Table Definition: operation_audit
7+
CREATE TABLE IF NOT EXISTS "public"."operation_audit" (
8+
"id" int NOT NULL DEFAULT nextval('id_seq_operation_audit'::regclass),
9+
"entity_id" int NOT NULL,
10+
"entity_type" VARCHAR(50) NOT NULL ,
11+
"operation_type" VARCHAR(20) NOT NULL,
12+
"entity_value_json" jsonb NOT NULL,
13+
"entity_value_schema_type" VARCHAR(20) NOT NULL,
14+
"created_on" timestamptz NOT NULL,
15+
"created_by" int4 NOT NULL,
16+
"updated_on" timestamptz NOT NULL,
17+
"updated_by" int4 NOT NULL,
18+
PRIMARY KEY ("id")
19+
);
20+
21+
COMMIT;

wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)