Added open and unlsited to StoriesFilter
the build was successful

This commit is contained in:
2018-08-01 14:27:28 +02:00
parent ca98648274
commit d5df624188
5 changed files with 40 additions and 2 deletions
+6
View File
@@ -9,3 +9,9 @@ type QueryResolver struct{}
// ErrCannotResolve is returned when a resolver constructor is at its wit's end
var ErrCannotResolve = errors.New("Cannot resolve due to invalid arguments")
// ErrUnauthorized is when a guest acts like they own the place
var ErrUnauthorized = errors.New("Unauthorized")
// ErrPermissionDenied is returned when users act above their station
var ErrPermissionDenied = errors.New("Permission denied")
+20 -1
View File
@@ -5,6 +5,7 @@ import (
"time"
"git.aiterp.net/rpdata/api/graphql/resolver/types"
"git.aiterp.net/rpdata/api/internal/session"
"git.aiterp.net/rpdata/api/model/story"
)
@@ -19,6 +20,8 @@ type StoriesArg struct {
EarliestFictionalDate *string
LatestFictionalDate *string
Limit *int32
Open *bool
Unlisted *bool
}
}
@@ -58,12 +61,28 @@ func (r *QueryResolver) Stories(ctx context.Context, args *StoriesArg) ([]*types
}
}
unlisted := filter.Unlisted != nil && *filter.Unlisted == true
if unlisted {
user := session.FromContext(ctx).User()
if user == nil {
return nil, ErrUnauthorized
}
if author != "" && author != user.ID && !user.Permitted("story.unlisted") {
return nil, ErrPermissionDenied
}
author = user.ID
}
open := filter.Open
limit := 30
if filter != nil && filter.Limit != nil {
limit = int(*filter.Limit)
}
stories, err := story.List(author, tags, earliest, latest, limit)
stories, err := story.List(author, tags, earliest, latest, unlisted, open, limit)
if err != nil {
return nil, err
}