Skip to content

Commit

Permalink
feat: list projects a user has access to
Browse files Browse the repository at this point in the history
Signed-off-by: Kush Sharma <[email protected]>
  • Loading branch information
kushsharma committed Jul 22, 2023
1 parent defb7ba commit f8d5046
Show file tree
Hide file tree
Showing 25 changed files with 6,519 additions and 4,611 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 := "a194e19f9a458129e134f57e275fb34186b1e844"
PROTON_COMMIT := "7a4fd9e7a6e557aec52f9dafe0c26fa099e54b0b"

ui:
@echo " > generating ui build"
Expand Down
4 changes: 4 additions & 0 deletions core/group/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"time"

"github.com/raystack/shield/internal/bootstrap/schema"

"github.com/raystack/shield/core/relation"
"github.com/raystack/shield/pkg/metadata"
)
Expand All @@ -19,6 +21,8 @@ const (
Disabled State = "disabled"
)

var MemberPermission = schema.MembershipPermission

type Repository interface {
Create(ctx context.Context, grp Group) (Group, error)
GetByID(ctx context.Context, id string) (Group, error)
Expand Down
21 changes: 0 additions & 21 deletions core/group/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,6 @@ func (s Service) ListByUser(ctx context.Context, userId string, flt Filter) ([]G
return s.repository.GetByIDs(ctx, subjectIDs, flt)
}

func (s Service) ListGroupUsers(ctx context.Context, groupID string) ([]user.User, error) {
subjectIDs, err := s.relationService.LookupSubjects(ctx, relation.Relation{
Object: relation.Object{
Namespace: schema.GroupNamespace,
ID: groupID,
},
Subject: relation.Subject{
Namespace: schema.UserPrincipal,
},
RelationName: schema.MembershipPermission,
})
if err != nil {
return nil, err
}
if len(subjectIDs) == 0 {
// no users
return nil, nil
}
return s.userService.GetByIDs(ctx, subjectIDs)
}

// AddMember adds a subject(user) to group as member
func (s Service) AddMember(ctx context.Context, groupID, relationName string, principal authenticate.Principal) error {
rel := relation.Relation{
Expand Down
1 change: 1 addition & 0 deletions core/organization/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (s Service) Create(ctx context.Context, org Organization) (Organization, er

newOrg, err := s.repository.Create(ctx, Organization{
Name: org.Name,
Title: org.Title,
Metadata: org.Metadata,
})
if err != nil {
Expand Down
40 changes: 32 additions & 8 deletions core/project/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
type RelationService interface {
Create(ctx context.Context, rel relation.Relation) (relation.Relation, error)
LookupSubjects(ctx context.Context, rel relation.Relation) ([]string, error)
LookupResources(ctx context.Context, rel relation.Relation) ([]string, error)
Delete(ctx context.Context, rel relation.Relation) error
}

Expand Down Expand Up @@ -65,28 +66,51 @@ func (s Service) List(ctx context.Context, f Filter) ([]Project, error) {
return s.repository.List(ctx, f)
}

func (s Service) ListByUser(ctx context.Context, userID string) ([]Project, error) {
requestedUser, err := s.userService.GetByID(ctx, userID)
if err != nil {
return nil, err
}
projIDs, err := s.relationService.LookupResources(ctx, relation.Relation{
Object: relation.Object{
Namespace: schema.ProjectNamespace,
},
Subject: relation.Subject{
Namespace: schema.UserPrincipal,
ID: requestedUser.ID,
},
RelationName: MemberPermission,
})
if err != nil {
return nil, err
}
if len(projIDs) == 0 {
return []Project{}, nil
}
return s.GetByIDs(ctx, projIDs)
}

func (s Service) Update(ctx context.Context, prj Project) (Project, error) {
if utils.IsValidUUID(prj.ID) {
return s.repository.UpdateByID(ctx, prj)
}
return s.repository.UpdateByName(ctx, prj)
}

func (s Service) AddAdmins(ctx context.Context, idOrSlug string, userIds []string) ([]user.User, error) {
// TODO(discussion): can be done with create relations
return []user.User{}, nil
}

func (s Service) ListUsers(ctx context.Context, id string, permissionFilter string) ([]user.User, error) {
requestedProject, err := s.Get(ctx, id)
if err != nil {
return nil, err
}
userIDs, err := s.relationService.LookupSubjects(ctx, relation.Relation{
Object: relation.Object{
ID: id,
ID: requestedProject.ID,
Namespace: schema.ProjectNamespace,
},
Subject: relation.Subject{
Namespace: schema.UserPrincipal,
SubRelationName: permissionFilter,
Namespace: schema.UserPrincipal,
},
RelationName: permissionFilter,
})
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
id: shield-service-create-organization-audit-log
id: shield-service-create-organization-audit-logs
title: "Create audit log"
description: "Create new audit logs in a batch."
sidebar_label: "Create audit log"
Expand All @@ -8,7 +8,7 @@ hide_table_of_contents: true
api:
{
"description": "Create new audit logs in a batch.",
"operationId": "ShieldService_CreateOrganizationAuditLog",
"operationId": "ShieldService_CreateOrganizationAuditLogs",
"responses":
{
"200":
Expand Down
10 changes: 8 additions & 2 deletions docs/docs/apis/shield-service-delete-service-user.api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ api:
"required": true,
"schema": { "type": "string" },
},
{
"name": "orgId",
"in": "query",
"required": false,
"schema": { "type": "string" },
},
],
"tags": ["ServiceUser"],
"method": "delete",
Expand Down Expand Up @@ -260,7 +266,7 @@ api:
{
"path": ["v1beta1", "serviceusers", ":id"],
"host": ["{{baseUrl}}"],
"query": [],
"query": [{ "disabled": false, "key": "orgId", "value": "" }],
"variable":
[
{
Expand Down Expand Up @@ -298,7 +304,7 @@ import TabItem from "@theme/TabItem";

Delete a service user permanently and all of its relations (keys, organizations, roles, etc)

<details style={{"marginBottom":"1rem"}} data-collapsed={false} open={true}><summary style={{}}><strong>Path Parameters</strong></summary><div><ul><ParamsItem className={"paramsItem"} param={{"name":"id","description":"The unique ID of the service user to delete.","in":"path","required":true,"schema":{"type":"string"}}}></ParamsItem></ul></div></details><div><ApiTabs><TabItem label={"200"} value={"200"}><div>
<details style={{"marginBottom":"1rem"}} data-collapsed={false} open={true}><summary style={{}}><strong>Path Parameters</strong></summary><div><ul><ParamsItem className={"paramsItem"} param={{"name":"id","description":"The unique ID of the service user to delete.","in":"path","required":true,"schema":{"type":"string"}}}></ParamsItem></ul></div></details><details style={{"marginBottom":"1rem"}} data-collapsed={false} open={true}><summary style={{}}><strong>Query Parameters</strong></summary><div><ul><ParamsItem className={"paramsItem"} param={{"name":"orgId","in":"query","required":false,"schema":{"type":"string"}}}></ParamsItem></ul></div></details><div><ApiTabs><TabItem label={"200"} value={"200"}><div>

A successful response.

Expand Down
Loading

0 comments on commit f8d5046

Please sign in to comment.