Add trust center files
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -1187,6 +1187,24 @@ enum TrustCenterReferenceOrderField
|
||||
)
|
||||
}
|
||||
|
||||
enum TrustCenterFileOrderField
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/coredata.TrustCenterFileOrderField"
|
||||
) {
|
||||
NAME
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.TrustCenterFileOrderFieldName"
|
||||
)
|
||||
CREATED_AT
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.TrustCenterFileOrderFieldCreatedAt"
|
||||
)
|
||||
UPDATED_AT
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.TrustCenterFileOrderFieldUpdatedAt"
|
||||
)
|
||||
}
|
||||
|
||||
enum SnapshotsType
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.SnapshotsType") {
|
||||
RISKS
|
||||
@@ -1422,6 +1440,14 @@ input TrustCenterReferenceOrder
|
||||
field: TrustCenterReferenceOrderField!
|
||||
}
|
||||
|
||||
input TrustCenterFileOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.TrustCenterFileOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: TrustCenterFileOrderField!
|
||||
}
|
||||
|
||||
input EvidenceOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.EvidenceOrderBy"
|
||||
@@ -1749,6 +1775,14 @@ type Organization implements Node {
|
||||
orderBy: SnapshotOrder
|
||||
): SnapshotConnection! @goField(forceResolver: true)
|
||||
|
||||
trustCenterFiles(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: TrustCenterFileOrder
|
||||
): TrustCenterFileConnection! @goField(forceResolver: true)
|
||||
|
||||
trustCenter: TrustCenter @goField(forceResolver: true)
|
||||
|
||||
customDomain: CustomDomain @goField(forceResolver: true)
|
||||
@@ -2391,6 +2425,7 @@ type TrustCenterDocumentAccess implements Node {
|
||||
trustCenterAccess: TrustCenterAccess! @goField(forceResolver: true)
|
||||
document: Document @goField(forceResolver: true)
|
||||
report: Report @goField(forceResolver: true)
|
||||
trustCenterFile: TrustCenterFile @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
type TrustCenterDocumentAccessConnection
|
||||
@@ -2441,6 +2476,31 @@ type TrustCenterReferenceEdge {
|
||||
node: TrustCenterReference!
|
||||
}
|
||||
|
||||
type TrustCenterFile implements Node {
|
||||
id: ID!
|
||||
name: String!
|
||||
category: String!
|
||||
fileUrl: String! @goField(forceResolver: true)
|
||||
trustCenterVisibility: TrustCenterVisibility!
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
organization: Organization! @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
type TrustCenterFileConnection
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.TrustCenterFileConnection"
|
||||
) {
|
||||
totalCount: Int! @goField(forceResolver: true)
|
||||
edges: [TrustCenterFileEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type TrustCenterFileEdge {
|
||||
cursor: CursorKey!
|
||||
node: TrustCenterFile!
|
||||
}
|
||||
|
||||
type UserConnection
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.UserConnection"
|
||||
@@ -2824,6 +2884,23 @@ type Mutation {
|
||||
input: DeleteTrustCenterReferenceInput!
|
||||
): DeleteTrustCenterReferencePayload!
|
||||
|
||||
# Trust Center File mutations
|
||||
createTrustCenterFile(
|
||||
input: CreateTrustCenterFileInput!
|
||||
): CreateTrustCenterFilePayload!
|
||||
|
||||
updateTrustCenterFile(
|
||||
input: UpdateTrustCenterFileInput!
|
||||
): UpdateTrustCenterFilePayload!
|
||||
|
||||
getTrustCenterFile(
|
||||
input: GetTrustCenterFileInput!
|
||||
): GetTrustCenterFilePayload!
|
||||
|
||||
deleteTrustCenterFile(
|
||||
input: DeleteTrustCenterFileInput!
|
||||
): DeleteTrustCenterFilePayload!
|
||||
|
||||
# User mutations
|
||||
confirmEmail(input: ConfirmEmailInput!): ConfirmEmailPayload!
|
||||
inviteUser(input: InviteUserInput!): InviteUserPayload!
|
||||
@@ -3151,6 +3228,7 @@ input UpdateTrustCenterAccessInput {
|
||||
active: Boolean
|
||||
documentIds: [ID!]
|
||||
reportIds: [ID!]
|
||||
trustCenterFileIds: [ID!]
|
||||
}
|
||||
|
||||
input DeleteTrustCenterAccessInput {
|
||||
@@ -3177,6 +3255,29 @@ input DeleteTrustCenterReferenceInput {
|
||||
id: ID!
|
||||
}
|
||||
|
||||
input CreateTrustCenterFileInput {
|
||||
organizationId: ID!
|
||||
name: String!
|
||||
category: String!
|
||||
file: Upload!
|
||||
trustCenterVisibility: TrustCenterVisibility!
|
||||
}
|
||||
|
||||
input UpdateTrustCenterFileInput {
|
||||
id: ID!
|
||||
name: String
|
||||
category: String
|
||||
trustCenterVisibility: TrustCenterVisibility
|
||||
}
|
||||
|
||||
input GetTrustCenterFileInput {
|
||||
id: ID!
|
||||
}
|
||||
|
||||
input DeleteTrustCenterFileInput {
|
||||
id: ID!
|
||||
}
|
||||
|
||||
input CreateVendorInput {
|
||||
organizationId: ID!
|
||||
name: String!
|
||||
@@ -3854,6 +3955,22 @@ type DeleteTrustCenterReferencePayload {
|
||||
deletedTrustCenterReferenceId: ID!
|
||||
}
|
||||
|
||||
type CreateTrustCenterFilePayload {
|
||||
trustCenterFileEdge: TrustCenterFileEdge!
|
||||
}
|
||||
|
||||
type UpdateTrustCenterFilePayload {
|
||||
trustCenterFile: TrustCenterFile!
|
||||
}
|
||||
|
||||
type GetTrustCenterFilePayload {
|
||||
trustCenterFile: TrustCenterFile!
|
||||
}
|
||||
|
||||
type DeleteTrustCenterFilePayload {
|
||||
deletedTrustCenterFileId: ID!
|
||||
}
|
||||
|
||||
type CreateControlPayload {
|
||||
controlEdge: ControlEdge!
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
65
pkg/server/api/console/v1/types/trust_center_file.go
Normal file
65
pkg/server/api/console/v1/types/trust_center_file.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/getprobo/probo/pkg/coredata"
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
type TrustCenterFileOrderBy = OrderBy[coredata.TrustCenterFileOrderField]
|
||||
|
||||
type TrustCenterFileConnection struct {
|
||||
TotalCount int `json:"totalCount"`
|
||||
Edges []*TrustCenterFileEdge `json:"edges"`
|
||||
PageInfo *PageInfo `json:"pageInfo"`
|
||||
ParentID gid.GID `json:"-"`
|
||||
}
|
||||
|
||||
func NewTrustCenterFile(tcf *coredata.TrustCenterFile) *TrustCenterFile {
|
||||
return &TrustCenterFile{
|
||||
ID: tcf.ID,
|
||||
Name: tcf.Name,
|
||||
Category: tcf.Category,
|
||||
TrustCenterVisibility: tcf.TrustCenterVisibility,
|
||||
CreatedAt: tcf.CreatedAt,
|
||||
UpdatedAt: tcf.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func NewTrustCenterFileConnection(
|
||||
p *page.Page[*coredata.TrustCenterFile, coredata.TrustCenterFileOrderField],
|
||||
parentID gid.GID,
|
||||
) *TrustCenterFileConnection {
|
||||
var edges = make([]*TrustCenterFileEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
edges[i] = NewTrustCenterFileEdge(p.Data[i], p.Cursor.OrderBy.Field)
|
||||
}
|
||||
|
||||
return &TrustCenterFileConnection{
|
||||
Edges: edges,
|
||||
PageInfo: NewPageInfo(p),
|
||||
ParentID: parentID,
|
||||
}
|
||||
}
|
||||
|
||||
func NewTrustCenterFileEdge(tcf *coredata.TrustCenterFile, orderBy coredata.TrustCenterFileOrderField) *TrustCenterFileEdge {
|
||||
return &TrustCenterFileEdge{
|
||||
Cursor: tcf.CursorKey(orderBy),
|
||||
Node: NewTrustCenterFile(tcf),
|
||||
}
|
||||
}
|
||||
@@ -541,6 +541,18 @@ type CreateTrustCenterAccessPayload struct {
|
||||
TrustCenterAccessEdge *TrustCenterAccessEdge `json:"trustCenterAccessEdge"`
|
||||
}
|
||||
|
||||
type CreateTrustCenterFileInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
Name string `json:"name"`
|
||||
Category string `json:"category"`
|
||||
File graphql.Upload `json:"file"`
|
||||
TrustCenterVisibility coredata.TrustCenterVisibility `json:"trustCenterVisibility"`
|
||||
}
|
||||
|
||||
type CreateTrustCenterFilePayload struct {
|
||||
TrustCenterFileEdge *TrustCenterFileEdge `json:"trustCenterFileEdge"`
|
||||
}
|
||||
|
||||
type CreateTrustCenterReferenceInput struct {
|
||||
TrustCenterID gid.GID `json:"trustCenterId"`
|
||||
Name string `json:"name"`
|
||||
@@ -916,6 +928,14 @@ type DeleteTrustCenterAccessPayload struct {
|
||||
DeletedTrustCenterAccessID gid.GID `json:"deletedTrustCenterAccessId"`
|
||||
}
|
||||
|
||||
type DeleteTrustCenterFileInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
}
|
||||
|
||||
type DeleteTrustCenterFilePayload struct {
|
||||
DeletedTrustCenterFileID gid.GID `json:"deletedTrustCenterFileId"`
|
||||
}
|
||||
|
||||
type DeleteTrustCenterNDAInput struct {
|
||||
TrustCenterID gid.GID `json:"trustCenterId"`
|
||||
}
|
||||
@@ -1170,6 +1190,14 @@ type GenerateFrameworkStateOfApplicabilityPayload struct {
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
type GetTrustCenterFileInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
}
|
||||
|
||||
type GetTrustCenterFilePayload struct {
|
||||
TrustCenterFile *TrustCenterFile `json:"trustCenterFile"`
|
||||
}
|
||||
|
||||
type ImportFrameworkInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
File graphql.Upload `json:"file"`
|
||||
@@ -1365,6 +1393,7 @@ type Organization struct {
|
||||
ContinualImprovements *ContinualImprovementConnection `json:"continualImprovements"`
|
||||
ProcessingActivities *ProcessingActivityConnection `json:"processingActivities"`
|
||||
Snapshots *SnapshotConnection `json:"snapshots"`
|
||||
TrustCenterFiles *TrustCenterFileConnection `json:"trustCenterFiles"`
|
||||
TrustCenter *TrustCenter `json:"trustCenter,omitempty"`
|
||||
CustomDomain *CustomDomain `json:"customDomain,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
@@ -1675,6 +1704,7 @@ type TrustCenterDocumentAccess struct {
|
||||
TrustCenterAccess *TrustCenterAccess `json:"trustCenterAccess"`
|
||||
Document *Document `json:"document,omitempty"`
|
||||
Report *Report `json:"report,omitempty"`
|
||||
TrustCenterFile *TrustCenterFile `json:"trustCenterFile,omitempty"`
|
||||
}
|
||||
|
||||
func (TrustCenterDocumentAccess) IsNode() {}
|
||||
@@ -1690,6 +1720,25 @@ type TrustCenterEdge struct {
|
||||
Node *TrustCenter `json:"node"`
|
||||
}
|
||||
|
||||
type TrustCenterFile struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Category string `json:"category"`
|
||||
FileURL string `json:"fileUrl"`
|
||||
TrustCenterVisibility coredata.TrustCenterVisibility `json:"trustCenterVisibility"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
Organization *Organization `json:"organization"`
|
||||
}
|
||||
|
||||
func (TrustCenterFile) IsNode() {}
|
||||
func (this TrustCenterFile) GetID() gid.GID { return this.ID }
|
||||
|
||||
type TrustCenterFileEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *TrustCenterFile `json:"node"`
|
||||
}
|
||||
|
||||
type TrustCenterReference struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -1948,17 +1997,29 @@ type UpdateTaskPayload struct {
|
||||
}
|
||||
|
||||
type UpdateTrustCenterAccessInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Active *bool `json:"active,omitempty"`
|
||||
DocumentIds []gid.GID `json:"documentIds,omitempty"`
|
||||
ReportIds []gid.GID `json:"reportIds,omitempty"`
|
||||
ID gid.GID `json:"id"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Active *bool `json:"active,omitempty"`
|
||||
DocumentIds []gid.GID `json:"documentIds,omitempty"`
|
||||
ReportIds []gid.GID `json:"reportIds,omitempty"`
|
||||
TrustCenterFileIds []gid.GID `json:"trustCenterFileIds,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateTrustCenterAccessPayload struct {
|
||||
TrustCenterAccess *TrustCenterAccess `json:"trustCenterAccess"`
|
||||
}
|
||||
|
||||
type UpdateTrustCenterFileInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Category *string `json:"category,omitempty"`
|
||||
TrustCenterVisibility *coredata.TrustCenterVisibility `json:"trustCenterVisibility,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateTrustCenterFilePayload struct {
|
||||
TrustCenterFile *TrustCenterFile `json:"trustCenterFile"`
|
||||
}
|
||||
|
||||
type UpdateTrustCenterInput struct {
|
||||
TrustCenterID gid.GID `json:"trustCenterId"`
|
||||
Active *bool `json:"active,omitempty"`
|
||||
|
||||
@@ -1288,11 +1288,12 @@ func (r *mutationResolver) UpdateTrustCenterAccess(ctx context.Context, input ty
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
|
||||
access, err := prb.TrustCenterAccesses.Update(ctx, &probo.UpdateTrustCenterAccessRequest{
|
||||
ID: input.ID,
|
||||
Name: input.Name,
|
||||
Active: input.Active,
|
||||
DocumentIDs: input.DocumentIds,
|
||||
ReportIDs: input.ReportIds,
|
||||
ID: input.ID,
|
||||
Name: input.Name,
|
||||
Active: input.Active,
|
||||
DocumentIDs: input.DocumentIds,
|
||||
ReportIDs: input.ReportIds,
|
||||
TrustCenterFileIDs: input.TrustCenterFileIds,
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot update trust center access: %w", err))
|
||||
@@ -1390,6 +1391,82 @@ func (r *mutationResolver) DeleteTrustCenterReference(ctx context.Context, input
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateTrustCenterFile is the resolver for the createTrustCenterFile field.
|
||||
func (r *mutationResolver) CreateTrustCenterFile(ctx context.Context, input types.CreateTrustCenterFileInput) (*types.CreateTrustCenterFilePayload, error) {
|
||||
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
||||
|
||||
file, err := prb.TrustCenterFiles.Create(ctx, &probo.CreateTrustCenterFileRequest{
|
||||
OrganizationID: input.OrganizationID,
|
||||
Name: input.Name,
|
||||
Category: input.Category,
|
||||
File: probo.File{
|
||||
Content: input.File.File,
|
||||
Filename: input.File.Filename,
|
||||
Size: input.File.Size,
|
||||
ContentType: input.File.ContentType,
|
||||
},
|
||||
TrustCenterVisibility: input.TrustCenterVisibility,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create trust center file: %w", err)
|
||||
}
|
||||
|
||||
return &types.CreateTrustCenterFilePayload{
|
||||
TrustCenterFileEdge: types.NewTrustCenterFileEdge(file, coredata.TrustCenterFileOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateTrustCenterFile is the resolver for the updateTrustCenterFile field.
|
||||
func (r *mutationResolver) UpdateTrustCenterFile(ctx context.Context, input types.UpdateTrustCenterFileInput) (*types.UpdateTrustCenterFilePayload, error) {
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
|
||||
file, err := prb.TrustCenterFiles.Update(ctx, &probo.UpdateTrustCenterFileRequest{
|
||||
ID: input.ID,
|
||||
Name: input.Name,
|
||||
Category: input.Category,
|
||||
TrustCenterVisibility: input.TrustCenterVisibility,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot update trust center file: %w", err)
|
||||
}
|
||||
|
||||
return &types.UpdateTrustCenterFilePayload{
|
||||
TrustCenterFile: types.NewTrustCenterFile(file),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetTrustCenterFile is the resolver for the getTrustCenterFile field.
|
||||
func (r *mutationResolver) GetTrustCenterFile(ctx context.Context, input types.GetTrustCenterFileInput) (*types.GetTrustCenterFilePayload, error) {
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
|
||||
file, err := prb.TrustCenterFiles.Get(ctx, &probo.GetTrustCenterFileRequest{
|
||||
ID: input.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get trust center file: %w", err)
|
||||
}
|
||||
|
||||
return &types.GetTrustCenterFilePayload{
|
||||
TrustCenterFile: types.NewTrustCenterFile(file),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeleteTrustCenterFile is the resolver for the deleteTrustCenterFile field.
|
||||
func (r *mutationResolver) DeleteTrustCenterFile(ctx context.Context, input types.DeleteTrustCenterFileInput) (*types.DeleteTrustCenterFilePayload, error) {
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
|
||||
err := prb.TrustCenterFiles.Delete(ctx, &probo.DeleteTrustCenterFileRequest{
|
||||
ID: input.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot delete trust center file: %w", err)
|
||||
}
|
||||
|
||||
return &types.DeleteTrustCenterFilePayload{
|
||||
DeletedTrustCenterFileID: input.ID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ConfirmEmail is the resolver for the confirmEmail field.
|
||||
func (r *mutationResolver) ConfirmEmail(ctx context.Context, input types.ConfirmEmailInput) (*types.ConfirmEmailPayload, error) {
|
||||
err := r.authSvc.ConfirmEmail(ctx, input.Token)
|
||||
@@ -4153,6 +4230,31 @@ func (r *organizationResolver) Snapshots(ctx context.Context, obj *types.Organiz
|
||||
return types.NewSnapshotConnection(page, r, obj.ID), nil
|
||||
}
|
||||
|
||||
// TrustCenterFiles is the resolver for the trustCenterFiles field.
|
||||
func (r *organizationResolver) TrustCenterFiles(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.OrderBy[coredata.TrustCenterFileOrderField]) (*types.TrustCenterFileConnection, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.TrustCenterFileOrderField]{
|
||||
Field: coredata.TrustCenterFileOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.TrustCenterFileOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
pageResult, err := prb.TrustCenterFiles.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list organization trust center files: %w", err))
|
||||
}
|
||||
|
||||
return types.NewTrustCenterFileConnection(pageResult, obj.ID), nil
|
||||
}
|
||||
|
||||
// TrustCenter is the resolver for the trustCenter field.
|
||||
func (r *organizationResolver) TrustCenter(ctx context.Context, obj *types.Organization) (*types.TrustCenter, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
@@ -4930,6 +5032,29 @@ func (r *trustCenterDocumentAccessResolver) Report(ctx context.Context, obj *typ
|
||||
return types.NewReport(report), nil
|
||||
}
|
||||
|
||||
// TrustCenterFile is the resolver for the trustCenterFile field.
|
||||
func (r *trustCenterDocumentAccessResolver) TrustCenterFile(ctx context.Context, obj *types.TrustCenterDocumentAccess) (*types.TrustCenterFile, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
documentAccess, err := prb.TrustCenterAccesses.GetDocumentAccess(ctx, obj.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot load trust center document access: %w", err)
|
||||
}
|
||||
|
||||
if documentAccess.TrustCenterFileID == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
trustCenterFile, err := prb.TrustCenterFiles.Get(ctx, &probo.GetTrustCenterFileRequest{
|
||||
ID: *documentAccess.TrustCenterFileID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot load trust center file: %w", err)
|
||||
}
|
||||
|
||||
return types.NewTrustCenterFile(trustCenterFile), nil
|
||||
}
|
||||
|
||||
// TotalCount is the resolver for the totalCount field.
|
||||
func (r *trustCenterDocumentAccessConnectionResolver) TotalCount(ctx context.Context, obj *types.TrustCenterDocumentAccessConnection) (int, error) {
|
||||
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
||||
@@ -4942,6 +5067,48 @@ func (r *trustCenterDocumentAccessConnectionResolver) TotalCount(ctx context.Con
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FileURL is the resolver for the fileUrl field.
|
||||
func (r *trustCenterFileResolver) FileURL(ctx context.Context, obj *types.TrustCenterFile) (string, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
fileURL, err := prb.TrustCenterFiles.GenerateFileURL(ctx, obj.ID, 1*time.Hour)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to generate file URL: %w", err))
|
||||
}
|
||||
|
||||
return fileURL, nil
|
||||
}
|
||||
|
||||
// Organization is the resolver for the organization field.
|
||||
func (r *trustCenterFileResolver) Organization(ctx context.Context, obj *types.TrustCenterFile) (*types.Organization, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
file, err := prb.TrustCenterFiles.Get(ctx, &probo.GetTrustCenterFileRequest{
|
||||
ID: obj.ID,
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get trust center file: %w", err))
|
||||
}
|
||||
|
||||
organization, err := prb.Organizations.Get(ctx, file.OrganizationID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get organization: %w", err))
|
||||
}
|
||||
|
||||
return types.NewOrganization(organization), nil
|
||||
}
|
||||
|
||||
// TotalCount is the resolver for the totalCount field.
|
||||
func (r *trustCenterFileConnectionResolver) TotalCount(ctx context.Context, obj *types.TrustCenterFileConnection) (int, error) {
|
||||
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
||||
|
||||
count, err := prb.TrustCenterFiles.CountForOrganizationID(ctx, obj.ParentID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot count trust center files: %w", err))
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// LogoURL is the resolver for the logoUrl field.
|
||||
func (r *trustCenterReferenceResolver) LogoURL(ctx context.Context, obj *types.TrustCenterReference) (string, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
@@ -5563,6 +5730,16 @@ func (r *Resolver) TrustCenterDocumentAccessConnection() schema.TrustCenterDocum
|
||||
return &trustCenterDocumentAccessConnectionResolver{r}
|
||||
}
|
||||
|
||||
// TrustCenterFile returns schema.TrustCenterFileResolver implementation.
|
||||
func (r *Resolver) TrustCenterFile() schema.TrustCenterFileResolver {
|
||||
return &trustCenterFileResolver{r}
|
||||
}
|
||||
|
||||
// TrustCenterFileConnection returns schema.TrustCenterFileConnectionResolver implementation.
|
||||
func (r *Resolver) TrustCenterFileConnection() schema.TrustCenterFileConnectionResolver {
|
||||
return &trustCenterFileConnectionResolver{r}
|
||||
}
|
||||
|
||||
// TrustCenterReference returns schema.TrustCenterReferenceResolver implementation.
|
||||
func (r *Resolver) TrustCenterReference() schema.TrustCenterReferenceResolver {
|
||||
return &trustCenterReferenceResolver{r}
|
||||
@@ -5658,6 +5835,8 @@ type trustCenterResolver struct{ *Resolver }
|
||||
type trustCenterAccessResolver struct{ *Resolver }
|
||||
type trustCenterDocumentAccessResolver struct{ *Resolver }
|
||||
type trustCenterDocumentAccessConnectionResolver struct{ *Resolver }
|
||||
type trustCenterFileResolver struct{ *Resolver }
|
||||
type trustCenterFileConnectionResolver struct{ *Resolver }
|
||||
type trustCenterReferenceResolver struct{ *Resolver }
|
||||
type trustCenterReferenceConnectionResolver struct{ *Resolver }
|
||||
type userConnectionResolver struct{ *Resolver }
|
||||
|
||||
@@ -476,6 +476,24 @@ type TrustCenterReferenceEdge {
|
||||
node: TrustCenterReference!
|
||||
}
|
||||
|
||||
type TrustCenterFile implements Node {
|
||||
id: ID!
|
||||
name: String!
|
||||
category: String!
|
||||
isUserAuthorized: Boolean! @goField(forceResolver: true)
|
||||
hasUserRequestedAccess: Boolean! @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
type TrustCenterFileConnection {
|
||||
edges: [TrustCenterFileEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type TrustCenterFileEdge {
|
||||
cursor: CursorKey!
|
||||
node: TrustCenterFile!
|
||||
}
|
||||
|
||||
type TrustCenter implements Node {
|
||||
id: ID!
|
||||
active: Boolean!
|
||||
@@ -513,6 +531,13 @@ type TrustCenter implements Node {
|
||||
last: Int
|
||||
before: CursorKey
|
||||
): TrustCenterReferenceConnection! @goField(forceResolver: true)
|
||||
|
||||
trustCenterFiles(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
): TrustCenterFileConnection! @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
type TrustCenterAccess implements Node {
|
||||
@@ -559,6 +584,17 @@ input RequestReportAccessInput {
|
||||
name: String
|
||||
}
|
||||
|
||||
input RequestTrustCenterFileAccessInput {
|
||||
trustCenterId: ID!
|
||||
trustCenterFileId: ID!
|
||||
email: String
|
||||
name: String
|
||||
}
|
||||
|
||||
input ExportTrustCenterFileInput {
|
||||
trustCenterFileId: ID!
|
||||
}
|
||||
|
||||
type ExportDocumentPDFPayload {
|
||||
data: String!
|
||||
}
|
||||
@@ -567,6 +603,10 @@ type ExportReportPDFPayload {
|
||||
data: String!
|
||||
}
|
||||
|
||||
type ExportTrustCenterFilePayload {
|
||||
data: String!
|
||||
}
|
||||
|
||||
type AcceptNonDisclosureAgreementPayload {
|
||||
success: Boolean!
|
||||
}
|
||||
@@ -598,4 +638,12 @@ type Mutation {
|
||||
requestReportAccess(
|
||||
input: RequestReportAccessInput!
|
||||
): RequestAccessesPayload! @mustBeAuthenticated(role: NONE)
|
||||
|
||||
requestTrustCenterFileAccess(
|
||||
input: RequestTrustCenterFileAccessInput!
|
||||
): RequestAccessesPayload! @mustBeAuthenticated(role: NONE)
|
||||
|
||||
exportTrustCenterFile(
|
||||
input: ExportTrustCenterFileInput!
|
||||
): ExportTrustCenterFilePayload! @mustBeAuthenticated(role: NONE)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -148,6 +148,7 @@ func slackHandler(trustSvc *trust.Service, slackSigningSecret string, logger *lo
|
||||
|
||||
var documentIDs []gid.GID
|
||||
var reportIDs []gid.GID
|
||||
var fileIDs []gid.GID
|
||||
|
||||
switch action.ActionID {
|
||||
case "accept_all":
|
||||
@@ -157,9 +158,9 @@ func slackHandler(trustSvc *trust.Service, slackSigningSecret string, logger *lo
|
||||
return
|
||||
}
|
||||
|
||||
documentIDs, reportIDs, err = tenantSvc.SlackMessages.GetSlackMessageMetadataByID(ctx, currentMessageId)
|
||||
documentIDs, reportIDs, fileIDs, err = tenantSvc.SlackMessages.GetSlackMessageDocumentIDs(ctx, currentMessageId)
|
||||
if err != nil {
|
||||
logger.ErrorCtx(ctx, "cannot load slack message metadata by ID", log.Error(err))
|
||||
logger.ErrorCtx(ctx, "cannot load slack message document ids", log.Error(err))
|
||||
httpserver.RenderJSON(w, http.StatusInternalServerError, SlackInteractiveResponse{Success: false, Message: "internal server error"})
|
||||
return
|
||||
}
|
||||
@@ -180,6 +181,14 @@ func slackHandler(trustSvc *trust.Service, slackSigningSecret string, logger *lo
|
||||
}
|
||||
reportIDs = []gid.GID{repID}
|
||||
|
||||
case "accept_file":
|
||||
fileID, err := gid.ParseGID(action.Value)
|
||||
if err != nil {
|
||||
httpserver.RenderJSON(w, http.StatusBadRequest, SlackInteractiveResponse{Success: false, Message: "invalid file ID"})
|
||||
return
|
||||
}
|
||||
fileIDs = []gid.GID{fileID}
|
||||
|
||||
default:
|
||||
httpserver.RenderJSON(w, http.StatusBadRequest, SlackInteractiveResponse{Success: false, Message: fmt.Sprintf("unknown action: %s", action.ActionID)})
|
||||
return
|
||||
@@ -191,6 +200,7 @@ func slackHandler(trustSvc *trust.Service, slackSigningSecret string, logger *lo
|
||||
requesterEmail,
|
||||
documentIDs,
|
||||
reportIDs,
|
||||
fileIDs,
|
||||
); err != nil {
|
||||
logger.ErrorCtx(ctx, "failed to grant access", log.Error(err))
|
||||
httpserver.RenderJSON(w, http.StatusInternalServerError, SlackInteractiveResponse{Success: false, Message: "internal server error"})
|
||||
|
||||
49
pkg/server/api/trust/v1/types/trust_center_file.go
Normal file
49
pkg/server/api/trust/v1/types/trust_center_file.go
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/getprobo/probo/pkg/coredata"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewTrustCenterFileConnection(
|
||||
p *page.Page[*coredata.TrustCenterFile, coredata.TrustCenterFileOrderField],
|
||||
) *TrustCenterFileConnection {
|
||||
edges := make([]*TrustCenterFileEdge, len(p.Data))
|
||||
for i, trustCenterFile := range p.Data {
|
||||
edges[i] = NewTrustCenterFileEdge(trustCenterFile, p.Cursor.OrderBy.Field)
|
||||
}
|
||||
|
||||
return &TrustCenterFileConnection{
|
||||
Edges: edges,
|
||||
PageInfo: NewPageInfo(p),
|
||||
}
|
||||
}
|
||||
|
||||
func NewTrustCenterFile(f *coredata.TrustCenterFile) *TrustCenterFile {
|
||||
return &TrustCenterFile{
|
||||
ID: f.ID,
|
||||
Name: f.Name,
|
||||
Category: f.Category,
|
||||
}
|
||||
}
|
||||
|
||||
func NewTrustCenterFileEdge(f *coredata.TrustCenterFile, orderField coredata.TrustCenterFileOrderField) *TrustCenterFileEdge {
|
||||
return &TrustCenterFileEdge{
|
||||
Node: NewTrustCenterFile(f),
|
||||
Cursor: f.CursorKey(orderField),
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,14 @@ type ExportReportPDFPayload struct {
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
type ExportTrustCenterFileInput struct {
|
||||
TrustCenterFileID gid.GID `json:"trustCenterFileId"`
|
||||
}
|
||||
|
||||
type ExportTrustCenterFilePayload struct {
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
type Framework struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -151,6 +159,13 @@ type RequestReportAccessInput struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type RequestTrustCenterFileAccessInput struct {
|
||||
TrustCenterID gid.GID `json:"trustCenterId"`
|
||||
TrustCenterFileID gid.GID `json:"trustCenterFileId"`
|
||||
Email *string `json:"email,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type TrustCenter struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Active bool `json:"active"`
|
||||
@@ -164,6 +179,7 @@ type TrustCenter struct {
|
||||
Audits *AuditConnection `json:"audits"`
|
||||
Vendors *VendorConnection `json:"vendors"`
|
||||
References *TrustCenterReferenceConnection `json:"references"`
|
||||
TrustCenterFiles *TrustCenterFileConnection `json:"trustCenterFiles"`
|
||||
}
|
||||
|
||||
func (TrustCenter) IsNode() {}
|
||||
@@ -180,6 +196,27 @@ type TrustCenterAccess struct {
|
||||
func (TrustCenterAccess) IsNode() {}
|
||||
func (this TrustCenterAccess) GetID() gid.GID { return this.ID }
|
||||
|
||||
type TrustCenterFile struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Category string `json:"category"`
|
||||
IsUserAuthorized bool `json:"isUserAuthorized"`
|
||||
HasUserRequestedAccess bool `json:"hasUserRequestedAccess"`
|
||||
}
|
||||
|
||||
func (TrustCenterFile) IsNode() {}
|
||||
func (this TrustCenterFile) GetID() gid.GID { return this.ID }
|
||||
|
||||
type TrustCenterFileConnection struct {
|
||||
Edges []*TrustCenterFileEdge `json:"edges"`
|
||||
PageInfo *PageInfo `json:"pageInfo"`
|
||||
}
|
||||
|
||||
type TrustCenterFileEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *TrustCenterFile `json:"node"`
|
||||
}
|
||||
|
||||
type TrustCenterReference struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
||||
@@ -445,6 +445,138 @@ func (r *mutationResolver) RequestReportAccess(ctx context.Context, input types.
|
||||
}, nil
|
||||
}
|
||||
|
||||
// RequestTrustCenterFileAccess is the resolver for the requestTrustCenterFileAccess field.
|
||||
func (r *mutationResolver) RequestTrustCenterFileAccess(ctx context.Context, input types.RequestTrustCenterFileAccessInput) (*types.RequestAccessesPayload, error) {
|
||||
publicTrustService := r.PublicTrustService(ctx, input.TrustCenterID.TenantID())
|
||||
|
||||
trustCenterFile, err := publicTrustService.TrustCenterFiles.Get(ctx, input.TrustCenterFileID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot load trust center file: %w", err))
|
||||
}
|
||||
|
||||
if trustCenterFile.TrustCenterVisibility == coredata.TrustCenterVisibilityPublic {
|
||||
return nil, fmt.Errorf("trust center file is publicly available and does not require access request")
|
||||
}
|
||||
|
||||
userData := r.UserFromContext(ctx)
|
||||
if userData != nil {
|
||||
return nil, fmt.Errorf("session users cannot request trust center access")
|
||||
}
|
||||
|
||||
email := input.Email
|
||||
tokenData := TokenAccessFromContext(ctx)
|
||||
if tokenData != nil {
|
||||
if email != nil || input.Name != nil {
|
||||
return nil, fmt.Errorf("email and name are not allowed for authenticated users")
|
||||
}
|
||||
emailValue := tokenData.GetEmail()
|
||||
email = &emailValue
|
||||
}
|
||||
if email == nil {
|
||||
return nil, fmt.Errorf("email is required for unauthenticated users")
|
||||
}
|
||||
|
||||
access, err := publicTrustService.TrustCenterAccesses.Request(ctx, &trust.TrustCenterAccessRequest{
|
||||
TrustCenterID: input.TrustCenterID,
|
||||
Email: *email,
|
||||
Name: input.Name,
|
||||
DocumentIDs: []gid.GID{},
|
||||
ReportIDs: []gid.GID{},
|
||||
TrustCenterFileIDs: []gid.GID{input.TrustCenterFileID},
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot request trust center file access: %w", err))
|
||||
}
|
||||
|
||||
return &types.RequestAccessesPayload{
|
||||
TrustCenterAccess: &types.TrustCenterAccess{
|
||||
ID: access.ID,
|
||||
Email: access.Email,
|
||||
Name: access.Name,
|
||||
CreatedAt: access.CreatedAt,
|
||||
UpdatedAt: access.UpdatedAt,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ExportTrustCenterFile is the resolver for the exportTrustCenterFile field.
|
||||
func (r *mutationResolver) ExportTrustCenterFile(ctx context.Context, input types.ExportTrustCenterFileInput) (*types.ExportTrustCenterFilePayload, error) {
|
||||
publicTrustService := r.PublicTrustService(ctx, input.TrustCenterFileID.TenantID())
|
||||
|
||||
trustCenterFile, err := publicTrustService.TrustCenterFiles.Get(ctx, input.TrustCenterFileID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot load trust center file: %w", err))
|
||||
}
|
||||
|
||||
if trustCenterFile.TrustCenterVisibility == coredata.TrustCenterVisibilityPublic {
|
||||
fileData, err := publicTrustService.TrustCenterFiles.ExportFileWithoutWatermark(ctx, input.TrustCenterFileID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot export trust center file: %w", err))
|
||||
}
|
||||
|
||||
return &types.ExportTrustCenterFilePayload{
|
||||
Data: fmt.Sprintf("data:application/pdf;base64,%s", base64.StdEncoding.EncodeToString(fileData)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
privateTrustService, err := r.PrivateTrustService(ctx, input.TrustCenterFileID.TenantID())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot export trust center file: %w", err)
|
||||
}
|
||||
|
||||
tokenData := TokenAccessFromContext(ctx)
|
||||
if tokenData != nil {
|
||||
ndaExists := true
|
||||
hasAcceptedNDA := false
|
||||
|
||||
trustCenter, _, err := privateTrustService.TrustCenters.Get(ctx, tokenData.TrustCenterID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get trust center: %w", err))
|
||||
}
|
||||
if trustCenter.NonDisclosureAgreementFileID == nil {
|
||||
ndaExists = false
|
||||
}
|
||||
|
||||
if ndaExists {
|
||||
hasAcceptedNDA, err = privateTrustService.TrustCenterAccesses.HasAcceptedNonDisclosureAgreement(ctx, tokenData.TrustCenterID, tokenData.GetEmail())
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot check if user has accepted NDA: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
fileAccess, err := privateTrustService.TrustCenterAccesses.LoadTrustCenterFileAccess(ctx, tokenData.TrustCenterID, tokenData.GetEmail(), input.TrustCenterFileID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot check trust center file access: %w", err))
|
||||
}
|
||||
|
||||
if !fileAccess.Active {
|
||||
return nil, fmt.Errorf("access denied: no permission to access this file")
|
||||
}
|
||||
|
||||
if ndaExists && !hasAcceptedNDA {
|
||||
return nil, fmt.Errorf("user has not accepted NDA")
|
||||
}
|
||||
}
|
||||
|
||||
userData := UserFromContext(ctx)
|
||||
userEmail := ""
|
||||
if userData != nil {
|
||||
userEmail = userData.EmailAddress
|
||||
}
|
||||
if tokenData != nil {
|
||||
userEmail = tokenData.GetEmail()
|
||||
}
|
||||
|
||||
fileData, err := privateTrustService.TrustCenterFiles.ExportFile(ctx, input.TrustCenterFileID, userEmail)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot export trust center file: %w", err))
|
||||
}
|
||||
|
||||
return &types.ExportTrustCenterFilePayload{
|
||||
Data: fmt.Sprintf("data:application/pdf;base64,%s", base64.StdEncoding.EncodeToString(fileData)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// LogoURL is the resolver for the logoUrl field.
|
||||
func (r *organizationResolver) LogoURL(ctx context.Context, obj *types.Organization) (*string, error) {
|
||||
publicTrustService := r.PublicTrustService(ctx, obj.ID.TenantID())
|
||||
@@ -772,6 +904,84 @@ func (r *trustCenterResolver) References(ctx context.Context, obj *types.TrustCe
|
||||
return types.NewTrustCenterReferenceConnection(referencePage), nil
|
||||
}
|
||||
|
||||
// TrustCenterFiles is the resolver for the trustCenterFiles field.
|
||||
func (r *trustCenterResolver) TrustCenterFiles(ctx context.Context, obj *types.TrustCenter, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.TrustCenterFileConnection, error) {
|
||||
publicTrustService := r.PublicTrustService(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.TrustCenterFileOrderField]{
|
||||
Field: coredata.TrustCenterFileOrderFieldName,
|
||||
Direction: page.OrderDirectionAsc,
|
||||
}
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
trustCenterFilePage, err := publicTrustService.TrustCenterFiles.ListForOrganizationId(ctx, obj.Organization.ID, cursor)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list public trust center files: %w", err))
|
||||
}
|
||||
|
||||
return types.NewTrustCenterFileConnection(trustCenterFilePage), nil
|
||||
}
|
||||
|
||||
// IsUserAuthorized is the resolver for the isUserAuthorized field.
|
||||
func (r *trustCenterFileResolver) IsUserAuthorized(ctx context.Context, obj *types.TrustCenterFile) (bool, error) {
|
||||
publicTrustService := r.PublicTrustService(ctx, obj.ID.TenantID())
|
||||
|
||||
trustCenterFile, err := publicTrustService.TrustCenterFiles.Get(ctx, obj.ID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot load trust center file: %w", err))
|
||||
}
|
||||
|
||||
if trustCenterFile.TrustCenterVisibility == coredata.TrustCenterVisibilityPublic {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
privateTrustService, err := r.PrivateTrustService(ctx, obj.ID.TenantID())
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
userData := r.UserFromContext(ctx)
|
||||
if userData != nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
tokenData := TokenAccessFromContext(ctx)
|
||||
if tokenData != nil {
|
||||
fileAccess, err := privateTrustService.TrustCenterAccesses.LoadTrustCenterFileAccess(ctx, tokenData.TrustCenterID, tokenData.GetEmail(), obj.ID)
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return fileAccess.Active, nil
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("no user or token data found"))
|
||||
}
|
||||
|
||||
// HasUserRequestedAccess is the resolver for the hasUserRequestedAccess field.
|
||||
func (r *trustCenterFileResolver) HasUserRequestedAccess(ctx context.Context, obj *types.TrustCenterFile) (bool, error) {
|
||||
privateTrustService, err := r.PrivateTrustService(ctx, obj.ID.TenantID())
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
userData := r.UserFromContext(ctx)
|
||||
if userData != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
tokenData := TokenAccessFromContext(ctx)
|
||||
if tokenData != nil {
|
||||
_, err := privateTrustService.TrustCenterAccesses.LoadTrustCenterFileAccess(ctx, tokenData.TrustCenterID, tokenData.GetEmail(), obj.ID)
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// LogoURL is the resolver for the logoUrl field.
|
||||
func (r *trustCenterReferenceResolver) LogoURL(ctx context.Context, obj *types.TrustCenterReference) (string, error) {
|
||||
publicTrustService := r.PublicTrustService(ctx, obj.ID.TenantID())
|
||||
@@ -805,6 +1015,11 @@ func (r *Resolver) Report() schema.ReportResolver { return &reportResolver{r} }
|
||||
// TrustCenter returns schema.TrustCenterResolver implementation.
|
||||
func (r *Resolver) TrustCenter() schema.TrustCenterResolver { return &trustCenterResolver{r} }
|
||||
|
||||
// TrustCenterFile returns schema.TrustCenterFileResolver implementation.
|
||||
func (r *Resolver) TrustCenterFile() schema.TrustCenterFileResolver {
|
||||
return &trustCenterFileResolver{r}
|
||||
}
|
||||
|
||||
// TrustCenterReference returns schema.TrustCenterReferenceResolver implementation.
|
||||
func (r *Resolver) TrustCenterReference() schema.TrustCenterReferenceResolver {
|
||||
return &trustCenterReferenceResolver{r}
|
||||
@@ -817,4 +1032,5 @@ type organizationResolver struct{ *Resolver }
|
||||
type queryResolver struct{ *Resolver }
|
||||
type reportResolver struct{ *Resolver }
|
||||
type trustCenterResolver struct{ *Resolver }
|
||||
type trustCenterFileResolver struct{ *Resolver }
|
||||
type trustCenterReferenceResolver struct{ *Resolver }
|
||||
|
||||
Reference in New Issue
Block a user