UI for file stuff.
the build was successful

This commit is contained in:
2019-09-15 16:34:16 +02:00
parent c8ced52e1a
commit 5dbed6d632
7 changed files with 73 additions and 16 deletions
+47 -8
View File
@@ -11,6 +11,7 @@ import (
"github.com/h2non/filetype"
"io"
"log"
"strings"
"time"
)
@@ -51,10 +52,12 @@ func (s *FileService) List(ctx context.Context, filter models.FileFilter) ([]*mo
if filter.Public != nil {
if *filter.Public == false {
if filter.Author == nil || *filter.Author == "" {
return nil, ErrPrivateNoAuthor
}
if token == nil {
return nil, ErrUnauthorized
}
if !token.PermittedUser(*filter.Author, "member", "file.list") {
filter.Author = &token.UserID
} else if !token.PermittedUser(*filter.Author, "member", "file.list") {
return nil, ErrUnauthorized
}
}
@@ -125,17 +128,53 @@ func (s *FileService) Edit(ctx context.Context, id string, name *string, public
err = s.authService.CheckPermission(ctx, "edit", file)
if err != nil {
if !file.Public {
return nil, repositories.ErrNotFound
}
return nil, err
}
return s.files.Update(ctx, *file, models.FileUpdate{
file, err = s.files.Update(ctx, *file, models.FileUpdate{
Name: name,
Public: public,
})
if err != nil {
return nil, err
}
s.changeService.Submit(ctx, models.ChangeModelFile, "edit", file.Public, changekeys.Listed(file), file)
return file, nil
}
func (s *FileService) Remove(ctx context.Context, id string) (*models.File, error) {
file, err := s.files.Find(ctx, id)
if err != nil {
return nil, err
}
err = s.authService.CheckPermission(ctx, "remove", file)
if err != nil {
return nil, err
}
if file.Kind == "upload" {
split := strings.Split(file.URL, "/")
name := split[len(split)-1]
if strings.HasPrefix(name, "U") {
err := s.space.RemoveFile(name)
if err != nil {
log.Printf("Failed to remove file %s for id %s: %s", name, id, err)
}
}
}
err = s.files.Delete(ctx, *file)
if err != nil {
return nil, err
}
s.changeService.Submit(ctx, models.ChangeModelFile, "remove", file.Public, changekeys.Listed(file), file)
return file, nil
}
// concatReader is a quick and dirty reader for reading the head and the file.
+2 -2
View File
@@ -395,9 +395,9 @@ func (s *StoryService) RemoveComment(ctx context.Context, comment *models.Commen
}
if story, err := s.stories.Find(ctx, chapter.StoryID); err == nil {
s.changeService.Submit(ctx, "Chapter", "remove", story.Listed, changekeys.Many(story, chapter, comment), comment)
s.changeService.Submit(ctx, "Comment", "remove", story.Listed, changekeys.Many(story, chapter, comment), comment)
} else {
s.changeService.Submit(ctx, "Chapter", "remove", false, changekeys.Many(models.Story{ID: chapter.StoryID}, chapter, comment), comment)
s.changeService.Submit(ctx, "Comment", "remove", false, changekeys.Many(models.Story{ID: chapter.StoryID}, chapter, comment), comment)
}
return nil