Skip to content

Commit

Permalink
feat: update workspace profile
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Jun 3, 2024
1 parent 15ca4fe commit d51d180
Show file tree
Hide file tree
Showing 17 changed files with 331 additions and 281 deletions.
5 changes: 0 additions & 5 deletions proto/api/v1/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ option go_package = "gen/api/v1";

enum RowStatus {
ROW_STATUS_UNSPECIFIED = 0;

NORMAL = 1;

ARCHIVED = 2;
}

enum Visibility {
VISIBILITY_UNSPECIFIED = 0;

PRIVATE = 1;

WORKSPACE = 2;

PUBLIC = 3;
}
2 changes: 0 additions & 2 deletions proto/api/v1/subscription_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ message Subscription {

enum PlanType {
PLAN_TYPE_UNSPECIFIED = 0;

FREE = 1;

PRO = 2;
}

Expand Down
3 changes: 3 additions & 0 deletions proto/api/v1/workspace_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ message WorkspaceProfile {
string custom_script = 6;
// The url of custom favicon provider.
string favicon_provider = 7;
// The owner name.
// Format: "users/{id}"
string owner = 8;
}

message WorkspaceSetting {
Expand Down
1 change: 1 addition & 0 deletions proto/gen/api/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@
| custom_style | [string](#string) | | The custom style. |
| custom_script | [string](#string) | | The custom script. |
| favicon_provider | [string](#string) | | The url of custom favicon provider. |
| owner | [string](#string) | | The owner name. Format: "users/{id}" |



Expand Down
219 changes: 115 additions & 104 deletions proto/gen/api/v1/workspace_service.pb.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions proto/gen/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1169,3 +1169,8 @@ definitions:
faviconProvider:
type: string
description: The url of custom favicon provider.
owner:
type: string
title: |-
The owner name.
Format: "users/{id}"
18 changes: 9 additions & 9 deletions server/route/api/v1/auth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ import (
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"

apiv1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
storepb "github.com/yourselfhosted/slash/proto/gen/store"
"github.com/yourselfhosted/slash/server/metric"
"github.com/yourselfhosted/slash/server/service/license"
"github.com/yourselfhosted/slash/store"
)

func (s *APIV1Service) GetAuthStatus(ctx context.Context, _ *apiv1pb.GetAuthStatusRequest) (*apiv1pb.GetAuthStatusResponse, error) {
func (s *APIV1Service) GetAuthStatus(ctx context.Context, _ *v1pb.GetAuthStatusRequest) (*v1pb.GetAuthStatusResponse, error) {
user, err := getCurrentUser(ctx, s.Store)
if err != nil {
return nil, status.Errorf(codes.Unauthenticated, "failed to get current user: %v", err)
}
if user == nil {
return nil, status.Errorf(codes.Unauthenticated, "user not found")
}
return &apiv1pb.GetAuthStatusResponse{
return &v1pb.GetAuthStatusResponse{
User: convertUserFromStore(user),
}, nil
}

func (s *APIV1Service) SignIn(ctx context.Context, request *apiv1pb.SignInRequest) (*apiv1pb.SignInResponse, error) {
func (s *APIV1Service) SignIn(ctx context.Context, request *v1pb.SignInRequest) (*v1pb.SignInResponse, error) {
user, err := s.Store.GetUser(ctx, &store.FindUser{
Email: &request.Email,
})
Expand Down Expand Up @@ -64,12 +64,12 @@ func (s *APIV1Service) SignIn(ctx context.Context, request *apiv1pb.SignInReques
}

metric.Enqueue("user sign in")
return &apiv1pb.SignInResponse{
return &v1pb.SignInResponse{
User: convertUserFromStore(user),
}, nil
}

func (s *APIV1Service) SignUp(ctx context.Context, request *apiv1pb.SignUpRequest) (*apiv1pb.SignUpResponse, error) {
func (s *APIV1Service) SignUp(ctx context.Context, request *v1pb.SignUpRequest) (*v1pb.SignUpResponse, error) {
enableSignUpSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Key: storepb.WorkspaceSettingKey_WORKSAPCE_SETTING_ENABLE_SIGNUP,
})
Expand Down Expand Up @@ -131,18 +131,18 @@ func (s *APIV1Service) SignUp(ctx context.Context, request *apiv1pb.SignUpReques
}

metric.Enqueue("user sign up")
return &apiv1pb.SignUpResponse{
return &v1pb.SignUpResponse{
User: convertUserFromStore(user),
}, nil
}

func (*APIV1Service) SignOut(ctx context.Context, _ *apiv1pb.SignOutRequest) (*apiv1pb.SignOutResponse, error) {
func (*APIV1Service) SignOut(ctx context.Context, _ *v1pb.SignOutRequest) (*v1pb.SignOutResponse, error) {
// Set the cookie header to expire access token.
if err := grpc.SetHeader(ctx, metadata.New(map[string]string{
"Set-Cookie": fmt.Sprintf("%s=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; SameSite=Strict", AccessTokenCookieName),
})); err != nil {
return nil, status.Errorf(codes.Internal, "failed to set grpc header, error: %v", err)
}

return &apiv1pb.SignOutResponse{}, nil
return &v1pb.SignOutResponse{}, nil
}
34 changes: 17 additions & 17 deletions server/route/api/v1/collection_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"

apiv1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
storepb "github.com/yourselfhosted/slash/proto/gen/store"
"github.com/yourselfhosted/slash/server/metric"
"github.com/yourselfhosted/slash/server/service/license"
"github.com/yourselfhosted/slash/store"
)

func (s *APIV1Service) ListCollections(ctx context.Context, _ *apiv1pb.ListCollectionsRequest) (*apiv1pb.ListCollectionsResponse, error) {
func (s *APIV1Service) ListCollections(ctx context.Context, _ *v1pb.ListCollectionsRequest) (*v1pb.ListCollectionsResponse, error) {
user, err := getCurrentUser(ctx, s.Store)
if err != nil {
return nil, status.Errorf(codes.Unauthenticated, "failed to get current user: %v", err)
Expand All @@ -41,18 +41,18 @@ func (s *APIV1Service) ListCollections(ctx context.Context, _ *apiv1pb.ListColle
}
collections = append(collections, sharedCollections...)

convertedCollections := []*apiv1pb.Collection{}
convertedCollections := []*v1pb.Collection{}
for _, collection := range collections {
convertedCollections = append(convertedCollections, convertCollectionFromStore(collection))
}

response := &apiv1pb.ListCollectionsResponse{
response := &v1pb.ListCollectionsResponse{
Collections: convertedCollections,
}
return response, nil
}

func (s *APIV1Service) GetCollection(ctx context.Context, request *apiv1pb.GetCollectionRequest) (*apiv1pb.GetCollectionResponse, error) {
func (s *APIV1Service) GetCollection(ctx context.Context, request *v1pb.GetCollectionRequest) (*v1pb.GetCollectionResponse, error) {
collection, err := s.Store.GetCollection(ctx, &store.FindCollection{
ID: &request.Id,
})
Expand All @@ -70,13 +70,13 @@ func (s *APIV1Service) GetCollection(ctx context.Context, request *apiv1pb.GetCo
if collection.Visibility == storepb.Visibility_PRIVATE && collection.CreatorId != user.ID {
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
}
response := &apiv1pb.GetCollectionResponse{
response := &v1pb.GetCollectionResponse{
Collection: convertCollectionFromStore(collection),
}
return response, nil
}

func (s *APIV1Service) GetCollectionByName(ctx context.Context, request *apiv1pb.GetCollectionByNameRequest) (*apiv1pb.GetCollectionByNameResponse, error) {
func (s *APIV1Service) GetCollectionByName(ctx context.Context, request *v1pb.GetCollectionByNameRequest) (*v1pb.GetCollectionByNameResponse, error) {
collection, err := s.Store.GetCollection(ctx, &store.FindCollection{
Name: &request.Name,
})
Expand All @@ -97,13 +97,13 @@ func (s *APIV1Service) GetCollectionByName(ctx context.Context, request *apiv1pb
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
}
}
response := &apiv1pb.GetCollectionByNameResponse{
response := &v1pb.GetCollectionByNameResponse{
Collection: convertCollectionFromStore(collection),
}
return response, nil
}

func (s *APIV1Service) CreateCollection(ctx context.Context, request *apiv1pb.CreateCollectionRequest) (*apiv1pb.CreateCollectionResponse, error) {
func (s *APIV1Service) CreateCollection(ctx context.Context, request *v1pb.CreateCollectionRequest) (*v1pb.CreateCollectionResponse, error) {
if request.Collection.Name == "" || request.Collection.Title == "" {
return nil, status.Errorf(codes.InvalidArgument, "name and title are required")
}
Expand Down Expand Up @@ -137,14 +137,14 @@ func (s *APIV1Service) CreateCollection(ctx context.Context, request *apiv1pb.Cr
return nil, status.Errorf(codes.Internal, "failed to create collection, err: %v", err)
}

response := &apiv1pb.CreateCollectionResponse{
response := &v1pb.CreateCollectionResponse{
Collection: convertCollectionFromStore(collection),
}
metric.Enqueue("collection create")
return response, nil
}

func (s *APIV1Service) UpdateCollection(ctx context.Context, request *apiv1pb.UpdateCollectionRequest) (*apiv1pb.UpdateCollectionResponse, error) {
func (s *APIV1Service) UpdateCollection(ctx context.Context, request *v1pb.UpdateCollectionRequest) (*v1pb.UpdateCollectionResponse, error) {
if request.UpdateMask == nil || len(request.UpdateMask.Paths) == 0 {
return nil, status.Errorf(codes.InvalidArgument, "updateMask is required")
}
Expand Down Expand Up @@ -189,13 +189,13 @@ func (s *APIV1Service) UpdateCollection(ctx context.Context, request *apiv1pb.Up
return nil, status.Errorf(codes.Internal, "failed to update collection, err: %v", err)
}

response := &apiv1pb.UpdateCollectionResponse{
response := &v1pb.UpdateCollectionResponse{
Collection: convertCollectionFromStore(collection),
}
return response, nil
}

func (s *APIV1Service) DeleteCollection(ctx context.Context, request *apiv1pb.DeleteCollectionRequest) (*apiv1pb.DeleteCollectionResponse, error) {
func (s *APIV1Service) DeleteCollection(ctx context.Context, request *v1pb.DeleteCollectionRequest) (*v1pb.DeleteCollectionResponse, error) {
user, err := getCurrentUser(ctx, s.Store)
if err != nil {
return nil, status.Errorf(codes.Unauthenticated, "failed to get current user: %v", err)
Expand All @@ -219,12 +219,12 @@ func (s *APIV1Service) DeleteCollection(ctx context.Context, request *apiv1pb.De
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete collection, err: %v", err)
}
response := &apiv1pb.DeleteCollectionResponse{}
response := &v1pb.DeleteCollectionResponse{}
return response, nil
}

func convertCollectionFromStore(collection *storepb.Collection) *apiv1pb.Collection {
return &apiv1pb.Collection{
func convertCollectionFromStore(collection *storepb.Collection) *v1pb.Collection {
return &v1pb.Collection{
Id: collection.Id,
CreatorId: collection.CreatorId,
CreatedTime: timestamppb.New(time.Unix(collection.CreatedTs, 0)),
Expand All @@ -233,6 +233,6 @@ func convertCollectionFromStore(collection *storepb.Collection) *apiv1pb.Collect
Title: collection.Title,
Description: collection.Description,
ShortcutIds: collection.ShortcutIds,
Visibility: apiv1pb.Visibility(collection.Visibility),
Visibility: v1pb.Visibility(collection.Visibility),
}
}
10 changes: 5 additions & 5 deletions server/route/api/v1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package v1
import (
"context"

apiv1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
"github.com/yourselfhosted/slash/store"
)

func convertRowStatusFromStore(rowStatus store.RowStatus) apiv1pb.RowStatus {
func convertRowStatusFromStore(rowStatus store.RowStatus) v1pb.RowStatus {
switch rowStatus {
case store.Normal:
return apiv1pb.RowStatus_NORMAL
return v1pb.RowStatus_NORMAL
case store.Archived:
return apiv1pb.RowStatus_ARCHIVED
return v1pb.RowStatus_ARCHIVED
default:
return apiv1pb.RowStatus_ROW_STATUS_UNSPECIFIED
return v1pb.RowStatus_ROW_STATUS_UNSPECIFIED
}
}

Expand Down
5 changes: 5 additions & 0 deletions server/route/api/v1/resource_name.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package v1

const (
UserNamePrefix = "users/"
)
Loading

0 comments on commit d51d180

Please sign in to comment.