Skip to content

Commit

Permalink
Merge branch 'main' into seed-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ravisuhag authored Sep 11, 2023
2 parents 0de594d + ee692f0 commit 9133b90
Show file tree
Hide file tree
Showing 56 changed files with 6,693 additions and 5,552 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TAG := $(shell git rev-list --tags --max-count=1)
VERSION := $(shell git describe --tags ${TAG})
.PHONY: build check fmt lint test test-race vet test-cover-html help install proto ui
.DEFAULT_GOAL := build
PROTON_COMMIT := "cd70e05e7c107a94b70ae16199a88ef611cef6f6"
PROTON_COMMIT := "a58081b1091c519b88630de5e9c6bffba93a5201"

ui:
@echo " > generating ui build"
Expand Down
2 changes: 1 addition & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func buildAPIDependencies(
)

organizationRepository := postgres.NewOrganizationRepository(dbc)
organizationService := organization.NewService(organizationRepository, relationService, userService, authnService)
organizationService := organization.NewService(organizationRepository, relationService, userService, authnService, cfg.App.DisableOrgsOnCreate)

domainRepository := postgres.NewDomainRepository(logger, dbc)
domainService := domain.NewService(logger, domainRepository, userService, organizationService)
Expand Down
3 changes: 3 additions & 0 deletions config/sample.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ app:
# secret string "val://user:password"
# optional
resources_config_path_secret: env://TEST_RESOURCE_CONFIG_SECRET
# disable_orgs_on_create if set to true will set the org status to disabled on creation. This can be used to
# prevent users from accessing the org until they contact the admin and get it enabled. Default is false
disable_orgs_on_create: false
# disable_orgs_listing if set to true will disallow non-admin APIs to list all organizations
disable_orgs_listing: false
# disable_orgs_listing if set to true will disallow non-admin APIs to list all users
Expand Down
6 changes: 4 additions & 2 deletions core/invitation/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ func (s Service) Create(ctx context.Context, invitation Invitation) (Invitation,
}
var tpl bytes.Buffer
err = t.Execute(&tpl, map[string]string{
"UserID": invitation.UserID,
"Organization": org.Name,
"UserID": invitation.UserID,
"Organization": org.Name,
"OrganizationID": org.ID,
"InviteID": invitation.ID.String(),
})
if err != nil {
return Invitation{}, fmt.Errorf("failed to parse email template: %w", err)
Expand Down
1 change: 1 addition & 0 deletions core/organization/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ var (
ErrInvalidID = errors.New("org id is invalid")
ErrConflict = errors.New("org already exist")
ErrInvalidDetail = errors.New("invalid org detail")
ErrDisabled = errors.New("org is disabled")
)
1 change: 1 addition & 0 deletions core/organization/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Organization struct {
Title string
Metadata metadata.Metadata
State State
Avatar string
CreatedAt time.Time
UpdatedAt time.Time
}
34 changes: 33 additions & 1 deletion core/organization/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,49 @@ type Service struct {
relationService RelationService
userService UserService
authnService AuthnService
defaultState State
}

func NewService(repository Repository, relationService RelationService,
userService UserService, authnService AuthnService) *Service {
userService UserService, authnService AuthnService, disableOrgsOnCreate bool) *Service {
defaultState := Enabled
if disableOrgsOnCreate {
defaultState = Disabled
}
return &Service{
repository: repository,
relationService: relationService,
userService: userService,
authnService: authnService,
defaultState: defaultState,
}
}

// Get returns an enabled organization by id or name. Will return `org is disabled` error if the organization is disabled
func (s Service) Get(ctx context.Context, idOrName string) (Organization, error) {
if utils.IsValidUUID(idOrName) {
orgResp, err := s.repository.GetByID(ctx, idOrName)
if err != nil {
return Organization{}, err
}
if orgResp.State == Disabled {
return Organization{}, ErrDisabled
}
return orgResp, nil
}

orgResp, err := s.repository.GetByName(ctx, idOrName)
if err != nil {
return Organization{}, err
}
if orgResp.State == Disabled {
return Organization{}, ErrDisabled
}
return orgResp, nil
}

// GetRaw returns an organization(both enabled and disabled) by id or name
func (s Service) GetRaw(ctx context.Context, idOrName string) (Organization, error) {
if utils.IsValidUUID(idOrName) {
return s.repository.GetByID(ctx, idOrName)
}
Expand All @@ -61,7 +91,9 @@ func (s Service) Create(ctx context.Context, org Organization) (Organization, er
newOrg, err := s.repository.Create(ctx, Organization{
Name: org.Name,
Title: org.Title,
Avatar: org.Avatar,
Metadata: org.Metadata,
State: s.defaultState,
})
if err != nil {
return Organization{}, err
Expand Down
1 change: 1 addition & 0 deletions core/user/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (s Service) Create(ctx context.Context, user User) (User, error) {
return s.repository.Create(ctx, User{
Name: strings.ToLower(user.Name),
Email: strings.ToLower(user.Email),
Avatar: user.Avatar,
Title: user.Title,
Metadata: user.Metadata,
})
Expand Down
1 change: 1 addition & 0 deletions core/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type User struct {
Name string
Email string
State State
Avatar string
Title string
Metadata metadata.Metadata
CreatedAt time.Time
Expand Down
13 changes: 12 additions & 1 deletion docs/docs/apis/admin-service-list-all-organizations.api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ api:
"example": "2023-06-07T05:39:56.961Z",
"description": "The time the organization was last updated.",
},
"state":
{
"type": "string",
"example": "enabled",
"description": "The state of the organization (enabled or disabled).",
},
"avatar":
{
"type": "string",
"description": "The base64 encoded image string of the organization avatar. Should be less than 2MB.",
},
},
},
},
Expand Down Expand Up @@ -358,7 +369,7 @@ Lists all the organizations in a Frontier instance. It can be filtered by user a

A successful response.

</div><div><MimeTabs schemaType={"response"}><TabItem label={"application/json"} value={"application/json"}><SchemaTabs><TabItem label={"Schema"} value={"Schema"}><details style={{}} data-collapsed={false} open={true}><summary style={{"textAlign":"left"}}><strong>Schema</strong></summary><div style={{"textAlign":"left","marginLeft":"1rem"}}></div><ul style={{"marginLeft":"1rem"}}><SchemaItem collapsible={true} className={"schemaItem"}><details style={{}}><summary style={{}}><strong>organizations</strong><span style={{"opacity":"0.6"}}> object[]</span></summary><div style={{"marginLeft":"1rem"}}><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem","paddingBottom":".5rem"}}>Array [</div></li><SchemaItem collapsible={false} name={"id"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"name"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"title"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"metadata"} required={false} schemaName={"object"} qualifierMessage={undefined} schema={{"type":"object"}}></SchemaItem><SchemaItem collapsible={false} name={"createdAt"} required={false} schemaName={"date-time"} qualifierMessage={undefined} schema={{"type":"string","format":"date-time","example":"2023-06-07T05:39:56.961Z","description":"The time the organization was created."}}></SchemaItem><SchemaItem collapsible={false} name={"updatedAt"} required={false} schemaName={"date-time"} qualifierMessage={undefined} schema={{"type":"string","format":"date-time","example":"2023-06-07T05:39:56.961Z","description":"The time the organization was last updated."}}></SchemaItem><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem"}}>]</div></li></div></details></SchemaItem></ul></details></TabItem><TabItem label={"Example (from schema)"} value={"Example (from schema)"}><ResponseSamples responseExample={"{\n \"organizations\": [\n {\n \"id\": \"string\",\n \"name\": \"string\",\n \"title\": \"string\",\n \"metadata\": {},\n \"createdAt\": \"2023-06-07T05:39:56.961Z\",\n \"updatedAt\": \"2023-06-07T05:39:56.961Z\"\n }\n ]\n}"} language={"json"}></ResponseSamples></TabItem></SchemaTabs></TabItem></MimeTabs></div></TabItem><TabItem label={"400"} value={"400"}><div>
</div><div><MimeTabs schemaType={"response"}><TabItem label={"application/json"} value={"application/json"}><SchemaTabs><TabItem label={"Schema"} value={"Schema"}><details style={{}} data-collapsed={false} open={true}><summary style={{"textAlign":"left"}}><strong>Schema</strong></summary><div style={{"textAlign":"left","marginLeft":"1rem"}}></div><ul style={{"marginLeft":"1rem"}}><SchemaItem collapsible={true} className={"schemaItem"}><details style={{}}><summary style={{}}><strong>organizations</strong><span style={{"opacity":"0.6"}}> object[]</span></summary><div style={{"marginLeft":"1rem"}}><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem","paddingBottom":".5rem"}}>Array [</div></li><SchemaItem collapsible={false} name={"id"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"name"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"title"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"metadata"} required={false} schemaName={"object"} qualifierMessage={undefined} schema={{"type":"object"}}></SchemaItem><SchemaItem collapsible={false} name={"createdAt"} required={false} schemaName={"date-time"} qualifierMessage={undefined} schema={{"type":"string","format":"date-time","example":"2023-06-07T05:39:56.961Z","description":"The time the organization was created."}}></SchemaItem><SchemaItem collapsible={false} name={"updatedAt"} required={false} schemaName={"date-time"} qualifierMessage={undefined} schema={{"type":"string","format":"date-time","example":"2023-06-07T05:39:56.961Z","description":"The time the organization was last updated."}}></SchemaItem><SchemaItem collapsible={false} name={"state"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string","example":"enabled","description":"The state of the organization (enabled or disabled)."}}></SchemaItem><SchemaItem collapsible={false} name={"avatar"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string","description":"The base64 encoded image string of the organization avatar. Should be less than 2MB."}}></SchemaItem><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem"}}>]</div></li></div></details></SchemaItem></ul></details></TabItem><TabItem label={"Example (from schema)"} value={"Example (from schema)"}><ResponseSamples responseExample={"{\n \"organizations\": [\n {\n \"id\": \"string\",\n \"name\": \"string\",\n \"title\": \"string\",\n \"metadata\": {},\n \"createdAt\": \"2023-06-07T05:39:56.961Z\",\n \"updatedAt\": \"2023-06-07T05:39:56.961Z\",\n \"state\": \"enabled\",\n \"avatar\": \"string\"\n }\n ]\n}"} language={"json"}></ResponseSamples></TabItem></SchemaTabs></TabItem></MimeTabs></div></TabItem><TabItem label={"400"} value={"400"}><div>

