mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:17:32 +00:00
feat: user grants command side (#1191)
* fix: user grant command side * fix: user grant command side * fix: user grant command side check permissions * fix: unique constraint on user grants * fix: add usergrant * fix: add usergrant * fix: add usergrant * fix: user grant remove * Update internal/v2/command/auth_checks.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/v2/command/auth_checks.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/v2/command/project.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/v2/command/user_grant.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: project events Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
@@ -21,17 +21,17 @@ func TestAppendAddGrantMemberEvent(t *testing.T) {
|
||||
name: "append add grant member",
|
||||
args: args{
|
||||
project: &Project{Grants: []*ProjectGrant{
|
||||
&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}},
|
||||
member: &ProjectGrantMember{GrantID: "GrantID", UserID: "UserID", Roles: []string{"Role"}},
|
||||
&ProjectGrant{GrantID: "ProjectGrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}},
|
||||
member: &ProjectGrantMember{GrantID: "ProjectGrantID", UserID: "UserID", Roles: []string{"Role"}},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Project{
|
||||
Grants: []*ProjectGrant{
|
||||
&ProjectGrant{
|
||||
GrantID: "GrantID",
|
||||
GrantID: "ProjectGrantID",
|
||||
GrantedOrgID: "OrgID",
|
||||
RoleKeys: []string{"Key"},
|
||||
Members: []*ProjectGrantMember{&ProjectGrantMember{GrantID: "GrantID", UserID: "UserID", Roles: []string{"Role"}}}}},
|
||||
Members: []*ProjectGrantMember{&ProjectGrantMember{GrantID: "ProjectGrantID", UserID: "UserID", Roles: []string{"Role"}}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -69,21 +69,21 @@ func TestAppendChangeGrantMemberEvent(t *testing.T) {
|
||||
project: &Project{
|
||||
Grants: []*ProjectGrant{
|
||||
&ProjectGrant{
|
||||
GrantID: "GrantID",
|
||||
GrantID: "ProjectGrantID",
|
||||
GrantedOrgID: "OrgID",
|
||||
RoleKeys: []string{"Key"},
|
||||
Members: []*ProjectGrantMember{&ProjectGrantMember{GrantID: "GrantID", UserID: "UserID", Roles: []string{"Role"}}}}},
|
||||
Members: []*ProjectGrantMember{&ProjectGrantMember{GrantID: "ProjectGrantID", UserID: "UserID", Roles: []string{"Role"}}}}},
|
||||
},
|
||||
member: &ProjectGrantMember{GrantID: "GrantID", UserID: "UserID", Roles: []string{"RoleChanged"}},
|
||||
member: &ProjectGrantMember{GrantID: "ProjectGrantID", UserID: "UserID", Roles: []string{"RoleChanged"}},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Project{
|
||||
Grants: []*ProjectGrant{
|
||||
&ProjectGrant{
|
||||
GrantID: "GrantID",
|
||||
GrantID: "ProjectGrantID",
|
||||
GrantedOrgID: "OrgID",
|
||||
RoleKeys: []string{"Key"},
|
||||
Members: []*ProjectGrantMember{&ProjectGrantMember{GrantID: "GrantID", UserID: "UserID", Roles: []string{"RoleChanged"}}}}},
|
||||
Members: []*ProjectGrantMember{&ProjectGrantMember{GrantID: "ProjectGrantID", UserID: "UserID", Roles: []string{"RoleChanged"}}}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -120,12 +120,12 @@ func TestAppendRemoveGrantMemberEvent(t *testing.T) {
|
||||
project: &Project{
|
||||
Grants: []*ProjectGrant{
|
||||
&ProjectGrant{
|
||||
GrantID: "GrantID",
|
||||
GrantID: "ProjectGrantID",
|
||||
GrantedOrgID: "OrgID",
|
||||
RoleKeys: []string{"Key"},
|
||||
Members: []*ProjectGrantMember{&ProjectGrantMember{GrantID: "GrantID", UserID: "UserID", Roles: []string{"Role"}}}}},
|
||||
Members: []*ProjectGrantMember{&ProjectGrantMember{GrantID: "ProjectGrantID", UserID: "UserID", Roles: []string{"Role"}}}}},
|
||||
},
|
||||
member: &ProjectGrantMember{GrantID: "GrantID", UserID: "UserID", Roles: []string{"RoleChanged"}},
|
||||
member: &ProjectGrantMember{GrantID: "ProjectGrantID", UserID: "UserID", Roles: []string{"RoleChanged"}},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
},
|
||||
|
@@ -22,10 +22,10 @@ func TestAppendAddGrantEvent(t *testing.T) {
|
||||
name: "append add grant event",
|
||||
args: args{
|
||||
project: &Project{},
|
||||
role: &ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}},
|
||||
role: &ProjectGrant{GrantID: "ProjectGrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}},
|
||||
result: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "ProjectGrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -59,11 +59,11 @@ func TestAppendChangeGrantEvent(t *testing.T) {
|
||||
{
|
||||
name: "append change grant event",
|
||||
args: args{
|
||||
project: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}},
|
||||
grant: &ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"KeyChanged"}},
|
||||
project: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "ProjectGrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}},
|
||||
grant: &ProjectGrant{GrantID: "ProjectGrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"KeyChanged"}},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"KeyChanged"}}}},
|
||||
result: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "ProjectGrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"KeyChanged"}}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -97,8 +97,8 @@ func TestAppendRemoveGrantEvent(t *testing.T) {
|
||||
{
|
||||
name: "append remove role event",
|
||||
args: args{
|
||||
project: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}},
|
||||
grant: &ProjectGrant{GrantID: "GrantID"},
|
||||
project: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "ProjectGrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}},
|
||||
grant: &ProjectGrant{GrantID: "ProjectGrantID"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Project{Grants: []*ProjectGrant{}},
|
||||
@@ -133,22 +133,22 @@ func TestAppendGrantStateEvent(t *testing.T) {
|
||||
{
|
||||
name: "append deactivate grant event",
|
||||
args: args{
|
||||
project: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}},
|
||||
grant: &ProjectGrantID{GrantID: "GrantID"},
|
||||
project: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "ProjectGrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}},
|
||||
grant: &ProjectGrantID{GrantID: "ProjectGrantID"},
|
||||
event: &es_models.Event{},
|
||||
state: model.ProjectGrantStateInactive,
|
||||
},
|
||||
result: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}, State: int32(model.ProjectGrantStateInactive)}}},
|
||||
result: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "ProjectGrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}, State: int32(model.ProjectGrantStateInactive)}}},
|
||||
},
|
||||
{
|
||||
name: "append reactivate grant event",
|
||||
args: args{
|
||||
project: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}},
|
||||
grant: &ProjectGrantID{GrantID: "GrantID"},
|
||||
project: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "ProjectGrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}}}},
|
||||
grant: &ProjectGrantID{GrantID: "ProjectGrantID"},
|
||||
event: &es_models.Event{},
|
||||
state: model.ProjectGrantStateActive,
|
||||
},
|
||||
result: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "GrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}, State: int32(model.ProjectGrantStateActive)}}},
|
||||
result: &Project{Grants: []*ProjectGrant{&ProjectGrant{GrantID: "ProjectGrantID", GrantedOrgID: "OrgID", RoleKeys: []string{"Key"}, State: int32(model.ProjectGrantStateActive)}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
Reference in New Issue
Block a user