Add method to get a saved filter from the lists endpoint
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
kolaente 2020-09-06 22:11:19 +02:00
parent 5988bc508f
commit 89258476eb
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 27 additions and 2 deletions

View File

@ -185,6 +185,19 @@ func (l *List) ReadOne() (err error) {
return nil
}
// Check for saved filters
if getSavedFilterIDFromListID(l.ID) > 0 {
sf, err := getSavedFilterSimpleByID(getSavedFilterIDFromListID(l.ID))
if err != nil {
return err
}
l.Title = sf.Title
l.Description = sf.Description
l.Created = sf.Created
l.Updated = sf.Updated
l.OwnerID = sf.OwnerID
}
// Get list owner
l.Owner, err = user.GetUserByID(l.OwnerID)
if err != nil {

View File

@ -81,6 +81,12 @@ func (l *List) CanRead(a web.Auth) (bool, int, error) {
return true, int(RightRead), nil
}
// Saved Filter Lists need a special case
if getSavedFilterIDFromListID(l.ID) > 0 {
sf := &SavedFilter{ID: getSavedFilterIDFromListID(l.ID)}
return sf.CanRead(a)
}
// Check if the user is either owner or can read
if err := l.GetSimpleByID(); err != nil {
return false, 0, err

View File

@ -57,9 +57,15 @@ func (s *SavedFilter) getTaskCollection() *TaskCollection {
return s.Filters
}
func getSavedFilterIDFromListID(listID int64) int64 {
// Returns the saved filter ID from a list ID. Will not check if the filter actually exists.
// If the returned ID is zero, means that it is probably invalid.
func getSavedFilterIDFromListID(listID int64) (filterID int64) {
// We get the id of the saved filter by multiplying the ListID with -1 and subtracting one
return listID*-1 - 1
filterID = listID*-1 - 1
if filterID > 0 {
filterID = 0
}
return
}
func (s *SavedFilter) Create(auth web.Auth) error {