Skip to content

Commit

Permalink
fix: update current user api expects email to be non nil
Browse files Browse the repository at this point in the history
Signed-off-by: Kush Sharma <[email protected]>
  • Loading branch information
kushsharma committed Sep 22, 2023
1 parent 4f28794 commit dc9559f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
31 changes: 22 additions & 9 deletions internal/bootstrap/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func MergeServiceDefinitions(definitions ...ServiceDefinition) *ServiceDefinitio

// RoleDefinition are a set of permissions which can be assigned to a user or group
type RoleDefinition struct {
Title string `yaml:"title"`
Name string `yaml:"name"`
Description string `yaml:"description"`
Permissions []string `yaml:"permissions"`
Expand Down Expand Up @@ -254,13 +255,15 @@ func IsValidPermissionName(name string) bool {
var PredefinedRoles = []RoleDefinition{
// org
{
Name: "app_organization_owner",
Title: "Organization Owner",
Name: "app_organization_owner",
Permissions: []string{
"app_organization_administer",
},
},
{
Name: "app_organization_manager",
Title: "Organization Manager",
Name: "app_organization_manager",
Permissions: []string{
"app_organization_update",
"app_organization_get",
Expand All @@ -272,49 +275,59 @@ var PredefinedRoles = []RoleDefinition{
},
},
{
Name: "app_organization_invitationmanager",
Title: "Organization Access Manager",
Name: "app_organization_accessmanager",
Permissions: []string{
"app_organization_invitationcreate",
"app_organization_invitationlist",
"app_organization_rolemanage",
"app_organization_policymanage",
},
},
{
Name: "app_organization_viewer",
Title: "Organization Viewer",
Name: "app_organization_viewer",
Permissions: []string{
"app_organization_get",
},
},
// project
{
Name: RoleProjectOwner,
Title: "Project Owner",
Name: RoleProjectOwner,
Permissions: []string{
"app_project_administer",
},
},
{
Name: "app_project_manager",
Title: "Project Manager",
Name: "app_project_manager",
Permissions: []string{
"app_project_update",
"app_project_get",
"app_project_resourcelist",
"app_organization_projectcreate",
"app_organization_projectlist",
},
},
{
Name: "app_project_viewer",
Title: "Project Viewer",
Name: "app_project_viewer",
Permissions: []string{
"app_project_get",
},
},
// group
{
Name: GroupOwnerRole,
Title: "Group Owner",
Name: GroupOwnerRole,
Permissions: []string{
"app_group_administer",
},
},
{
Name: GroupMemberRole,
Title: "Group Member",
Name: GroupMemberRole,
Permissions: []string{
"app_group_get",
},
Expand Down
1 change: 1 addition & 0 deletions internal/bootstrap/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func (s Service) MigrateRoles(ctx context.Context) error {

func (s Service) createRole(ctx context.Context, orgID string, defRole schema.RoleDefinition) error {
_, err := s.roleService.Upsert(ctx, role.Role{
Title: defRole.Title,
Name: defRole.Name,
OrgID: orgID,
Permissions: defRole.Permissions,
Expand Down
2 changes: 2 additions & 0 deletions internal/store/postgres/role_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func (r RoleRepository) buildListQuery(dialect goqu.DialectWrapper) *goqu.Select
goqu.I("r.permissions"),
goqu.I("r.state"),
goqu.I("r.metadata"),
goqu.I("r.created_at"),
goqu.I("r.updated_at"),
).From(goqu.T(TABLE_ROLES).As("r"))
return roleSelectStatement
}
Expand Down
4 changes: 3 additions & 1 deletion internal/store/postgres/role_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,9 @@ func (s *RoleRepositoryTestSuite) TestGetByName() {
}
if tc.ErrString == "" {
s.Assert().NoError(err)
s.Assert().Equal(tc.ExpectedRole, got)
s.Assert().Equal(tc.ExpectedRole.ID, got.ID)
s.Assert().Equal(tc.ExpectedRole.Name, got.Name)
s.Assert().Equal(tc.ExpectedRole.Permissions, got.Permissions)
}
})
}
Expand Down
3 changes: 0 additions & 3 deletions internal/store/postgres/user_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,6 @@ func (r UserRepository) UpdateByID(ctx context.Context, usr user.User) (user.Use
if usr.ID == "" || !utils.IsValidUUID(usr.ID) {
return user.User{}, user.ErrInvalidID
}
if strings.TrimSpace(usr.Email) == "" || strings.TrimSpace(usr.Name) == "" {
return user.User{}, user.ErrInvalidDetails
}

marshaledMetadata, err := json.Marshal(usr.Metadata)
if err != nil {
Expand Down

0 comments on commit dc9559f

Please sign in to comment.