This commit is contained in:
kolaente 2020-04-18 23:12:50 +02:00
parent 06c2f0707d
commit 2da2837942
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 17 additions and 8 deletions

View File

@ -26,17 +26,20 @@ import (
// Bucket represents a kanban bucket // Bucket represents a kanban bucket
type Bucket struct { type Bucket struct {
// The unique, numeric id of this bucket. // The unique, numeric id of this bucket.
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"bucket"` ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"bucket"`
Title string `xorm:"text not null" valid:"runelength(1|)" minLength:"1" json:"title"` // The title of this bucket.
ListID int64 `xorm:"int(11) not null" json:"list_id"` Title string `xorm:"text not null" valid:"runelength(1|)" minLength:"1" json:"title"`
Tasks []*Task `xorm:"-" json:"tasks"` // The list this bucket belongs to.
ListID int64 `xorm:"int(11) not null" json:"list_id"`
// All tasks which belong to this bucket.
Tasks []*Task `xorm:"-" json:"tasks"`
// A timestamp when this task was created. You cannot change this value. // A timestamp when this bucket was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"` Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
// A timestamp when this task was last updated. You cannot change this value. // A timestamp when this bucket was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"` Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
// The user who initially created the task. // The user who initially created the bucket.
CreatedBy *user.User `xorm:"-" json:"created_by" valid:"-"` CreatedBy *user.User `xorm:"-" json:"created_by" valid:"-"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"` CreatedByID int64 `xorm:"int(11) not null" json:"-"`
@ -44,6 +47,7 @@ type Bucket struct {
web.CRUDable `xorm:"-" json:"-"` web.CRUDable `xorm:"-" json:"-"`
} }
// TableName returns the table name for this bucket.
func (b *Bucket) TableName() string { func (b *Bucket) TableName() string {
return "buckets" return "buckets"
} }

View File

@ -18,18 +18,23 @@ package models
import "code.vikunja.io/web" import "code.vikunja.io/web"
// CanCreate checks if a user can create a new bucket
func (b *Bucket) CanCreate(a web.Auth) (bool, error) { func (b *Bucket) CanCreate(a web.Auth) (bool, error) {
return b.canDoBucket(a) l := &List{ID: b.ListID}
return l.CanWrite(a)
} }
// CanUpdate checks if a user can update an existing bucket
func (b *Bucket) CanUpdate(a web.Auth) (bool, error) { func (b *Bucket) CanUpdate(a web.Auth) (bool, error) {
return b.canDoBucket(a) return b.canDoBucket(a)
} }
// CanDelete checks if a user can delete an existing bucket
func (b *Bucket) CanDelete(a web.Auth) (bool, error) { func (b *Bucket) CanDelete(a web.Auth) (bool, error) {
return b.canDoBucket(a) return b.canDoBucket(a)
} }
// canDoBucket checks if the bucket exists and if the user has the right to act on it
func (b *Bucket) canDoBucket(a web.Auth) (bool, error) { func (b *Bucket) canDoBucket(a web.Auth) (bool, error) {
bb, err := getBucketByID(b.ID) bb, err := getBucketByID(b.ID)
if err != nil { if err != nil {