Skip to content

feat: sql script changes for operation audit #6342

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 26 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fa38d63
permissions audit
Shivam-nagar23 Jan 26, 2025
b1c45c6
adpater and repo changes
Shivam-nagar23 Jan 27, 2025
a33c0c2
save audit
Shivam-nagar23 Jan 27, 2025
312f31f
audits for user and role group
Shivam-nagar23 Jan 27, 2025
118ef58
permissions audit
Shivam-nagar23 Jan 27, 2025
0327308
permissions schema for
Shivam-nagar23 Jan 27, 2025
90ae112
generic operation audit repo adn service
Shivam-nagar23 Jan 27, 2025
d96fbf5
renaming
Shivam-nagar23 Jan 27, 2025
9b0ff7c
operations audit service
Shivam-nagar23 Jan 28, 2025
c3bfc9c
schema added
Shivam-nagar23 Jan 28, 2025
9d1a7af
opeartions audit
Shivam-nagar23 Jan 28, 2025
9f9a6e8
audit generic changes
Shivam-nagar23 Jan 28, 2025
6460318
audit struct change
Shivam-nagar23 Jan 28, 2025
91dd0e8
permissions chanages
Shivam-nagar23 Jan 28, 2025
68f6193
sql script
Shivam-nagar23 Jan 28, 2025
7ff7801
Merge branch 'develop' into feat-permissions-audit
Shivam-nagar23 Jan 28, 2025
ddf313d
sql script
Shivam-nagar23 Jan 28, 2025
37acacb
sql fetch
Shivam-nagar23 Jan 29, 2025
e7ca131
Merge branch 'develop' into feat-permissions-audit
Shivam-nagar23 Jan 30, 2025
7a7ad89
role grouplisting fix
Shivam-nagar23 Jan 30, 2025
0d30167
Merge branch 'fix-role-group-listing' into feat-permissions-audit
Shivam-nagar23 Jan 31, 2025
948de83
Merge branch 'develop' into feat-permissions-audit
Shivam-nagar23 Jan 31, 2025
b955478
role group validation
Shivam-nagar23 Jan 31, 2025
f25a0c0
removed opeartion audit pkg from oss
Shivam-nagar23 Jan 31, 2025
e717e72
column change
Shivam-nagar23 Jan 31, 2025
5de2040
Merge branch 'develop' into feat-permissions-audit
Shivam-nagar23 Feb 3, 2025
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
38 changes: 38 additions & 0 deletions api/bean/UserRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
10 changes: 10 additions & 0 deletions internal/util/adapter.go
Original file line number Diff line number Diff line change
@@ -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,
}
}
6 changes: 5 additions & 1 deletion pkg/auth/user/RoleGroupService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions scripts/sql/31902800_operation_audit.down.sql
Original file line number Diff line number Diff line change
@@ -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;
21 changes: 21 additions & 0 deletions scripts/sql/31902800_operation_audit.up.sql
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.