You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
package mutations
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
|
"git.aiterp.net/rpdata/api/internal/auth"
|
|
"git.aiterp.net/rpdata/api/model/change"
|
|
"git.aiterp.net/rpdata/api/model/story"
|
|
)
|
|
|
|
// StoryTagAddArgs is args for the addStoryTag mutation
|
|
type StoryTagAddArgs struct {
|
|
Input *struct {
|
|
ID string
|
|
Tag struct {
|
|
Kind string
|
|
Name string
|
|
}
|
|
}
|
|
}
|
|
|
|
// AddStoryTag resolves the addStoryTag mutation
|
|
func (r *MutationResolver) AddStoryTag(ctx context.Context, args *StoryTagAddArgs) (*types.StoryResolver, error) {
|
|
input := args.Input
|
|
tag := story.Tag{Kind: input.Tag.Kind, Name: input.Tag.Name}
|
|
|
|
token := auth.TokenFromContext(ctx)
|
|
if !token.Permitted("member", "story.edit") {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
|
|
story, err := story.FindID(input.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if story.Author != token.UserID && !token.Permitted("story.edit") {
|
|
return nil, ErrPermissionDenied
|
|
}
|
|
|
|
err = story.AddTag(tag)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
go change.Submit("Story", "add.tag", token.UserID, story.ID, map[string]interface{}{
|
|
"kind": tag.Kind,
|
|
"name": tag.Name,
|
|
})
|
|
|
|
return &types.StoryResolver{S: story}, nil
|
|
}
|