Skip to content

Commit

Permalink
chore: remove permission sync job
Browse files Browse the repository at this point in the history
* make updated_by on persmission optional
* remove casbin rule model
  • Loading branch information
adityathebe committed Sep 24, 2024
1 parent 7d875bf commit 0d520db
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 64 deletions.
35 changes: 0 additions & 35 deletions job/permission.go

This file was deleted.

54 changes: 28 additions & 26 deletions models/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,38 @@ import (
"github.com/google/uuid"
)

type CasbinRule struct {
ID int64 `gorm:"primaryKey;autoIncrement"`
PType string `json:"ptype"`
V0 string `json:"v0"`
V1 string `json:"v1"`
V2 string `json:"v2"`
V3 string `json:"v3"`
V4 string `json:"v4"`
V5 string `json:"v5"`
}

type Permission struct {
ID uuid.UUID `json:"id" gorm:"default:generate_ulid()"`
Action string `json:"action"`
CanaryID *uuid.UUID `json:"canary_id,omitempty"`
ComponentID *uuid.UUID `json:"component_id,omitempty"`
ConfigID *uuid.UUID `json:"config_id,omitempty"`
CreatedAt time.Time `json:"created_at"`
CreatedBy uuid.UUID `json:"created_by"`
Deny bool `json:"deny"`
Description string `json:"description"`
PersonID *uuid.UUID `json:"person_id,omitempty"`
PlaybookID *uuid.UUID `json:"playbook_id,omitempty"`
TeamID *uuid.UUID `json:"team_id,omitempty"`
Until *time.Time `json:"until"`
UpdatedAt *time.Time `json:"updated_at"`
UpdatedBy *uuid.UUID `json:"updated_by"`
ID uuid.UUID `json:"id" gorm:"default:generate_ulid()"`
Action string `json:"action"`
ConnectionID *uuid.UUID `json:"connection_id,omitempty"`
CanaryID *uuid.UUID `json:"canary_id,omitempty"`
ComponentID *uuid.UUID `json:"component_id,omitempty"`
ConfigID *uuid.UUID `json:"config_id,omitempty"`
CreatedAt time.Time `json:"created_at"`
CreatedBy uuid.UUID `json:"created_by"`
Deny bool `json:"deny"`
Description string `json:"description"`
PersonID *uuid.UUID `json:"person_id,omitempty"`
PlaybookID *uuid.UUID `json:"playbook_id,omitempty"`
TeamID *uuid.UUID `json:"team_id,omitempty"`
Until *time.Time `json:"until"`
UpdatedAt *time.Time `json:"updated_at"`
UpdatedBy *uuid.UUID `json:"updated_by"`
}

func (t *Permission) Principal() string {
if t.PersonID != nil {
return t.PersonID.String()
}

if t.TeamID != nil {
return t.TeamID.String()
}

return ""
}

func (t *Permission) Condition() string {
var rule []string

if t.PersonID != nil {
Expand Down
4 changes: 2 additions & 2 deletions models/permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/samber/lo"
)

func TestPermission_Principal(t *testing.T) {
func TestPermission_Condition(t *testing.T) {
tests := []struct {
name string
perm Permission
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestPermission_Principal(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.perm.Principal()
result := tt.perm.Condition()
if tt.expected != result {
t.Errorf("Expected %s, got %s", tt.expected, result)
}
Expand Down
3 changes: 2 additions & 1 deletion schema/permissions.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ table "permissions" {
null = true
type = uuid
}

column "updated_by" {
null = false
null = true
type = uuid
}

Expand Down

0 comments on commit 0d520db

Please sign in to comment.