mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-08 09:57:40 +00:00
fix: check if project has resourceOwner and ownerID (#8725)
# Which Problems Are Solved There is no check that the creation of a project also has a resource owner. # How the Problems Are Solved Check if resource owner and the ID of the owner are provided on command side. # Additional Changes None # Additional Context Closes #7794
This commit is contained in:
parent
34195157ce
commit
911cb42d70
@ -20,6 +20,12 @@ import (
|
|||||||
func (c *Commands) AddProjectWithID(ctx context.Context, project *domain.Project, resourceOwner, projectID string) (_ *domain.Project, err error) {
|
func (c *Commands) AddProjectWithID(ctx context.Context, project *domain.Project, resourceOwner, projectID string) (_ *domain.Project, err error) {
|
||||||
ctx, span := tracing.NewSpan(ctx)
|
ctx, span := tracing.NewSpan(ctx)
|
||||||
defer func() { span.EndWithError(err) }()
|
defer func() { span.EndWithError(err) }()
|
||||||
|
if resourceOwner == "" {
|
||||||
|
return nil, zerrors.ThrowInvalidArgument(nil, "COMMAND-w8tnSoJxtn", "Errors.ResourceOwnerMissing")
|
||||||
|
}
|
||||||
|
if projectID == "" {
|
||||||
|
return nil, zerrors.ThrowInvalidArgument(nil, "COMMAND-nDXf5vXoUj", "Errors.IDMissing")
|
||||||
|
}
|
||||||
|
|
||||||
existingProject, err := c.getProjectWriteModelByID(ctx, projectID, resourceOwner)
|
existingProject, err := c.getProjectWriteModelByID(ctx, projectID, resourceOwner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -35,6 +41,12 @@ func (c *Commands) AddProject(ctx context.Context, project *domain.Project, reso
|
|||||||
if !project.IsValid() {
|
if !project.IsValid() {
|
||||||
return nil, zerrors.ThrowInvalidArgument(nil, "PROJECT-IOVCC", "Errors.Project.Invalid")
|
return nil, zerrors.ThrowInvalidArgument(nil, "PROJECT-IOVCC", "Errors.Project.Invalid")
|
||||||
}
|
}
|
||||||
|
if resourceOwner == "" {
|
||||||
|
return nil, zerrors.ThrowInvalidArgument(nil, "COMMAND-fmq7bqQX1s", "Errors.ResourceOwnerMissing")
|
||||||
|
}
|
||||||
|
if ownerUserID == "" {
|
||||||
|
return nil, zerrors.ThrowInvalidArgument(nil, "COMMAND-xe95Gl3Dro", "Errors.IDMissing")
|
||||||
|
}
|
||||||
|
|
||||||
projectID, err := c.idGenerator.Next()
|
projectID, err := c.idGenerator.Next()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -52,6 +52,52 @@ func TestCommandSide_AddProject(t *testing.T) {
|
|||||||
err: zerrors.IsErrorInvalidArgument,
|
err: zerrors.IsErrorInvalidArgument,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "org with project owner, resourceowner empty",
|
||||||
|
fields: fields{
|
||||||
|
eventstore: eventstoreExpect(
|
||||||
|
t,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
ctx: context.Background(),
|
||||||
|
project: &domain.Project{
|
||||||
|
Name: "project",
|
||||||
|
ProjectRoleAssertion: true,
|
||||||
|
ProjectRoleCheck: true,
|
||||||
|
HasProjectCheck: true,
|
||||||
|
PrivateLabelingSetting: domain.PrivateLabelingSettingAllowLoginUserResourceOwnerPolicy,
|
||||||
|
},
|
||||||
|
resourceOwner: "",
|
||||||
|
ownerID: "user1",
|
||||||
|
},
|
||||||
|
res: res{
|
||||||
|
err: zerrors.IsErrorInvalidArgument,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "org with project owner, ownerID empty",
|
||||||
|
fields: fields{
|
||||||
|
eventstore: eventstoreExpect(
|
||||||
|
t,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
ctx: context.Background(),
|
||||||
|
project: &domain.Project{
|
||||||
|
Name: "project",
|
||||||
|
ProjectRoleAssertion: true,
|
||||||
|
ProjectRoleCheck: true,
|
||||||
|
HasProjectCheck: true,
|
||||||
|
PrivateLabelingSetting: domain.PrivateLabelingSettingAllowLoginUserResourceOwnerPolicy,
|
||||||
|
},
|
||||||
|
resourceOwner: "org1",
|
||||||
|
ownerID: "",
|
||||||
|
},
|
||||||
|
res: res{
|
||||||
|
err: zerrors.IsErrorInvalidArgument,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "org with project owner, error already exists",
|
name: "org with project owner, error already exists",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user