diff options
author | Luke Granger-Brown <git@lukegb.com> | 2020-06-18 02:52:33 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-06-27 22:56:10 +0200 |
commit | 4a28f25347addf05708cdff37ecace4139f01779 (patch) | |
tree | 145e5fd420f70b182d66a5824d76300b5307d509 /graphql/resolvers | |
parent | 23228101a2a38a139f6fc2cafc18e9f08d911089 (diff) | |
download | git-bug-4a28f25347addf05708cdff37ecace4139f01779.tar.gz |
Add support for read-only mode for web UI.
Fixes #402.
Diffstat (limited to 'graphql/resolvers')
-rw-r--r-- | graphql/resolvers/mutation.go | 24 | ||||
-rw-r--r-- | graphql/resolvers/repo.go | 8 | ||||
-rw-r--r-- | graphql/resolvers/root.go | 14 |
3 files changed, 40 insertions, 6 deletions
diff --git a/graphql/resolvers/mutation.go b/graphql/resolvers/mutation.go index 850645f4..80d6fb1a 100644 --- a/graphql/resolvers/mutation.go +++ b/graphql/resolvers/mutation.go @@ -7,8 +7,32 @@ import ( "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/graphql/graph" "github.com/MichaelMure/git-bug/graphql/models" + "github.com/vektah/gqlparser/gqlerror" ) +var _ graph.MutationResolver = &readonlyMutationResolver{} + +type readonlyMutationResolver struct{} + +func (readonlyMutationResolver) NewBug(_ context.Context, _ models.NewBugInput) (*models.NewBugPayload, error) { + return nil, gqlerror.Errorf("readonly mode") +} +func (readonlyMutationResolver) AddComment(_ context.Context, input models.AddCommentInput) (*models.AddCommentPayload, error) { + return nil, gqlerror.Errorf("readonly mode") +} +func (readonlyMutationResolver) ChangeLabels(_ context.Context, input *models.ChangeLabelInput) (*models.ChangeLabelPayload, error) { + return nil, gqlerror.Errorf("readonly mode") +} +func (readonlyMutationResolver) OpenBug(_ context.Context, input models.OpenBugInput) (*models.OpenBugPayload, error) { + return nil, gqlerror.Errorf("readonly mode") +} +func (readonlyMutationResolver) CloseBug(_ context.Context, input models.CloseBugInput) (*models.CloseBugPayload, error) { + return nil, gqlerror.Errorf("readonly mode") +} +func (readonlyMutationResolver) SetTitle(_ context.Context, input models.SetTitleInput) (*models.SetTitlePayload, error) { + return nil, gqlerror.Errorf("readonly mode") +} + var _ graph.MutationResolver = &mutationResolver{} type mutationResolver struct { diff --git a/graphql/resolvers/repo.go b/graphql/resolvers/repo.go index 639e8f90..e30b49f0 100644 --- a/graphql/resolvers/repo.go +++ b/graphql/resolvers/repo.go @@ -5,6 +5,7 @@ import ( "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/entity" + "github.com/MichaelMure/git-bug/graphql/config" "github.com/MichaelMure/git-bug/graphql/connections" "github.com/MichaelMure/git-bug/graphql/graph" "github.com/MichaelMure/git-bug/graphql/models" @@ -13,7 +14,7 @@ import ( var _ graph.RepositoryResolver = &repoResolver{} -type repoResolver struct{} +type repoResolver struct{ cfg config.Config } func (repoResolver) Name(_ context.Context, obj *models.Repository) (*string, error) { name := obj.Repo.Name() @@ -149,7 +150,10 @@ func (repoResolver) Identity(_ context.Context, obj *models.Repository, prefix s return models.NewLazyIdentity(obj.Repo, excerpt), nil } -func (repoResolver) UserIdentity(_ context.Context, obj *models.Repository) (models.IdentityWrapper, error) { +func (r repoResolver) UserIdentity(_ context.Context, obj *models.Repository) (models.IdentityWrapper, error) { + if r.cfg.ReadOnly { + return nil, nil + } excerpt, err := obj.Repo.GetUserIdentityExcerpt() if err != nil { return nil, err diff --git a/graphql/resolvers/root.go b/graphql/resolvers/root.go index 9973ff59..214bbae3 100644 --- a/graphql/resolvers/root.go +++ b/graphql/resolvers/root.go @@ -3,6 +3,7 @@ package resolvers import ( "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/graphql/config" "github.com/MichaelMure/git-bug/graphql/graph" ) @@ -10,11 +11,13 @@ var _ graph.ResolverRoot = &RootResolver{} type RootResolver struct { cache.MultiRepoCache + cfg config.Config } -func NewRootResolver() *RootResolver { +func NewRootResolver(cfg config.Config) *RootResolver { return &RootResolver{ MultiRepoCache: cache.NewMultiRepoCache(), + cfg: cfg, } } @@ -25,13 +28,16 @@ func (r RootResolver) Query() graph.QueryResolver { } func (r RootResolver) Mutation() graph.MutationResolver { + if r.cfg.ReadOnly { + return &readonlyMutationResolver{} + } return &mutationResolver{ cache: &r.MultiRepoCache, } } -func (RootResolver) Repository() graph.RepositoryResolver { - return &repoResolver{} +func (r RootResolver) Repository() graph.RepositoryResolver { + return &repoResolver{r.cfg} } func (RootResolver) Bug() graph.BugResolver { @@ -50,7 +56,7 @@ func (RootResolver) Label() graph.LabelResolver { return &labelResolver{} } -func (r RootResolver) Identity() graph.IdentityResolver { +func (RootResolver) Identity() graph.IdentityResolver { return &identityResolver{} } |