Skip to content

Commit

Permalink
Merge pull request #497 from openinfradev/minor_fix
Browse files Browse the repository at this point in the history
trivial. update validation rule for user & organization
  • Loading branch information
ktkfree authored May 21, 2024
2 parents 4242cf0 + 7b8a304 commit 73bb151
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
require (
github.com/Masterminds/semver/v3 v3.2.0
github.com/Nerzal/gocloak/v13 v13.9.0
github.com/PuerkitoBio/goquery v1.9.1
github.com/aws/aws-sdk-go-v2 v1.25.0
github.com/aws/aws-sdk-go-v2/config v1.27.0
github.com/aws/aws-sdk-go-v2/credentials v1.17.0
Expand All @@ -27,7 +28,6 @@ require (
github.com/gorilla/websocket v1.5.1
github.com/iancoleman/strcase v0.3.0
github.com/open-policy-agent/opa v0.62.1
github.com/opentracing/opentracing-go v1.2.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
Expand Down Expand Up @@ -59,7 +59,6 @@ require (
github.com/Code-Hex/uniseg v0.2.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/PuerkitoBio/goquery v1.9.1 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.0 // indirect
Expand Down Expand Up @@ -110,6 +109,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func migrateSchema(db *gorm.DB) error {
&model.SystemNotificationAction{},
&model.SystemNotificationMetricParameter{},
&model.SystemNotificationTemplate{},
&model.SystemNotificationCondition{},
&model.SystemNotificationRule{},
&model.SystemNotificationCondition{},
&model.Permission{},
&model.Endpoint{},
&model.Project{},
Expand Down
9 changes: 9 additions & 0 deletions internal/usecase/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ func (u *OrganizationUsecase) Create(ctx context.Context, in *model.Organization
userId := user.GetUserId()
in.CreatorId = &userId

pg := pagination.NewPaginationWithFilter("name", "", "$eq", []string{in.Name})
organizations, err := u.repo.Fetch(ctx, pg)
if err != nil {
return "", err
}
if organizations != nil && len(*organizations) > 0 {
return "", httpErrors.NewBadRequestError(fmt.Errorf("duplicate organization name"), "O_CREATE_ALREADY_EXISTED_NAME", "")
}

// Create realm in keycloak
if organizationId, err = u.kc.CreateRealm(ctx, helper.GenerateOrganizationId()); err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type SimpleOrganizationResponse = struct {
type CreateOrganizationRequest struct {
Name string `json:"name" validate:"required,name"`
Description string `json:"description" validate:"omitempty,min=0,max=100"`
AdminAccountId string `json:"adminAccountId" validate:"required"`
AdminAccountId string `json:"adminAccountId" validate:"required,min=0,max=20,alphanum"`
AdminName string `json:"adminName" validate:"name"`
AdminEmail string `json:"adminEmail" validate:"required,email"`
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type UserResponse struct {
}

type CreateUserRequest struct {
AccountId string `json:"accountId" validate:"required"`
AccountId string `json:"accountId" validate:"required,min=0,max=20,alphanum"`
Password string `json:"password" validate:"required"`
Name string `json:"name" validate:"name"`
Email string `json:"email" validate:"required,email"`
Expand Down
1 change: 1 addition & 0 deletions pkg/httpErrors/errorCode.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var errorMap = map[ErrorCode]string{
// Organization
"O_INVALID_ORGANIZATION_NAME": "조직에 이미 존재하는 이름입니다.",
"O_NOT_EXISTED_NAME": "조직이 존재하지 않습니다.",
"O_CREATE_ALREADY_EXISTED_NAME": "이미 존재하는 이름입니다.",
"O_FAILED_UPDATE_STACK_TEMPLATES": "조직에 스택템플릿을 설정하는데 실패했습니다",
"O_FAILED_UPDATE_POLICY_TEMPLATES": "조직에 정책템플릿을 설정하는데 실패했습니다",
"O_FAILED_UPDATE_SYSTEM_NOTIFICATION_TEMPLATES": "조직에 알림템플릿을 설정하는데 실패했습니다",
Expand Down

0 comments on commit 73bb151

Please sign in to comment.