Add condition show tasks from the favorites list
This commit is contained in:
parent
d742d87b0a
commit
d0f2b216e0
|
@ -74,6 +74,12 @@ type ListBackgroundType struct {
|
||||||
// ListBackgroundUpload represents the list upload background type
|
// ListBackgroundUpload represents the list upload background type
|
||||||
const ListBackgroundUpload string = "upload"
|
const ListBackgroundUpload string = "upload"
|
||||||
|
|
||||||
|
// FavoriteListID is the id of the list which holds the favorites
|
||||||
|
const FavoriteListID int64 = -1
|
||||||
|
|
||||||
|
// FavoriteListNamespaceID is the id of the pseudo namespace containing the favorite list
|
||||||
|
const FavoriteListNamespaceID int64 = -2
|
||||||
|
|
||||||
// GetListsByNamespaceID gets all lists in a namespace
|
// GetListsByNamespaceID gets all lists in a namespace
|
||||||
func GetListsByNamespaceID(nID int64, doer *user.User) (lists []*List, err error) {
|
func GetListsByNamespaceID(nID int64, doer *user.User) (lists []*List, err error) {
|
||||||
if nID == -1 {
|
if nID == -1 {
|
||||||
|
@ -165,6 +171,12 @@ func (l *List) ReadAll(a web.Auth, search string, page int, perPage int) (result
|
||||||
// @Failure 500 {object} models.Message "Internal error"
|
// @Failure 500 {object} models.Message "Internal error"
|
||||||
// @Router /lists/{id} [get]
|
// @Router /lists/{id} [get]
|
||||||
func (l *List) ReadOne() (err error) {
|
func (l *List) ReadOne() (err error) {
|
||||||
|
|
||||||
|
if l.ID == FavoriteListID {
|
||||||
|
// Already "built" the list in CanRead
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Get list owner
|
// Get list owner
|
||||||
l.Owner, err = user.GetUserByID(l.OwnerID)
|
l.Owner, err = user.GetUserByID(l.OwnerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -25,6 +25,11 @@ import (
|
||||||
// CanWrite return whether the user can write on that list or not
|
// CanWrite return whether the user can write on that list or not
|
||||||
func (l *List) CanWrite(a web.Auth) (bool, error) {
|
func (l *List) CanWrite(a web.Auth) (bool, error) {
|
||||||
|
|
||||||
|
// The favorite list can't be edited
|
||||||
|
if l.ID == FavoriteListID {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Get the list and check the right
|
// Get the list and check the right
|
||||||
originalList := &List{ID: l.ID}
|
originalList := &List{ID: l.ID}
|
||||||
err := originalList.GetSimpleByID()
|
err := originalList.GetSimpleByID()
|
||||||
|
@ -63,6 +68,25 @@ func (l *List) CanWrite(a web.Auth) (bool, error) {
|
||||||
|
|
||||||
// CanRead checks if a user has read access to a list
|
// CanRead checks if a user has read access to a list
|
||||||
func (l *List) CanRead(a web.Auth) (bool, int, error) {
|
func (l *List) CanRead(a web.Auth) (bool, int, error) {
|
||||||
|
|
||||||
|
// The favorite list needs a special treatment
|
||||||
|
if l.ID == FavoriteListID {
|
||||||
|
owner, err := user.GetFromAuth(a)
|
||||||
|
if err != nil {
|
||||||
|
return false, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
*l = List{
|
||||||
|
ID: FavoriteListID,
|
||||||
|
Title: "Favorites",
|
||||||
|
Description: "This list has all tasks marked as favorites.",
|
||||||
|
OwnerID: a.GetID(),
|
||||||
|
Owner: owner,
|
||||||
|
NamespaceID: FavoriteListNamespaceID,
|
||||||
|
}
|
||||||
|
return true, int(RightRead), nil
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the user is either owner or can read
|
// Check if the user is either owner or can read
|
||||||
if err := l.GetSimpleByID(); err != nil {
|
if err := l.GetSimpleByID(); err != nil {
|
||||||
return false, 0, err
|
return false, 0, err
|
||||||
|
@ -83,6 +107,10 @@ func (l *List) CanRead(a web.Auth) (bool, int, error) {
|
||||||
|
|
||||||
// CanUpdate checks if the user can update a list
|
// CanUpdate checks if the user can update a list
|
||||||
func (l *List) CanUpdate(a web.Auth) (canUpdate bool, err error) {
|
func (l *List) CanUpdate(a web.Auth) (canUpdate bool, err error) {
|
||||||
|
// The favorite list can't be edited
|
||||||
|
if l.ID == FavoriteListID {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
canUpdate, err = l.CanWrite(a)
|
canUpdate, err = l.CanWrite(a)
|
||||||
// If the list is archived and the user tries to un-archive it, let the request through
|
// If the list is archived and the user tries to un-archive it, let the request through
|
||||||
if IsErrListIsArchived(err) && !l.IsArchived {
|
if IsErrListIsArchived(err) && !l.IsArchived {
|
||||||
|
@ -105,6 +133,11 @@ func (l *List) CanCreate(a web.Auth) (bool, error) {
|
||||||
|
|
||||||
// IsAdmin returns whether the user has admin rights on the list or not
|
// IsAdmin returns whether the user has admin rights on the list or not
|
||||||
func (l *List) IsAdmin(a web.Auth) (bool, error) {
|
func (l *List) IsAdmin(a web.Auth) (bool, error) {
|
||||||
|
// The favorite list can't be edited
|
||||||
|
if l.ID == FavoriteListID {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
originalList := &List{ID: l.ID}
|
originalList := &List{ID: l.ID}
|
||||||
err := originalList.GetSimpleByID()
|
err := originalList.GetSimpleByID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -182,7 +182,11 @@ func getRawTasksForLists(lists []*List, opts *taskOptions) (tasks []*Task, resul
|
||||||
|
|
||||||
// Get all list IDs and get the tasks
|
// Get all list IDs and get the tasks
|
||||||
var listIDs []int64
|
var listIDs []int64
|
||||||
|
var hasFavoriteLists bool
|
||||||
for _, l := range lists {
|
for _, l := range lists {
|
||||||
|
if l.ID == FavoriteListID {
|
||||||
|
hasFavoriteLists = true
|
||||||
|
}
|
||||||
listIDs = append(listIDs, l.ID)
|
listIDs = append(listIDs, l.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,11 +281,21 @@ func getRawTasksForLists(lists []*List, opts *taskOptions) (tasks []*Task, resul
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var listIDCond builder.Cond
|
||||||
|
var listCond builder.Cond
|
||||||
if len(listIDs) > 0 {
|
if len(listIDs) > 0 {
|
||||||
query = query.In("list_id", listIDs)
|
listIDCond = builder.In("list_id", listIDs)
|
||||||
queryCount = queryCount.In("list_id", listIDs)
|
listCond = listIDCond
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if hasFavoriteLists {
|
||||||
|
// TODO: Make sure users can only see their favorites
|
||||||
|
listCond = builder.Or(listIDCond, builder.Eq{"is_favorite": true})
|
||||||
|
}
|
||||||
|
|
||||||
|
query = query.Where(listCond)
|
||||||
|
queryCount = queryCount.Where(listCond)
|
||||||
|
|
||||||
if len(filters) > 0 {
|
if len(filters) > 0 {
|
||||||
if opts.filterConcat == filterConcatOr {
|
if opts.filterConcat == filterConcatOr {
|
||||||
query = query.Where(builder.Or(filters...))
|
query = query.Where(builder.Or(filters...))
|
||||||
|
|
Loading…
Reference in New Issue