Bad Request - The request was malformed or contained invalid parameters.

Expand Down
14 changes: 12 additions & 2 deletions docs/docs/apis/admin-service-list-all-users.api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,17 @@ api:
"example": "2023-06-07T05:39:56.961Z",
"description": "The time the user was last updated.",
},
"state": { "type": "string" },
"state":
{
"type": "string",
"example": "enabled",
"description": "The state of the user (enabled or disabled).",
},
"avatar":
{
"type": "string",
"description": "The base64 encoded image string of the user avatar. Should be less than 2MB.",
},
},
},
},
Expand Down Expand Up @@ -440,7 +450,7 @@ Lists all the users from all the organizations in a Frontier instance. It can be

A successful response.

</div><div><MimeTabs schemaType={"response"}><TabItem label={"application/json"} value={"application/json"}><SchemaTabs><TabItem label={"Schema"} value={"Schema"}><details style={{}} data-collapsed={false} open={true}><summary style={{"textAlign":"left"}}><strong>Schema</strong></summary><div style={{"textAlign":"left","marginLeft":"1rem"}}></div><ul style={{"marginLeft":"1rem"}}><SchemaItem collapsible={false} name={"count"} required={false} schemaName={"int32"} qualifierMessage={undefined} schema={{"type":"integer","format":"int32"}}></SchemaItem><SchemaItem collapsible={true} className={"schemaItem"}><details style={{}}><summary style={{}}><strong>users</strong><span style={{"opacity":"0.6"}}> object[]</span></summary><div style={{"marginLeft":"1rem"}}><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem","paddingBottom":".5rem"}}>Array [</div></li><SchemaItem collapsible={false} name={"id"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"name"} required={false} schemaName={"can either be empty or must start with a character"} qualifierMessage={undefined} schema={{"type":"string","example":"johndoe","description":"Unique name of the user.","title":"can either be empty or must start with a character"}}></SchemaItem><SchemaItem collapsible={false} name={"title"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string","example":"John Doe","description":"Name of the user."}}></SchemaItem><SchemaItem collapsible={false} name={"email"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"metadata"} required={false} schemaName={"object"} qualifierMessage={undefined} schema={{"type":"object"}}></SchemaItem><SchemaItem collapsible={false} name={"createdAt"} required={false} schemaName={"date-time"} qualifierMessage={undefined} schema={{"type":"string","format":"date-time","example":"2023-06-07T05:39:56.961Z","description":"The time the user was created."}}></SchemaItem><SchemaItem collapsible={false} name={"updatedAt"} required={false} schemaName={"date-time"} qualifierMessage={undefined} schema={{"type":"string","format":"date-time","example":"2023-06-07T05:39:56.961Z","description":"The time the user was last updated."}}></SchemaItem><SchemaItem collapsible={false} name={"state"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string"}}></SchemaItem><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem"}}>]</div></li></div></details></SchemaItem></ul></details></TabItem><TabItem label={"Example (from schema)"} value={"Example (from schema)"}><ResponseSamples responseExample={"{\n \"count\": 0,\n \"users\": [\n {\n \"id\": \"string\",\n \"name\": \"johndoe\",\n \"title\": \"John Doe\",\n \"email\": \"string\",\n \"metadata\": {},\n \"createdAt\": \"2023-06-07T05:39:56.961Z\",\n \"updatedAt\": \"2023-06-07T05:39:56.961Z\",\n \"state\": \"string\"\n }\n ]\n}"} language={"json"}></ResponseSamples></TabItem></SchemaTabs></TabItem></MimeTabs></div></TabItem><TabItem label={"400"} value={"400"}><div>
</div><div><MimeTabs schemaType={"response"}><TabItem label={"application/json"} value={"application/json"}><SchemaTabs><TabItem label={"Schema"} value={"Schema"}><details style={{}} data-collapsed={false} open={true}><summary style={{"textAlign":"left"}}><strong>Schema</strong></summary><div style={{"textAlign":"left","marginLeft":"1rem"}}></div><ul style={{"marginLeft":"1rem"}}><SchemaItem collapsible={false} name={"count"} required={false} schemaName={"int32"} qualifierMessage={undefined} schema={{"type":"integer","format":"int32"}}></SchemaItem><SchemaItem collapsible={true} className={"schemaItem"}><details style={{}}><summary style={{}}><strong>users</strong><span style={{"opacity":"0.6"}}> object[]</span></summary><div style={{"marginLeft":"1rem"}}><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem","paddingBottom":".5rem"}}>Array [</div></li><SchemaItem collapsible={false} name={"id"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"name"} required={false} schemaName={"can either be empty or must start with a character"} qualifierMessage={undefined} schema={{"type":"string","example":"johndoe","description":"Unique name of the user.","title":"can either be empty or must start with a character"}}></SchemaItem><SchemaItem collapsible={false} name={"title"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string","example":"John Doe","description":"Name of the user."}}></SchemaItem><SchemaItem collapsible={false} name={"email"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string"}}></SchemaItem><SchemaItem collapsible={false} name={"metadata"} required={false} schemaName={"object"} qualifierMessage={undefined} schema={{"type":"object"}}></SchemaItem><SchemaItem collapsible={false} name={"createdAt"} required={false} schemaName={"date-time"} qualifierMessage={undefined} schema={{"type":"string","format":"date-time","example":"2023-06-07T05:39:56.961Z","description":"The time the user was created."}}></SchemaItem><SchemaItem collapsible={false} name={"updatedAt"} required={false} schemaName={"date-time"} qualifierMessage={undefined} schema={{"type":"string","format":"date-time","example":"2023-06-07T05:39:56.961Z","description":"The time the user was last updated."}}></SchemaItem><SchemaItem collapsible={false} name={"state"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string","example":"enabled","description":"The state of the user (enabled or disabled)."}}></SchemaItem><SchemaItem collapsible={false} name={"avatar"} required={false} schemaName={"string"} qualifierMessage={undefined} schema={{"type":"string","description":"The base64 encoded image string of the user avatar. Should be less than 2MB."}}></SchemaItem><li><div style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem"}}>]</div></li></div></details></SchemaItem></ul></details></TabItem><TabItem label={"Example (from schema)"} value={"Example (from schema)"}><ResponseSamples responseExample={"{\n \"count\": 0,\n \"users\": [\n {\n \"id\": \"string\",\n \"name\": \"johndoe\",\n \"title\": \"John Doe\",\n \"email\": \"string\",\n \"metadata\": {},\n \"createdAt\": \"2023-06-07T05:39:56.961Z\",\n \"updatedAt\": \"2023-06-07T05:39:56.961Z\",\n \"state\": \"enabled\",\n \"avatar\": \"string\"\n }\n ]\n}"} language={"json"}></ResponseSamples></TabItem></SchemaTabs></TabItem></MimeTabs></div></TabItem><TabItem label={"400"} value={"400"}><div>

Bad Request - The request was malformed or contained invalid parameters.

Expand Down
Loading

0 comments on commit 9133b90

Please sign in to comment.