Add basic struct and methods
This commit is contained in:
parent
3b2289c8fa
commit
d10e58b37c
|
@ -0,0 +1,68 @@
|
|||
// Vikunja is a to-do list application to facilitate your life.
|
||||
// Copyright 2018-2020 Vikunja and contributors. All rights reserved.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"code.vikunja.io/web"
|
||||
)
|
||||
|
||||
// ListDuplicate holds everything needed to duplicate a list
|
||||
type ListDuplicate struct {
|
||||
// The list id of the list to duplicate
|
||||
ListID int64 `json:"list_id"`
|
||||
// The target namespace
|
||||
NamespaceID int64 `json:"namespace_id"`
|
||||
|
||||
List *List `json:"-"`
|
||||
|
||||
web.Rights `json:"-"`
|
||||
web.CRUDable `json:"-"`
|
||||
}
|
||||
|
||||
// CanCreate checks if a user has the right to duplicate a list
|
||||
func (ld *ListDuplicate) CanCreate(a web.Auth) (canCreate bool, err error) {
|
||||
// List Exists + user has read access to list
|
||||
ld.List = &List{ID: ld.ListID}
|
||||
canRead, err := ld.List.CanRead(a)
|
||||
if err != nil || !canRead {
|
||||
return canRead, err
|
||||
}
|
||||
|
||||
// Namespace exists + user has write access to is (-> can create new lists)
|
||||
ld.List.NamespaceID = ld.NamespaceID
|
||||
return ld.List.CanCreate(a)
|
||||
}
|
||||
|
||||
// Create duplicates a list
|
||||
func (ld *ListDuplicate) Create(a web.Auth) (err error) {
|
||||
// Get the list
|
||||
|
||||
// Get all tasks + all task details
|
||||
// copy stuff
|
||||
// * List
|
||||
// * Tasks
|
||||
// * Files
|
||||
// * Label Tasks (not the labels)
|
||||
// * assignees
|
||||
// * attachments
|
||||
// * comments
|
||||
// * relations in that list
|
||||
// * reminders
|
||||
|
||||
// * rights / shares
|
||||
// * Generate new link shares if any are available
|
||||
}
|
|
@ -98,7 +98,7 @@ func (l *List) CanDelete(a web.Auth) (bool, error) {
|
|||
|
||||
// CanCreate checks if the user can create a list
|
||||
func (l *List) CanCreate(a web.Auth) (bool, error) {
|
||||
// A user can create a list if he has write access to the namespace
|
||||
// A user can create a list if they have write access to the namespace
|
||||
n := &Namespace{ID: l.NamespaceID}
|
||||
return n.CanWrite(a)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue