diff --git a/internal/groups/api/decode.go b/internal/groups/api/decode.go index 059be6ced..68f899148 100644 --- a/internal/groups/api/decode.go +++ b/internal/groups/api/decode.go @@ -267,10 +267,6 @@ func decodePageMeta(r *http.Request) (mggroups.PageMeta, error) { if err != nil { return mggroups.PageMeta{}, errors.Wrap(apiutil.ErrValidation, err) } - ownerID, err := apiutil.ReadStringQuery(r, api.OwnerKey, "") - if err != nil { - return mggroups.PageMeta{}, errors.Wrap(apiutil.ErrValidation, err) - } name, err := apiutil.ReadStringQuery(r, api.NameKey, "") if err != nil { return mggroups.PageMeta{}, errors.Wrap(apiutil.ErrValidation, err) @@ -284,7 +280,6 @@ func decodePageMeta(r *http.Request) (mggroups.PageMeta, error) { Offset: offset, Limit: limit, Name: name, - OwnerID: ownerID, Metadata: meta, Status: st, } diff --git a/internal/groups/events/events.go b/internal/groups/events/events.go index 118a4fd88..880c7eddf 100644 --- a/internal/groups/events/events.go +++ b/internal/groups/events/events.go @@ -46,8 +46,8 @@ func (cge createGroupEvent) Encode() (map[string]interface{}, error) { "created_at": cge.CreatedAt, } - if cge.Owner != "" { - val["owner"] = cge.Owner + if cge.Domain != "" { + val["domain"] = cge.Domain } if cge.Parent != "" { val["parent"] = cge.Parent @@ -87,8 +87,8 @@ func (uge updateGroupEvent) Encode() (map[string]interface{}, error) { if uge.ID != "" { val["id"] = uge.ID } - if uge.Owner != "" { - val["owner"] = uge.Owner + if uge.Domain != "" { + val["domain"] = uge.Domain } if uge.Parent != "" { val["parent"] = uge.Parent @@ -144,8 +144,8 @@ func (vge viewGroupEvent) Encode() (map[string]interface{}, error) { "id": vge.ID, } - if vge.Owner != "" { - val["owner"] = vge.Owner + if vge.Domain != "" { + val["domain"] = vge.Domain } if vge.Parent != "" { val["parent"] = vge.Parent @@ -207,8 +207,8 @@ func (lge listGroupEvent) Encode() (map[string]interface{}, error) { if lge.Name != "" { val["name"] = lge.Name } - if lge.OwnerID != "" { - val["owner_id"] = lge.OwnerID + if lge.DomainID != "" { + val["domain_id"] = lge.DomainID } if lge.Tag != "" { val["tag"] = lge.Tag diff --git a/internal/groups/mocks/groups.go b/internal/groups/mocks/groups.go index 3d8113b76..f87d08ceb 100644 --- a/internal/groups/mocks/groups.go +++ b/internal/groups/mocks/groups.go @@ -69,7 +69,7 @@ func (m *Repository) Save(ctx context.Context, g mggroups.Group) (mggroups.Group return mggroups.Group{}, repoerr.ErrCreateEntity } - if g.Owner == WrongID { + if g.Domain == WrongID { return mggroups.Group{}, repoerr.ErrCreateEntity } diff --git a/internal/groups/postgres/groups.go b/internal/groups/postgres/groups.go index 4077bf593..b653fb701 100644 --- a/internal/groups/postgres/groups.go +++ b/internal/groups/postgres/groups.go @@ -34,9 +34,9 @@ func New(db postgres.Database) mggroups.Repository { } func (repo groupRepository) Save(ctx context.Context, g mggroups.Group) (mggroups.Group, error) { - q := `INSERT INTO groups (name, description, id, owner_id, parent_id, metadata, created_at, status) - VALUES (:name, :description, :id, :owner_id, :parent_id, :metadata, :created_at, :status) - RETURNING id, name, description, owner_id, COALESCE(parent_id, '') AS parent_id, metadata, created_at, status;` + q := `INSERT INTO groups (name, description, id, domain_id, parent_id, metadata, created_at, status) + VALUES (:name, :description, :id, :domain_id, :parent_id, :metadata, :created_at, :status) + RETURNING id, name, description, domain_id, COALESCE(parent_id, '') AS parent_id, metadata, created_at, status;` dbg, err := toDBGroup(g) if err != nil { return mggroups.Group{}, err @@ -74,7 +74,7 @@ func (repo groupRepository) Update(ctx context.Context, g mggroups.Group) (mggro g.Status = mgclients.EnabledStatus q := fmt.Sprintf(`UPDATE groups SET %s updated_at = :updated_at, updated_by = :updated_by WHERE id = :id AND status = :status - RETURNING id, name, description, owner_id, COALESCE(parent_id, '') AS parent_id, metadata, created_at, updated_at, updated_by, status`, upq) + RETURNING id, name, description, domain_id, COALESCE(parent_id, '') AS parent_id, metadata, created_at, updated_at, updated_by, status`, upq) dbu, err := toDBGroup(g) if err != nil { @@ -99,7 +99,7 @@ func (repo groupRepository) Update(ctx context.Context, g mggroups.Group) (mggro func (repo groupRepository) ChangeStatus(ctx context.Context, group mggroups.Group) (mggroups.Group, error) { qc := `UPDATE groups SET status = :status, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id - RETURNING id, name, description, owner_id, COALESCE(parent_id, '') AS parent_id, metadata, created_at, updated_at, updated_by, status` + RETURNING id, name, description, domain_id, COALESCE(parent_id, '') AS parent_id, metadata, created_at, updated_at, updated_by, status` dbg, err := toDBGroup(group) if err != nil { @@ -122,7 +122,7 @@ func (repo groupRepository) ChangeStatus(ctx context.Context, group mggroups.Gro } func (repo groupRepository) RetrieveByID(ctx context.Context, id string) (mggroups.Group, error) { - q := `SELECT id, name, owner_id, COALESCE(parent_id, '') AS parent_id, description, metadata, created_at, updated_at, updated_by, status FROM groups + q := `SELECT id, name, domain_id, COALESCE(parent_id, '') AS parent_id, description, metadata, created_at, updated_at, updated_by, status FROM groups WHERE id = :id` dbg := dbGroup{ @@ -153,7 +153,7 @@ func (repo groupRepository) RetrieveAll(ctx context.Context, gm mggroups.Page) ( q = buildHierachy(gm) } if gm.ID == "" { - q = `SELECT DISTINCT g.id, g.owner_id, COALESCE(g.parent_id, '') AS parent_id, g.name, g.description, + q = `SELECT DISTINCT g.id, g.domain_id, COALESCE(g.parent_id, '') AS parent_id, g.name, g.description, g.metadata, g.created_at, g.updated_at, g.updated_by, g.status FROM groups g` } q = fmt.Sprintf("%s %s ORDER BY g.created_at LIMIT :limit OFFSET :offset;", q, query) @@ -192,7 +192,7 @@ func (repo groupRepository) RetrieveAll(ctx context.Context, gm mggroups.Page) ( func (repo groupRepository) RetrieveByIDs(ctx context.Context, gm mggroups.Page, ids ...string) (mggroups.Page, error) { var q string - if (len(ids) <= 0) && (gm.PageMeta.OwnerID == "") { + if (len(ids) <= 0) && (gm.PageMeta.DomainID == "") { return mggroups.Page{PageMeta: mggroups.PageMeta{Offset: gm.Offset, Limit: gm.Limit}}, nil } query := buildQuery(gm, ids...) @@ -201,7 +201,7 @@ func (repo groupRepository) RetrieveByIDs(ctx context.Context, gm mggroups.Page, q = buildHierachy(gm) } if gm.ID == "" { - q = `SELECT DISTINCT g.id, g.owner_id, COALESCE(g.parent_id, '') AS parent_id, g.name, g.description, + q = `SELECT DISTINCT g.id, g.domain_id, COALESCE(g.parent_id, '') AS parent_id, g.name, g.description, g.metadata, g.created_at, g.updated_at, g.updated_by, g.status FROM groups g` } q = fmt.Sprintf("%s %s ORDER BY g.created_at LIMIT :limit OFFSET :offset;", q, query) @@ -310,15 +310,15 @@ func buildHierachy(gm mggroups.Page) string { switch { case gm.Direction >= 0: // ancestors query = `WITH RECURSIVE groups_cte as ( - SELECT id, COALESCE(parent_id, '') AS parent_id, owner_id, name, description, metadata, created_at, updated_at, updated_by, status, 0 as level from groups WHERE id = :id - UNION SELECT x.id, COALESCE(x.parent_id, '') AS parent_id, x.owner_id, x.name, x.description, x.metadata, x.created_at, x.updated_at, x.updated_by, x.status, level - 1 from groups x + SELECT id, COALESCE(parent_id, '') AS parent_id, domain_id, name, description, metadata, created_at, updated_at, updated_by, status, 0 as level from groups WHERE id = :id + UNION SELECT x.id, COALESCE(x.parent_id, '') AS parent_id, x.domain_id, x.name, x.description, x.metadata, x.created_at, x.updated_at, x.updated_by, x.status, level - 1 from groups x INNER JOIN groups_cte a ON a.parent_id = x.id ) SELECT * FROM groups_cte g` case gm.Direction < 0: // descendants query = `WITH RECURSIVE groups_cte as ( - SELECT id, COALESCE(parent_id, '') AS parent_id, owner_id, name, description, metadata, created_at, updated_at, updated_by, status, 0 as level, CONCAT('', '', id) as path from groups WHERE id = :id - UNION SELECT x.id, COALESCE(x.parent_id, '') AS parent_id, x.owner_id, x.name, x.description, x.metadata, x.created_at, x.updated_at, x.updated_by, x.status, level + 1, CONCAT(path, '.', x.id) as path from groups x + SELECT id, COALESCE(parent_id, '') AS parent_id, domain_id, name, description, metadata, created_at, updated_at, updated_by, status, 0 as level, CONCAT('', '', id) as path from groups WHERE id = :id + UNION SELECT x.id, COALESCE(x.parent_id, '') AS parent_id, x.domain_id, x.name, x.description, x.metadata, x.created_at, x.updated_at, x.updated_by, x.status, level + 1, CONCAT(path, '.', x.id) as path from groups x INNER JOIN groups_cte d ON d.id = x.parent_id ) SELECT * FROM groups_cte g` } @@ -337,8 +337,8 @@ func buildQuery(gm mggroups.Page, ids ...string) string { if gm.Status != mgclients.AllStatus { queries = append(queries, "g.status = :status") } - if gm.OwnerID != "" { - queries = append(queries, "g.owner_id = :owner_id") + if gm.DomainID != "" { + queries = append(queries, "g.domain_id = :domain_id") } if len(gm.Metadata) > 0 { queries = append(queries, "g.metadata @> :metadata") @@ -353,7 +353,7 @@ func buildQuery(gm mggroups.Page, ids ...string) string { type dbGroup struct { ID string `db:"id"` ParentID *string `db:"parent_id,omitempty"` - OwnerID string `db:"owner_id,omitempty"` + DomainID string `db:"domain_id,omitempty"` Name string `db:"name"` Description string `db:"description,omitempty"` Level int `db:"level"` @@ -390,7 +390,7 @@ func toDBGroup(g mggroups.Group) (dbGroup, error) { ID: g.ID, Name: g.Name, ParentID: parentID, - OwnerID: g.Owner, + DomainID: g.Domain, Description: g.Description, Metadata: data, Path: g.Path, @@ -425,7 +425,7 @@ func toGroup(g dbGroup) (mggroups.Group, error) { ID: g.ID, Name: g.Name, Parent: parentID, - Owner: g.OwnerID, + Domain: g.DomainID, Description: g.Description, Metadata: metadata, Level: g.Level, @@ -460,7 +460,7 @@ func toDBGroupPage(pm mggroups.Page) (dbGroupPage, error) { Offset: pm.Offset, Limit: pm.Limit, ParentID: pm.ID, - OwnerID: pm.OwnerID, + DomainID: pm.DomainID, Status: pm.Status, }, nil } @@ -470,7 +470,7 @@ type dbGroupPage struct { ID string `db:"id"` Name string `db:"name"` ParentID string `db:"parent_id"` - OwnerID string `db:"owner_id"` + DomainID string `db:"domain_id"` Metadata []byte `db:"metadata"` Path string `db:"path"` Level uint64 `db:"level"` diff --git a/internal/groups/postgres/init.go b/internal/groups/postgres/init.go index 0cff683e5..0b799c46c 100644 --- a/internal/groups/postgres/init.go +++ b/internal/groups/postgres/init.go @@ -17,7 +17,7 @@ func Migration() *migrate.MemoryMigrationSource { `CREATE TABLE IF NOT EXISTS groups ( id VARCHAR(36) PRIMARY KEY, parent_id VARCHAR(36), - owner_id VARCHAR(36) NOT NULL, + domain_id VARCHAR(36) NOT NULL, name VARCHAR(1024) NOT NULL, description VARCHAR(1024), metadata JSONB, @@ -25,7 +25,7 @@ func Migration() *migrate.MemoryMigrationSource { updated_at TIMESTAMP, updated_by VARCHAR(254), status SMALLINT NOT NULL DEFAULT 0 CHECK (status >= 0), - UNIQUE (owner_id, name), + UNIQUE (domain_id, name), FOREIGN KEY (parent_id) REFERENCES groups (id) ON DELETE SET NULL )`, }, diff --git a/internal/groups/service.go b/internal/groups/service.go index 0af806f40..3c2b93b0f 100644 --- a/internal/groups/service.go +++ b/internal/groups/service.go @@ -60,7 +60,7 @@ func (svc service) CreateGroup(ctx context.Context, token, kind string, g groups g.ID = groupID g.CreatedAt = time.Now() - g.Owner = res.GetDomainId() + g.Domain = res.GetDomainId() if g.Parent != "" { _, err := svc.authorizeToken(ctx, auth.UserType, token, auth.EditPermission, auth.GroupType, g.Parent) if err != nil { @@ -221,7 +221,7 @@ func (svc service) ListGroups(ctx context.Context, token, memberKind, memberID s if res.GetDomainId() == "" { return groups.Page{}, errors.ErrMalformedEntity } - gm.PageMeta.OwnerID = res.GetDomainId() + gm.PageMeta.DomainID = res.GetDomainId() default: // If domain is disabled , then this authorization will fail for all non-admin domain users if _, err := svc.authorizeKind(ctx, "", auth.UserType, auth.UsersKind, res.GetId(), auth.MembershipPermission, auth.DomainType, res.GetDomainId()); err != nil { diff --git a/pkg/clients/clients.go b/pkg/clients/clients.go index 2fed8e67e..8d16fe913 100644 --- a/pkg/clients/clients.go +++ b/pkg/clients/clients.go @@ -42,7 +42,7 @@ type Client struct { ID string `json:"id"` Name string `json:"name,omitempty"` Tags []string `json:"tags,omitempty"` - Owner string `json:"owner,omitempty"` // nullable + Domain string `json:"domain,omitempty"` Credentials Credentials `json:"credentials,omitempty"` Metadata Metadata `json:"metadata,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"` @@ -96,9 +96,6 @@ type Repository interface { // UpdateSecret updates secret for client with given identity. UpdateSecret(ctx context.Context, client Client) (Client, error) - // UpdateOwner updates owner for client with given id. - UpdateOwner(ctx context.Context, client Client) (Client, error) - // UpdateRole updates role for client with given id. UpdateRole(ctx context.Context, client Client) (Client, error) diff --git a/pkg/clients/page.go b/pkg/clients/page.go index 0bf4ccc82..87285fdf4 100644 --- a/pkg/clients/page.go +++ b/pkg/clients/page.go @@ -12,7 +12,7 @@ type Page struct { Order string `json:"order,omitempty"` Dir string `json:"dir,omitempty"` Metadata Metadata `json:"metadata,omitempty"` - Owner string `json:"owner,omitempty"` + Domain string `json:"domain,omitempty"` Tag string `json:"tag,omitempty"` Permission string `json:"permission,omitempty"` Status Status `json:"status,omitempty"` diff --git a/pkg/clients/postgres/clients.go b/pkg/clients/postgres/clients.go index 057b79e04..a00442088 100644 --- a/pkg/clients/postgres/clients.go +++ b/pkg/clients/postgres/clients.go @@ -39,7 +39,7 @@ func (repo ClientRepository) Update(ctx context.Context, client clients.Client) client.Status = clients.EnabledStatus q := fmt.Sprintf(`UPDATE clients SET %s updated_at = :updated_at, updated_by = :updated_by WHERE id = :id AND status = :status - RETURNING id, name, tags, identity, secret, metadata, COALESCE(owner_id, '') AS owner_id, status, created_at, updated_at, updated_by`, + RETURNING id, name, tags, identity, secret, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by`, upq) return repo.update(ctx, client, q) @@ -49,7 +49,7 @@ func (repo ClientRepository) UpdateTags(ctx context.Context, client clients.Clie client.Status = clients.EnabledStatus q := `UPDATE clients SET tags = :tags, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id AND status = :status - RETURNING id, name, tags, identity, metadata, COALESCE(owner_id, '') AS owner_id, status, created_at, updated_at, updated_by` + RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by` return repo.update(ctx, client, q) } @@ -57,7 +57,7 @@ func (repo ClientRepository) UpdateTags(ctx context.Context, client clients.Clie func (repo ClientRepository) UpdateIdentity(ctx context.Context, client clients.Client) (clients.Client, error) { q := `UPDATE clients SET identity = :identity, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id AND status = :status - RETURNING id, name, tags, identity, metadata, COALESCE(owner_id, '') AS owner_id, status, created_at, updated_at, updated_by` + RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by` return repo.update(ctx, client, q) } @@ -65,15 +65,7 @@ func (repo ClientRepository) UpdateIdentity(ctx context.Context, client clients. func (repo ClientRepository) UpdateSecret(ctx context.Context, client clients.Client) (clients.Client, error) { q := `UPDATE clients SET secret = :secret, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id AND status = :status - RETURNING id, name, tags, identity, metadata, COALESCE(owner_id, '') AS owner_id, status, created_at, updated_at, updated_by` - - return repo.update(ctx, client, q) -} - -func (repo ClientRepository) UpdateOwner(ctx context.Context, client clients.Client) (clients.Client, error) { - q := `UPDATE clients SET owner_id = :owner_id, updated_at = :updated_at, updated_by = :updated_by - WHERE id = :id AND status = :status - RETURNING id, name, tags, identity, metadata, COALESCE(owner_id, '') AS owner_id, status, created_at, updated_at, updated_by` + RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by` return repo.update(ctx, client, q) } @@ -81,20 +73,20 @@ func (repo ClientRepository) UpdateOwner(ctx context.Context, client clients.Cli func (repo ClientRepository) UpdateRole(ctx context.Context, client clients.Client) (clients.Client, error) { q := `UPDATE clients SET role = :role, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id AND status = :status - RETURNING id, name, tags, identity, metadata, COALESCE(owner_id, '') AS owner_id, status, created_at, updated_at, updated_by` + RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by` return repo.update(ctx, client, q) } func (repo ClientRepository) ChangeStatus(ctx context.Context, client clients.Client) (clients.Client, error) { q := `UPDATE clients SET status = :status WHERE id = :id - RETURNING id, name, tags, identity, metadata, COALESCE(owner_id, '') AS owner_id, status, created_at, updated_at, updated_by` + RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by` return repo.update(ctx, client, q) } func (repo ClientRepository) RetrieveByID(ctx context.Context, id string) (clients.Client, error) { - q := `SELECT id, name, tags, COALESCE(owner_id, '') AS owner_id, identity, secret, metadata, created_at, updated_at, updated_by, status + q := `SELECT id, name, tags, COALESCE(domain_id, '') AS domain_id, identity, secret, metadata, created_at, updated_at, updated_by, status FROM clients WHERE id = :id` dbc := DBClient{ @@ -120,7 +112,7 @@ func (repo ClientRepository) RetrieveByID(ctx context.Context, id string) (clien } func (repo ClientRepository) RetrieveByIdentity(ctx context.Context, identity string) (clients.Client, error) { - q := `SELECT id, name, tags, COALESCE(owner_id, '') AS owner_id, identity, secret, metadata, created_at, updated_at, updated_by, status + q := `SELECT id, name, tags, COALESCE(domain_id, '') AS domain_id, identity, secret, metadata, created_at, updated_at, updated_by, status FROM clients WHERE identity = :identity AND status = :status` dbc := DBClient{ @@ -152,7 +144,7 @@ func (repo ClientRepository) RetrieveAll(ctx context.Context, pm clients.Page) ( return clients.ClientsPage{}, errors.Wrap(repoerr.ErrViewEntity, err) } - q := fmt.Sprintf(`SELECT c.id, c.name, c.tags, c.identity, c.metadata, COALESCE(c.owner_id, '') AS owner_id, c.status, + q := fmt.Sprintf(`SELECT c.id, c.name, c.tags, c.identity, c.metadata, COALESCE(c.domain_id, '') AS domain_id, c.status, c.created_at, c.updated_at, COALESCE(c.updated_by, '') AS updated_by FROM clients c %s ORDER BY c.created_at LIMIT :limit OFFSET :offset;`, query) dbPage, err := ToDBClientsPage(pm) @@ -248,7 +240,7 @@ func (repo ClientRepository) RetrieveAllBasicInfo(ctx context.Context, pm client } func (repo ClientRepository) RetrieveAllByIDs(ctx context.Context, pm clients.Page) (clients.ClientsPage, error) { - if (len(pm.IDs) <= 0) && (pm.Owner == "") { + if (len(pm.IDs) == 0) && (pm.Domain == "") { return clients.ClientsPage{ Page: clients.Page{Total: pm.Total, Offset: pm.Offset, Limit: pm.Limit}, }, nil @@ -258,7 +250,7 @@ func (repo ClientRepository) RetrieveAllByIDs(ctx context.Context, pm clients.Pa return clients.ClientsPage{}, errors.Wrap(repoerr.ErrViewEntity, err) } - q := fmt.Sprintf(`SELECT c.id, c.name, c.tags, c.identity, c.metadata, COALESCE(c.owner_id, '') AS owner_id, c.status, + q := fmt.Sprintf(`SELECT c.id, c.name, c.tags, c.identity, c.metadata, COALESCE(c.domain_id, '') AS domain_id, c.status, c.created_at, c.updated_at, COALESCE(c.updated_by, '') AS updated_by FROM clients c %s ORDER BY c.created_at LIMIT :limit OFFSET :offset;`, query) dbPage, err := ToDBClientsPage(pm) @@ -333,7 +325,7 @@ type DBClient struct { Name string `db:"name,omitempty"` Tags pgtype.TextArray `db:"tags,omitempty"` Identity string `db:"identity"` - Owner *string `db:"owner_id,omitempty"` // nullable + Domain string `db:"domain_id"` Secret string `db:"secret"` Metadata []byte `db:"metadata,omitempty"` CreatedAt time.Time `db:"created_at,omitempty"` @@ -357,10 +349,6 @@ func ToDBClient(c clients.Client) (DBClient, error) { if err := tags.Set(c.Tags); err != nil { return DBClient{}, err } - var owner *string - if c.Owner != "" { - owner = &c.Owner - } var updatedBy *string if c.UpdatedBy != "" { updatedBy = &c.UpdatedBy @@ -374,7 +362,7 @@ func ToDBClient(c clients.Client) (DBClient, error) { ID: c.ID, Name: c.Name, Tags: tags, - Owner: owner, + Domain: c.Domain, Identity: c.Credentials.Identity, Secret: c.Credentials.Secret, Metadata: data, @@ -397,10 +385,6 @@ func ToClient(c DBClient) (clients.Client, error) { for _, e := range c.Tags.Elements { tags = append(tags, e.String) } - var owner string - if c.Owner != nil { - owner = *c.Owner - } var updatedBy string if c.UpdatedBy != nil { updatedBy = *c.UpdatedBy @@ -411,10 +395,10 @@ func ToClient(c DBClient) (clients.Client, error) { } cli := clients.Client{ - ID: c.ID, - Name: c.Name, - Tags: tags, - Owner: owner, + ID: c.ID, + Name: c.Name, + Tags: tags, + Domain: c.Domain, Credentials: clients.Credentials{ Identity: c.Identity, Secret: c.Secret, @@ -444,7 +428,7 @@ func ToDBClientsPage(pm clients.Page) (dbClientsPage, error) { Name: pm.Name, Identity: pm.Identity, Metadata: data, - Owner: pm.Owner, + Domain: pm.Domain, Total: pm.Total, Offset: pm.Offset, Limit: pm.Limit, @@ -459,7 +443,7 @@ type dbClientsPage struct { Limit uint64 `db:"limit"` Offset uint64 `db:"offset"` Name string `db:"name"` - Owner string `db:"owner_id"` + Domain string `db:"domain_id"` Identity string `db:"identity"` Metadata []byte `db:"metadata"` Tag string `db:"tag"` @@ -493,9 +477,8 @@ func PageQuery(pm clients.Page) (string, error) { if pm.Status != clients.AllStatus { query = append(query, "c.status = :status") } - // For listing clients that the specified client owns but not sharedby - if pm.Owner != "" { - query = append(query, "c.owner_id = :owner_id") + if pm.Domain != "" { + query = append(query, "c.domain_id = :domain_id") } if pm.Role != nil { diff --git a/pkg/groups/groups.go b/pkg/groups/groups.go index aa78d9070..0b451e56c 100644 --- a/pkg/groups/groups.go +++ b/pkg/groups/groups.go @@ -20,10 +20,10 @@ const ( // Group represents the group of Clients. // Indicates a level in tree hierarchy. Root node is level 1. // Path in a tree consisting of group IDs -// Paths are unique per owner. +// Paths are unique per domain. type Group struct { ID string `json:"id"` - Owner string `json:"owner_id,omitempty"` + Domain string `json:"domain_id,omitempty"` Parent string `json:"parent_id,omitempty"` Name string `json:"name"` Description string `json:"description,omitempty"` diff --git a/pkg/groups/page.go b/pkg/groups/page.go index e0155aa5d..2f8fc8fdd 100644 --- a/pkg/groups/page.go +++ b/pkg/groups/page.go @@ -11,7 +11,7 @@ type PageMeta struct { Offset uint64 `json:"offset"` Limit uint64 `json:"limit"` Name string `json:"name,omitempty"` - OwnerID string `json:"identity,omitempty"` + DomainID string `json:"domain_id,omitempty"` Tag string `json:"tag,omitempty"` Metadata clients.Metadata `json:"metadata,omitempty"` Status clients.Status `json:"status,omitempty"` diff --git a/pkg/sdk/go/things.go b/pkg/sdk/go/things.go index 0593d7b33..ceba8a9d0 100644 --- a/pkg/sdk/go/things.go +++ b/pkg/sdk/go/things.go @@ -28,7 +28,7 @@ type Thing struct { Name string `json:"name,omitempty"` Credentials Credentials `json:"credentials"` Tags []string `json:"tags,omitempty"` - Owner string `json:"owner,omitempty"` + Domain string `json:"domain,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"` diff --git a/pkg/sdk/go/users.go b/pkg/sdk/go/users.go index b7a4c583d..ab6cfe831 100644 --- a/pkg/sdk/go/users.go +++ b/pkg/sdk/go/users.go @@ -30,7 +30,7 @@ type User struct { Name string `json:"name,omitempty"` Credentials Credentials `json:"credentials"` Tags []string `json:"tags,omitempty"` - Owner string `json:"owner,omitempty"` + Domain string `json:"domain,omitempty"` Metadata Metadata `json:"metadata,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"` diff --git a/pkg/sdk/go/users_test.go b/pkg/sdk/go/users_test.go index 3285a3037..07c01ed14 100644 --- a/pkg/sdk/go/users_test.go +++ b/pkg/sdk/go/users_test.go @@ -920,7 +920,7 @@ func TestUpdateClientRole(t *testing.T) { client: client2, response: sdk.User{}, token: validToken, - err: errors.NewSDKErrorWithStatus(errors.Wrap(users.ErrFailedOwnerUpdate, users.ErrFailedOwnerUpdate), http.StatusInternalServerError), + err: errors.NewSDKErrorWithStatus(errors.Wrap(users.ErrFailedUpdateRole, users.ErrFailedUpdateRole), http.StatusInternalServerError), }, { desc: "update a user that can't be marshalled", diff --git a/things/api/http/clients.go b/things/api/http/clients.go index 4abcd9587..4b5bcf4f7 100644 --- a/things/api/http/clients.go +++ b/things/api/http/clients.go @@ -157,7 +157,6 @@ func decodeViewClientPerms(_ context.Context, r *http.Request) (interface{}, err } func decodeListClients(_ context.Context, r *http.Request) (interface{}, error) { - var ownerID string s, err := apiutil.ReadStringQuery(r, api.StatusKey, api.DefClientStatus) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -182,11 +181,6 @@ func decodeListClients(_ context.Context, r *http.Request) (interface{}, error) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) } - oid, err := apiutil.ReadStringQuery(r, api.OwnerKey, "") - if err != nil { - return nil, err - } - p, err := apiutil.ReadStringQuery(r, api.PermissionKey, api.DefPermission) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -196,10 +190,6 @@ func decodeListClients(_ context.Context, r *http.Request) (interface{}, error) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) } - - if oid != "" { - ownerID = oid - } st, err := mgclients.ToStatus(s) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -215,7 +205,6 @@ func decodeListClients(_ context.Context, r *http.Request) (interface{}, error) permission: p, listPerms: lp, userID: chi.URLParam(r, "userID"), - owner: ownerID, } return req, nil } diff --git a/things/api/http/endpoints.go b/things/api/http/endpoints.go index 6e90c0fad..d33dd9a6b 100644 --- a/things/api/http/endpoints.go +++ b/things/api/http/endpoints.go @@ -103,7 +103,6 @@ func listClientsEndpoint(svc things.Service) endpoint.Endpoint { Status: req.status, Offset: req.offset, Limit: req.limit, - Owner: req.owner, Name: req.name, Tag: req.tag, Permission: req.permission, diff --git a/things/api/http/requests.go b/things/api/http/requests.go index 7aab9565e..091f32b5b 100644 --- a/things/api/http/requests.go +++ b/things/api/http/requests.go @@ -92,7 +92,6 @@ type listClientsReq struct { limit uint64 name string tag string - owner string permission string visibility string userID string diff --git a/things/events/events.go b/things/events/events.go index a709838c4..3d2cd953d 100644 --- a/things/events/events.go +++ b/things/events/events.go @@ -60,8 +60,8 @@ func (cce createClientEvent) Encode() (map[string]interface{}, error) { tags := fmt.Sprintf("[%s]", strings.Join(cce.Tags, ",")) val["tags"] = tags } - if cce.Owner != "" { - val["owner"] = cce.Owner + if cce.Domain != "" { + val["domain"] = cce.Domain } if cce.Metadata != nil { metadata, err := json.Marshal(cce.Metadata) @@ -103,8 +103,8 @@ func (uce updateClientEvent) Encode() (map[string]interface{}, error) { tags := fmt.Sprintf("[%s]", strings.Join(uce.Tags, ",")) val["tags"] = tags } - if uce.Owner != "" { - val["owner"] = uce.Owner + if uce.Domain != "" { + val["domain"] = uce.Domain } if uce.Credentials.Identity != "" { val["identity"] = uce.Credentials.Identity @@ -161,8 +161,8 @@ func (vce viewClientEvent) Encode() (map[string]interface{}, error) { tags := fmt.Sprintf("[%s]", strings.Join(vce.Tags, ",")) val["tags"] = tags } - if vce.Owner != "" { - val["owner"] = vce.Owner + if vce.Domain != "" { + val["domain"] = vce.Domain } if vce.Credentials.Identity != "" { val["identity"] = vce.Credentials.Identity @@ -234,8 +234,8 @@ func (lce listClientEvent) Encode() (map[string]interface{}, error) { val["metadata"] = metadata } - if lce.Owner != "" { - val["owner"] = lce.Owner + if lce.Domain != "" { + val["domain"] = lce.Domain } if lce.Tag != "" { val["tag"] = lce.Tag @@ -288,8 +288,8 @@ func (lcge listClientByGroupEvent) Encode() (map[string]interface{}, error) { val["metadata"] = metadata } - if lcge.Owner != "" { - val["owner"] = lcge.Owner + if lcge.Domain != "" { + val["domain"] = lcge.Domain } if lcge.Tag != "" { val["tag"] = lcge.Tag diff --git a/things/mocks/repository.go b/things/mocks/repository.go index 14429f163..d347b4209 100644 --- a/things/mocks/repository.go +++ b/things/mocks/repository.go @@ -324,34 +324,6 @@ func (_m *Repository) UpdateIdentity(ctx context.Context, client clients.Client) return r0, r1 } -// UpdateOwner provides a mock function with given fields: ctx, client -func (_m *Repository) UpdateOwner(ctx context.Context, client clients.Client) (clients.Client, error) { - ret := _m.Called(ctx, client) - - if len(ret) == 0 { - panic("no return value specified for UpdateOwner") - } - - var r0 clients.Client - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, clients.Client) (clients.Client, error)); ok { - return rf(ctx, client) - } - if rf, ok := ret.Get(0).(func(context.Context, clients.Client) clients.Client); ok { - r0 = rf(ctx, client) - } else { - r0 = ret.Get(0).(clients.Client) - } - - if rf, ok := ret.Get(1).(func(context.Context, clients.Client) error); ok { - r1 = rf(ctx, client) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - // UpdateRole provides a mock function with given fields: ctx, client func (_m *Repository) UpdateRole(ctx context.Context, client clients.Client) (clients.Client, error) { ret := _m.Called(ctx, client) diff --git a/things/postgres/clients.go b/things/postgres/clients.go index 065bc2992..7fc600a4d 100644 --- a/things/postgres/clients.go +++ b/things/postgres/clients.go @@ -55,9 +55,9 @@ func (repo clientRepo) Save(ctx context.Context, cs ...mgclients.Client) ([]mgcl var clients []mgclients.Client for _, cli := range cs { - q := `INSERT INTO clients (id, name, tags, owner_id, identity, secret, metadata, created_at, updated_at, updated_by, status) - VALUES (:id, :name, :tags, :owner_id, :identity, :secret, :metadata, :created_at, :updated_at, :updated_by, :status) - RETURNING id, name, tags, identity, secret, metadata, COALESCE(owner_id, '') AS owner_id, status, created_at, updated_at, updated_by` + q := `INSERT INTO clients (id, name, tags, domain_id, identity, secret, metadata, created_at, updated_at, updated_by, status) + VALUES (:id, :name, :tags, :domain_id, :identity, :secret, :metadata, :created_at, :updated_at, :updated_by, :status) + RETURNING id, name, tags, identity, secret, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by` dbcli, err := pgclients.ToDBClient(cli) if err != nil { @@ -93,7 +93,7 @@ func (repo clientRepo) Save(ctx context.Context, cs ...mgclients.Client) ([]mgcl } func (repo clientRepo) RetrieveBySecret(ctx context.Context, key string) (mgclients.Client, error) { - q := fmt.Sprintf(`SELECT id, name, tags, COALESCE(owner_id, '') AS owner_id, identity, secret, metadata, created_at, updated_at, updated_by, status + q := fmt.Sprintf(`SELECT id, name, tags, COALESCE(domain_id, '') AS domain_id, identity, secret, metadata, created_at, updated_at, updated_by, status FROM clients WHERE secret = $1 AND status = %d`, mgclients.EnabledStatus) diff --git a/things/postgres/init.go b/things/postgres/init.go index d59627e9c..026e14f9f 100644 --- a/things/postgres/init.go +++ b/things/postgres/init.go @@ -19,7 +19,7 @@ func Migration() *migrate.MemoryMigrationSource { `CREATE TABLE IF NOT EXISTS clients ( id VARCHAR(36) PRIMARY KEY, name VARCHAR(1024), - owner_id VARCHAR(36), + domain_id VARCHAR(36), identity VARCHAR(254), secret VARCHAR(4096) NOT NULL, tags TEXT[], @@ -28,8 +28,8 @@ func Migration() *migrate.MemoryMigrationSource { updated_at TIMESTAMP, updated_by VARCHAR(254), status SMALLINT NOT NULL DEFAULT 0 CHECK (status >= 0), - UNIQUE (owner_id, secret), - UNIQUE (owner_id, name) + UNIQUE (domain_id, secret), + UNIQUE (domain_id, name) )`, }, Down: []string{ diff --git a/things/service.go b/things/service.go index 1da19c87e..4e9c211a1 100644 --- a/things/service.go +++ b/things/service.go @@ -94,7 +94,7 @@ func (svc service) CreateThings(ctx context.Context, token string, cls ...mgclie if c.Status != mgclients.DisabledStatus && c.Status != mgclients.EnabledStatus { return []mgclients.Client{}, svcerr.ErrInvalidStatus } - c.Owner = user.GetDomainId() + c.Domain = user.GetDomainId() c.CreatedAt = time.Now() clients = append(clients, c) } @@ -188,7 +188,7 @@ func (svc service) ListClients(ctx context.Context, token, reqUserID string, pm if res.GetDomainId() == "" { return mgclients.ClientsPage{}, errors.ErrDomainAuthorization } - pm.Owner = res.GetDomainId() + pm.Domain = res.GetDomainId() default: // If domain is disabled , then this authorization will fail for all non-admin domain users if _, err := svc.authorize(ctx, "", auth.UserType, auth.UsersKind, res.GetId(), auth.MembershipPermission, auth.DomainType, res.GetDomainId()); err != nil { diff --git a/users/api/clients.go b/users/api/clients.go index 32dea1a2b..bed70aa89 100644 --- a/users/api/clients.go +++ b/users/api/clients.go @@ -189,7 +189,6 @@ func decodeViewProfile(_ context.Context, r *http.Request) (interface{}, error) } func decodeListClients(_ context.Context, r *http.Request) (interface{}, error) { - var sharedID, ownerID string s, err := apiutil.ReadStringQuery(r, api.StatusKey, api.DefClientStatus) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -218,14 +217,7 @@ func decodeListClients(_ context.Context, r *http.Request) (interface{}, error) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) } - oid, err := apiutil.ReadStringQuery(r, api.OwnerKey, "") - if err != nil { - return nil, err - } - visibility, err := apiutil.ReadStringQuery(r, api.VisibilityKey, "") - if err != nil { - return nil, errors.Wrap(apiutil.ErrValidation, err) - } + order, err := apiutil.ReadStringQuery(r, api.OrderKey, api.DefOrder) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -234,18 +226,7 @@ func decodeListClients(_ context.Context, r *http.Request) (interface{}, error) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) } - switch visibility { - case api.MyVisibility: - ownerID = api.MyVisibility - case api.SharedVisibility: - sharedID = api.MyVisibility - case api.AllVisibility: - sharedID = api.MyVisibility - ownerID = api.MyVisibility - } - if oid != "" { - ownerID = oid - } + st, err := mgclients.ToStatus(s) if err != nil { return nil, errors.Wrap(apiutil.ErrValidation, err) @@ -259,8 +240,6 @@ func decodeListClients(_ context.Context, r *http.Request) (interface{}, error) name: n, identity: i, tag: t, - sharedBy: sharedID, - owner: ownerID, order: order, dir: dir, } @@ -518,10 +497,6 @@ func queryPageParams(r *http.Request, defPermission string) (mgclients.Page, err if err != nil { return mgclients.Page{}, errors.Wrap(apiutil.ErrValidation, err) } - oid, err := apiutil.ReadStringQuery(r, api.OwnerKey, "") - if err != nil { - return mgclients.Page{}, errors.Wrap(apiutil.ErrValidation, err) - } st, err := mgclients.ToStatus(s) if err != nil { return mgclients.Page{}, errors.Wrap(apiutil.ErrValidation, err) @@ -538,7 +513,6 @@ func queryPageParams(r *http.Request, defPermission string) (mgclients.Page, err Identity: i, Name: n, Tag: t, - Owner: oid, Permission: p, }, nil } diff --git a/users/api/endpoints.go b/users/api/endpoints.go index 50f7d91c8..b8bb81101 100644 --- a/users/api/endpoints.go +++ b/users/api/endpoints.go @@ -75,7 +75,6 @@ func listClientsEndpoint(svc users.Service) endpoint.Endpoint { Status: req.status, Offset: req.offset, Limit: req.limit, - Owner: req.owner, Name: req.name, Tag: req.tag, Metadata: req.metadata, diff --git a/users/api/requests.go b/users/api/requests.go index dfd51147c..ea890176b 100644 --- a/users/api/requests.go +++ b/users/api/requests.go @@ -61,7 +61,6 @@ type listClientsReq struct { tag string identity string visibility string - owner string sharedBy string metadata mgclients.Metadata order string diff --git a/users/events/events.go b/users/events/events.go index b02d18ddf..95bba4790 100644 --- a/users/events/events.go +++ b/users/events/events.go @@ -65,8 +65,8 @@ func (cce createClientEvent) Encode() (map[string]interface{}, error) { tags := fmt.Sprintf("[%s]", strings.Join(cce.Tags, ",")) val["tags"] = tags } - if cce.Owner != "" { - val["owner"] = cce.Owner + if cce.Domain != "" { + val["domain"] = cce.Domain } if cce.Metadata != nil { metadata, err := json.Marshal(cce.Metadata) @@ -163,8 +163,8 @@ func (vce viewClientEvent) Encode() (map[string]interface{}, error) { tags := fmt.Sprintf("[%s]", strings.Join(vce.Tags, ",")) val["tags"] = tags } - if vce.Owner != "" { - val["owner"] = vce.Owner + if vce.Domain != "" { + val["domain"] = vce.Domain } if vce.Credentials.Identity != "" { val["identity"] = vce.Credentials.Identity @@ -210,8 +210,8 @@ func (vpe viewProfileEvent) Encode() (map[string]interface{}, error) { tags := fmt.Sprintf("[%s]", strings.Join(vpe.Tags, ",")) val["tags"] = tags } - if vpe.Owner != "" { - val["owner"] = vpe.Owner + if vpe.Domain != "" { + val["domain"] = vpe.Domain } if vpe.Credentials.Identity != "" { val["identity"] = vpe.Credentials.Identity @@ -269,8 +269,8 @@ func (lce listClientEvent) Encode() (map[string]interface{}, error) { val["metadata"] = metadata } - if lce.Owner != "" { - val["owner"] = lce.Owner + if lce.Domain != "" { + val["domain"] = lce.Domain } if lce.Tag != "" { val["tag"] = lce.Tag @@ -321,8 +321,8 @@ func (lcge listClientByGroupEvent) Encode() (map[string]interface{}, error) { val["metadata"] = metadata } - if lcge.Owner != "" { - val["owner"] = lcge.Owner + if lcge.Domain != "" { + val["domain"] = lcge.Domain } if lcge.Tag != "" { val["tag"] = lcge.Tag diff --git a/users/mocks/repository.go b/users/mocks/repository.go index 6a71d302f..2bc4c6509 100644 --- a/users/mocks/repository.go +++ b/users/mocks/repository.go @@ -287,34 +287,6 @@ func (_m *Repository) UpdateIdentity(ctx context.Context, client clients.Client) return r0, r1 } -// UpdateOwner provides a mock function with given fields: ctx, client -func (_m *Repository) UpdateOwner(ctx context.Context, client clients.Client) (clients.Client, error) { - ret := _m.Called(ctx, client) - - if len(ret) == 0 { - panic("no return value specified for UpdateOwner") - } - - var r0 clients.Client - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, clients.Client) (clients.Client, error)); ok { - return rf(ctx, client) - } - if rf, ok := ret.Get(0).(func(context.Context, clients.Client) clients.Client); ok { - r0 = rf(ctx, client) - } else { - r0 = ret.Get(0).(clients.Client) - } - - if rf, ok := ret.Get(1).(func(context.Context, clients.Client) error); ok { - r1 = rf(ctx, client) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - // UpdateRole provides a mock function with given fields: ctx, client func (_m *Repository) UpdateRole(ctx context.Context, client clients.Client) (clients.Client, error) { ret := _m.Called(ctx, client) diff --git a/users/postgres/clients.go b/users/postgres/clients.go index 7f5ebb53d..23454e0b8 100644 --- a/users/postgres/clients.go +++ b/users/postgres/clients.go @@ -47,9 +47,9 @@ func NewRepository(db postgres.Database) Repository { } func (repo clientRepo) Save(ctx context.Context, c mgclients.Client) (mgclients.Client, error) { - q := `INSERT INTO clients (id, name, tags, owner_id, identity, secret, metadata, created_at, status, role) - VALUES (:id, :name, :tags, :owner_id, :identity, :secret, :metadata, :created_at, :status, :role) - RETURNING id, name, tags, identity, metadata, COALESCE(owner_id, '') AS owner_id, status, created_at` + q := `INSERT INTO clients (id, name, tags, identity, secret, metadata, created_at, status, role) + VALUES (:id, :name, :tags, :identity, :secret, :metadata, :created_at, :status, :role) + RETURNING id, name, tags, identity, metadata, status, created_at` dbc, err := pgclients.ToDBClient(c) if err != nil { return mgclients.Client{}, errors.Wrap(repoerr.ErrCreateEntity, err) @@ -95,7 +95,7 @@ func (repo clientRepo) CheckSuperAdmin(ctx context.Context, adminID string) erro } func (repo clientRepo) RetrieveByID(ctx context.Context, id string) (mgclients.Client, error) { - q := `SELECT id, name, tags, COALESCE(owner_id, '') AS owner_id, identity, secret, metadata, created_at, updated_at, updated_by, status, role + q := `SELECT id, name, tags, identity, secret, metadata, created_at, updated_at, updated_by, status, role FROM clients WHERE id = :id` dbc := pgclients.DBClient{ @@ -126,7 +126,7 @@ func (repo clientRepo) RetrieveAll(ctx context.Context, pm mgclients.Page) (mgcl return mgclients.ClientsPage{}, errors.Wrap(errors.ErrViewEntity, err) } - q := fmt.Sprintf(`SELECT c.id, c.name, c.tags, c.identity, c.metadata, COALESCE(c.owner_id, '') AS owner_id, c.status, c.role, + q := fmt.Sprintf(`SELECT c.id, c.name, c.tags, c.identity, c.metadata, c.status, c.role, c.created_at, c.updated_at, COALESCE(c.updated_by, '') AS updated_by FROM clients c %s ORDER BY c.created_at LIMIT :limit OFFSET :offset;`, query) dbPage, err := pgclients.ToDBClientsPage(pm) @@ -175,7 +175,7 @@ func (repo clientRepo) RetrieveAll(ctx context.Context, pm mgclients.Page) (mgcl func (repo clientRepo) UpdateRole(ctx context.Context, client mgclients.Client) (mgclients.Client, error) { query := `UPDATE clients SET role = :role, updated_at = :updated_at, updated_by = :updated_by WHERE id = :id AND status = :status - RETURNING id, name, tags, identity, metadata, COALESCE(owner_id, '') AS owner_id, status, role, created_at, updated_at, updated_by` + RETURNING id, name, tags, identity, metadata, status, role, created_at, updated_at, updated_by` dbc, err := pgclients.ToDBClient(client) if err != nil { diff --git a/users/postgres/init.go b/users/postgres/init.go index 3edda715f..3bcf20bf7 100644 --- a/users/postgres/init.go +++ b/users/postgres/init.go @@ -21,7 +21,7 @@ func Migration() *migrate.MemoryMigrationSource { `CREATE TABLE IF NOT EXISTS clients ( id VARCHAR(36) PRIMARY KEY, name VARCHAR(254) NOT NULL UNIQUE, - owner_id VARCHAR(36), + domain_id VARCHAR(36), identity VARCHAR(254) NOT NULL UNIQUE, secret TEXT NOT NULL, tags TEXT[], diff --git a/users/service.go b/users/service.go index e40ce0aad..08d8447ce 100644 --- a/users/service.go +++ b/users/service.go @@ -27,8 +27,8 @@ var ( // ErrFailedPolicyUpdate indicates a failure to update user policy. ErrFailedPolicyUpdate = errors.New("failed to update user policy") - // ErrFailedOwnerUpdate indicates a failure to update user policy. - ErrFailedOwnerUpdate = errors.New("failed to update user owner") + // ErrFailedUpdateRole indicates a failure to update user role. + ErrFailedUpdateRole = errors.New("failed to update user role") // ErrAddPolicies indictaed a failre to add policies. errAddPolicies = errors.New("failed to add policies") @@ -391,7 +391,7 @@ func (svc service) UpdateClientRole(ctx context.Context, token string, cli mgcli if errRollback := svc.updateClientPolicy(ctx, cli.ID, mgclients.UserRole); errRollback != nil { return mgclients.Client{}, errors.Wrap(err, errors.Wrap(repoerr.ErrRollbackTx, errRollback)) } - return mgclients.Client{}, errors.Wrap(ErrFailedOwnerUpdate, err) + return mgclients.Client{}, errors.Wrap(ErrFailedUpdateRole, err) } return client, nil }