From c0c1322c8916bfcdbe45f85645e381d5e46a4b8a Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 7 Sep 2020 16:40:30 +0200 Subject: [PATCH] Fix lint --- pkg/models/saved_filters.go | 55 ++++++++++++++++++++++++++---- pkg/models/saved_filters_rights.go | 5 +++ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/pkg/models/saved_filters.go b/pkg/models/saved_filters.go index 1d5653523..b2e232909 100644 --- a/pkg/models/saved_filters.go +++ b/pkg/models/saved_filters.go @@ -68,6 +68,17 @@ func getSavedFilterIDFromListID(listID int64) (filterID int64) { return } +// Create creates a new saved filter +// @Summary Creates a new saved filter +// @Description Creates a new saved filter +// @tags filter +// @Accept json +// @Produce json +// @Security JWTKeyAuth +// @Success 200 {object} models.SavedFilter "The Saved Filter" +// @Failure 403 {object} web.HTTPError "The user does not have access to that saved filter." +// @Failure 500 {object} models.Message "Internal error" +// @Router /filters [put] func (s *SavedFilter) Create(auth web.Auth) error { s.OwnerID = auth.GetID() _, err := x.Insert(s) @@ -79,6 +90,18 @@ func getSavedFilterSimpleByID(id int64) (s *SavedFilter, err error) { return } +// ReadOne returns one saved filter +// @Summary Gets one saved filter +// @Description Returns a saved filter by its ID. +// @tags filter +// @Accept json +// @Produce json +// @Security JWTKeyAuth +// @Param id path int true "Filter ID" +// @Success 200 {object} models.SavedFilter "The Saved Filter" +// @Failure 403 {object} web.HTTPError "The user does not have access to that saved filter." +// @Failure 500 {object} models.Message "Internal error" +// @Router /filters/{id} [get] func (s *SavedFilter) ReadOne() error { // s already contains almost the full saved filter from the rights check, we only need to add the user u, err := user.GetUserByID(s.OwnerID) @@ -86,17 +109,37 @@ func (s *SavedFilter) ReadOne() error { return err } -// ReadAll returns all tasks of a saved filter. -// Since saved filters are shown in a pseudo-namespace, we can use this function to get all tasks -func (s *SavedFilter) ReadAll(auth web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfTotalItems int64, err error) { - return -} - +// Update updates an existing filter +// @Summary Updates a saved filter +// @Description Updates a saved filter by its ID. +// @tags filter +// @Accept json +// @Produce json +// @Security JWTKeyAuth +// @Param id path int true "Filter ID" +// @Success 200 {object} models.SavedFilter "The Saved Filter" +// @Failure 403 {object} web.HTTPError "The user does not have access to that saved filter." +// @Failure 404 {object} web.HTTPError "The saved filter does not exist." +// @Failure 500 {object} models.Message "Internal error" +// @Router /filters/{id} [post] func (s *SavedFilter) Update() error { _, err := x.Where("id = ?", s.ID).Update(s) return err } +// Delete removes a saved filter +// @Summary Removes a saved filter +// @Description Removes a saved filter by its ID. +// @tags filter +// @Accept json +// @Produce json +// @Security JWTKeyAuth +// @Param id path int true "Filter ID" +// @Success 200 {object} models.SavedFilter "The Saved Filter" +// @Failure 403 {object} web.HTTPError "The user does not have access to that saved filter." +// @Failure 404 {object} web.HTTPError "The saved filter does not exist." +// @Failure 500 {object} models.Message "Internal error" +// @Router /filters/{id} [delete] func (s *SavedFilter) Delete() error { _, err := x.Where("id = ?", s.ID).Delete(s) return err diff --git a/pkg/models/saved_filters_rights.go b/pkg/models/saved_filters_rights.go index fe09b1c70..687fa38bb 100644 --- a/pkg/models/saved_filters_rights.go +++ b/pkg/models/saved_filters_rights.go @@ -18,19 +18,23 @@ package models import "code.vikunja.io/web" +// CanRead checks if a user has the right to read a saved filter func (s *SavedFilter) CanRead(auth web.Auth) (bool, int, error) { can, err := s.canDoFilter(auth) return can, int(RightAdmin), err } +// CanDelete checks if a user has the right to delete a saved filter func (s *SavedFilter) CanDelete(auth web.Auth) (bool, error) { return s.canDoFilter(auth) } +// CanUpdate checks if a user has the right to update a saved filter func (s *SavedFilter) CanUpdate(auth web.Auth) (bool, error) { return s.canDoFilter(auth) } +// CanCreate checks if a user has the right to update a saved filter func (s *SavedFilter) CanCreate(auth web.Auth) (bool, error) { if _, is := auth.(*LinkSharing); is { return false, nil @@ -39,6 +43,7 @@ func (s *SavedFilter) CanCreate(auth web.Auth) (bool, error) { return true, nil } +// Helper function to check saved filter rights sind they all have the same logic func (s *SavedFilter) canDoFilter(auth web.Auth) (can bool, err error) { // Link shares can't view or modify saved filters, therefore we can error out right away if _, is := auth.(*LinkSharing); is {