graph2: Added change logging for story and chapter, fixed channel ops not being logged.
the build was successful
the build was successful
This commit is contained in:
@@ -5,6 +5,9 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models/changekeys"
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models/stories"
|
||||
|
||||
@@ -45,7 +48,14 @@ func (r *mutationResolver) AddChapter(ctx context.Context, input input.ChapterAd
|
||||
return models.Chapter{}, errors.New("Story is not open")
|
||||
}
|
||||
|
||||
return chapters.Add(story, input.Title, author, input.Source, time.Now(), input.FictionalDate)
|
||||
chapter, err := chapters.Add(story, input.Title, author, input.Source, time.Now(), input.FictionalDate)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Failed to create chapter: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Chapter", "add", token.UserID, story.Listed, changekeys.Listed(story, chapter), story, chapter)
|
||||
|
||||
return chapter, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) MoveChapter(ctx context.Context, input input.ChapterMoveInput) (models.Chapter, error) {
|
||||
@@ -68,7 +78,28 @@ func (r *mutationResolver) MoveChapter(ctx context.Context, input input.ChapterM
|
||||
return models.Chapter{}, errors.New("You are not permitted to move chapters to this story")
|
||||
}
|
||||
|
||||
return chapters.Move(chapter, target)
|
||||
oldStoryID := chapter.StoryID
|
||||
chapter, err = chapters.Move(chapter, target)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Failed to move chapter: " + err.Error())
|
||||
}
|
||||
|
||||
go func() {
|
||||
story, err := stories.FindID(chapter.StoryID)
|
||||
if err != nil {
|
||||
story.ID = chapter.StoryID
|
||||
}
|
||||
|
||||
oldStory, err := stories.FindID(oldStoryID)
|
||||
if err != nil {
|
||||
oldStory.ID = oldStoryID
|
||||
}
|
||||
|
||||
changes.Submit("Chapter", "move-out", chapter.Author, oldStory.Listed, changekeys.Many(oldStory, chapter), chapter)
|
||||
changes.Submit("Chapter", "move-in", token.UserID, story.Listed, changekeys.Listed(story, chapter), story, chapter)
|
||||
}()
|
||||
|
||||
return chapter, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) EditChapter(ctx context.Context, input input.ChapterEditInput) (models.Chapter, error) {
|
||||
@@ -86,7 +117,21 @@ func (r *mutationResolver) EditChapter(ctx context.Context, input input.ChapterE
|
||||
input.FictionalDate = &time.Time{}
|
||||
}
|
||||
|
||||
return chapters.Edit(chapter, input.Title, input.Source, input.FictionalDate)
|
||||
chapter, err = chapters.Edit(chapter, input.Title, input.Source, input.FictionalDate)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Failed to edit chapter: " + err.Error())
|
||||
}
|
||||
|
||||
go func() {
|
||||
story, err := stories.FindID(chapter.StoryID)
|
||||
if err != nil {
|
||||
story.ID = chapter.StoryID
|
||||
}
|
||||
|
||||
changes.Submit("Chapter", "edit", token.UserID, story.Listed, changekeys.Many(story, chapter), chapter)
|
||||
}()
|
||||
|
||||
return chapter, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemoveChapter(ctx context.Context, input input.ChapterRemoveInput) (models.Chapter, error) {
|
||||
@@ -100,5 +145,19 @@ func (r *mutationResolver) RemoveChapter(ctx context.Context, input input.Chapte
|
||||
return models.Chapter{}, errors.New("Unauthorized")
|
||||
}
|
||||
|
||||
return chapters.Remove(chapter)
|
||||
chapter, err = chapters.Remove(chapter)
|
||||
if err != nil {
|
||||
return models.Chapter{}, errors.New("Failed to remove chapter: " + err.Error())
|
||||
}
|
||||
|
||||
go func() {
|
||||
story, err := stories.FindID(chapter.StoryID)
|
||||
if err != nil {
|
||||
story.ID = chapter.StoryID
|
||||
}
|
||||
|
||||
changes.Submit("Chapter", "remove", token.UserID, story.Listed, changekeys.Many(story, chapter), chapter)
|
||||
}()
|
||||
|
||||
return chapter, nil
|
||||
}
|
||||
|
||||
+14
-1
@@ -5,6 +5,8 @@ import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models/channels"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/internal/loader"
|
||||
@@ -73,12 +75,23 @@ func (r *mutationResolver) AddLog(ctx context.Context, input input.LogAddInput)
|
||||
description = *input.Description
|
||||
}
|
||||
|
||||
existingChannel, _ := channels.FindName(input.Channel)
|
||||
|
||||
log, err := logs.Add(input.Date, input.Channel, title, event, description, open)
|
||||
if !token.Authenticated() || !token.Permitted("log.add") {
|
||||
return models.Log{}, errors.New("Failed to create log: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Log", "add", token.UserID, true, changekeys.Listed(log), log)
|
||||
go func() {
|
||||
if existingChannel.Name == "" {
|
||||
channel, err := channels.FindName(input.Channel)
|
||||
if err == nil {
|
||||
changes.Submit("Channel", "add", token.UserID, true, changekeys.Listed(channel), channel)
|
||||
}
|
||||
}
|
||||
|
||||
changes.Submit("Log", "add", token.UserID, true, changekeys.Listed(log), log)
|
||||
}()
|
||||
|
||||
return log, nil
|
||||
}
|
||||
|
||||
+37
-4
@@ -5,6 +5,9 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.aiterp.net/rpdata/api/models/changekeys"
|
||||
"git.aiterp.net/rpdata/api/models/changes"
|
||||
|
||||
"git.aiterp.net/rpdata/api/graph2/input"
|
||||
"git.aiterp.net/rpdata/api/internal/auth"
|
||||
"git.aiterp.net/rpdata/api/models"
|
||||
@@ -58,7 +61,14 @@ func (r *mutationResolver) AddStory(ctx context.Context, input input.StoryAddInp
|
||||
listed := input.Listed != nil && *input.Listed
|
||||
open := input.Open != nil && *input.Open
|
||||
|
||||
return stories.Add(input.Name, author, input.Category, listed, open, input.Tags, time.Now(), fictionalDate)
|
||||
story, err := stories.Add(input.Name, author, input.Category, listed, open, input.Tags, time.Now(), fictionalDate)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Failed to add story: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Story", "add", token.UserID, story.Listed, changekeys.Listed(story), story)
|
||||
|
||||
return story, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) AddStoryTag(ctx context.Context, input input.StoryTagAddInput) (models.Story, error) {
|
||||
@@ -73,7 +83,14 @@ func (r *mutationResolver) AddStoryTag(ctx context.Context, input input.StoryTag
|
||||
return models.Story{}, errors.New("You are not permitted to edit this story")
|
||||
}
|
||||
|
||||
return stories.AddTag(story, input.Tag)
|
||||
story, err = stories.AddTag(story, input.Tag)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Failed to add story: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Story", "tag", token.UserID, story.Listed, changekeys.Listed(story), story, input.Tag)
|
||||
|
||||
return story, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemoveStoryTag(ctx context.Context, input input.StoryTagRemoveInput) (models.Story, error) {
|
||||
@@ -88,7 +105,14 @@ func (r *mutationResolver) RemoveStoryTag(ctx context.Context, input input.Story
|
||||
return models.Story{}, errors.New("You are not permitted to edit this story")
|
||||
}
|
||||
|
||||
return stories.RemoveTag(story, input.Tag)
|
||||
story, err = stories.RemoveTag(story, input.Tag)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Failed to add story: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Story", "untag", token.UserID, story.Listed, changekeys.Listed(story), story, input.Tag)
|
||||
|
||||
return story, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) EditStory(ctx context.Context, input input.StoryEditInput) (models.Story, error) {
|
||||
@@ -107,7 +131,14 @@ func (r *mutationResolver) EditStory(ctx context.Context, input input.StoryEditI
|
||||
input.FictionalDate = &time.Time{}
|
||||
}
|
||||
|
||||
return stories.Edit(story, input.Name, input.Category, input.Listed, input.Open, input.FictionalDate)
|
||||
story, err = stories.Edit(story, input.Name, input.Category, input.Listed, input.Open, input.FictionalDate)
|
||||
if err != nil {
|
||||
return models.Story{}, errors.New("Failed to add story: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Story", "edit", token.UserID, story.Listed, changekeys.Listed(story), story)
|
||||
|
||||
return story, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) RemoveStory(ctx context.Context, input input.StoryRemoveInput) (models.Story, error) {
|
||||
@@ -132,5 +163,7 @@ func (r *mutationResolver) RemoveStory(ctx context.Context, input input.StoryRem
|
||||
return models.Story{}, errors.New("Failed to remove chapters, but story is removed: " + err.Error())
|
||||
}
|
||||
|
||||
go changes.Submit("Story", "remove", token.UserID, story.Listed, changekeys.Listed(story), story)
|
||||
|
||||
return story, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user