implemented binding url params directly to struct instead of passing them to the method for deleting items
This commit is contained in:
@ -6,5 +6,5 @@ type CRUDable interface {
|
||||
ReadOne(int64) error
|
||||
ReadAll(*User) (interface{}, error)
|
||||
Update(int64) error
|
||||
Delete(int64) error
|
||||
Delete() error
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package models
|
||||
|
||||
// List represents a list of items
|
||||
type List struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"listid"`
|
||||
Title string `xorm:"varchar(250)" json:"title"`
|
||||
Description string `xorm:"varchar(1000)" json:"description"`
|
||||
OwnerID int64 `xorm:"int(11)" json:"-"`
|
||||
|
@ -1,20 +1,20 @@
|
||||
package models
|
||||
|
||||
// Delete implements the delete method of CRUDable
|
||||
func (l *List) Delete(id int64) (err error) {
|
||||
func (l *List) Delete() (err error) {
|
||||
// Check if the list exists
|
||||
_, err = GetListByID(id)
|
||||
_, err = GetListByID(l.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Delete the list
|
||||
_, err = x.ID(id).Delete(&List{})
|
||||
_, err = x.ID(l.ID).Delete(&List{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Delete all todoitems on that list
|
||||
_, err = x.Where("list_id = ?", id).Delete(&ListItem{})
|
||||
_, err = x.Where("list_id = ?", l.ID).Delete(&ListItem{})
|
||||
return
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package models
|
||||
|
||||
// ListItem represents an item in a todolist
|
||||
type ListItem struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"listitemid"`
|
||||
Text string `xorm:"varchar(250)" json:"text"`
|
||||
Description string `xorm:"varchar(250)" json:"description"`
|
||||
Done bool `json:"done"`
|
||||
|
@ -1,14 +1,14 @@
|
||||
package models
|
||||
|
||||
// Delete implements the delete method for listItem
|
||||
func (i *ListItem) Delete(id int64) (err error) {
|
||||
func (i *ListItem) Delete() (err error) {
|
||||
|
||||
// Check if it exists
|
||||
_, err = GetListItemByID(id)
|
||||
_, err = GetListItemByID(i.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = x.ID(id).Delete(ListItem{})
|
||||
_, err = x.ID(i.ID).Delete(ListItem{})
|
||||
return
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package models
|
||||
|
||||
// CanDelete checks if the user can delete an item
|
||||
func (i *ListItem) CanDelete(doer *User, id int64) bool {
|
||||
func (i *ListItem) CanDelete(doer *User) bool {
|
||||
// Get the item
|
||||
lI, _ := GetListItemByID(id)
|
||||
lI, _ := GetListItemByID(i.ID)
|
||||
|
||||
// A user can delete an item if he has write acces to its list
|
||||
list, _ := GetListByID(lI.ListID)
|
||||
|
@ -81,8 +81,8 @@ func (l *List) CanRead(user *User) bool {
|
||||
}
|
||||
|
||||
// CanDelete checks if the user can delete a list
|
||||
func (l *List) CanDelete(doer *User, id int64) bool {
|
||||
list, _ := GetListByID(id)
|
||||
func (l *List) CanDelete(doer *User) bool {
|
||||
list, _ := GetListByID(l.ID)
|
||||
return list.IsAdmin(doer)
|
||||
}
|
||||
|
||||
|
@ -1,22 +1,22 @@
|
||||
package models
|
||||
|
||||
// Delete deletes a namespace
|
||||
func (n *Namespace) Delete(id int64) (err error) {
|
||||
func (n *Namespace) Delete() (err error) {
|
||||
|
||||
// Check if the namespace exists
|
||||
_, err = GetNamespaceByID(id)
|
||||
_, err = GetNamespaceByID(n.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Delete the namespace
|
||||
_, err = x.ID(id).Delete(&Namespace{})
|
||||
_, err = x.ID(n.ID).Delete(&Namespace{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Delete all lists with their items
|
||||
lists, err := GetListsByNamespaceID(id)
|
||||
lists, err := GetListsByNamespaceID(n.ID)
|
||||
var listIDs []int64
|
||||
// We need to do that for here because we need the list ids to delete two times:
|
||||
// 1) to delete the lists itself
|
||||
|
@ -77,8 +77,8 @@ func (n *Namespace) CanUpdate(user *User, id int64) bool {
|
||||
}
|
||||
|
||||
// CanDelete checks if the user can delete a namespace
|
||||
func (n *Namespace) CanDelete(user *User, id int64) bool {
|
||||
nn, _ := GetNamespaceByID(id)
|
||||
func (n *Namespace) CanDelete(user *User) bool {
|
||||
nn, _ := GetNamespaceByID(n.ID)
|
||||
return nn.IsAdmin(user)
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package models
|
||||
|
||||
// Namespace holds informations about a namespace
|
||||
type Namespace struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"nid"`
|
||||
Name string `xorm:"varchar(250)" json:"name"`
|
||||
Description string `xorm:"varchar(1000)" json:"description"`
|
||||
OwnerID int64 `xorm:"int(11) not null" json:"-"`
|
||||
|
@ -5,7 +5,7 @@ type Rights interface {
|
||||
IsAdmin(*User) bool
|
||||
CanWrite(*User) bool
|
||||
CanRead(*User) bool
|
||||
CanDelete(*User, int64) bool
|
||||
CanDelete(*User) bool
|
||||
CanUpdate(*User, int64) bool
|
||||
CanCreate(*User, int64) bool
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package models
|
||||
// TeamNamespace defines the relationship between a Team and a Namespace
|
||||
type TeamNamespace struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
|
||||
TeamID int64 `xorm:"int(11) not null" json:"team_id"`
|
||||
NamespaceID int64 `xorm:"int(11) not null" json:"namespace_id"`
|
||||
TeamID int64 `xorm:"int(11) not null" json:"team_id" param:"teamid"`
|
||||
NamespaceID int64 `xorm:"int(11) not null" json:"namespace_id" param:"nid"`
|
||||
Right NamespaceRight `xorm:"int(11)" json:"right"`
|
||||
|
||||
Created int64 `xorm:"created" json:"created"`
|
||||
|
@ -2,7 +2,7 @@ package models
|
||||
|
||||
// Team holds a team object
|
||||
type Team struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"teamid"`
|
||||
Name string `xorm:"varchar(250) not null" json:"name"`
|
||||
Description string `xorm:"varchar(250)" json:"description"`
|
||||
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
|
||||
|
@ -1,33 +1,33 @@
|
||||
package models
|
||||
|
||||
// Delete deletes a team
|
||||
func (t *Team) Delete(id int64) (err error) {
|
||||
func (t *Team) Delete() (err error) {
|
||||
|
||||
// Check if the team exists
|
||||
_, err = GetTeamByID(id)
|
||||
_, err = GetTeamByID(t.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Delete the team
|
||||
_, err = x.ID(id).Delete(&Team{})
|
||||
_, err = x.ID(t.ID).Delete(&Team{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Delete team members
|
||||
_, err = x.Where("team_id = ?", id).Delete(&TeamMember{})
|
||||
_, err = x.Where("team_id = ?", t.ID).Delete(&TeamMember{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Delete team <-> namespace relations
|
||||
_, err = x.Where("team_id = ?", id).Delete(&TeamNamespace{})
|
||||
_, err = x.Where("team_id = ?", t.ID).Delete(&TeamNamespace{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Delete team <-> lists relations
|
||||
_, err = x.Where("team_id = ?", id).Delete(&TeamList{})
|
||||
_, err = x.Where("team_id = ?", t.ID).Delete(&TeamList{})
|
||||
return
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ func (t *Team) CanUpdate(user *User, id int64) bool {
|
||||
}
|
||||
|
||||
// CanDelete checks if a user can delete a team
|
||||
func (t *Team) CanDelete(user *User, id int64) bool {
|
||||
t.ID = id
|
||||
func (t *Team) CanDelete(user *User) bool {
|
||||
//t.ID = id
|
||||
return t.IsAdmin(user)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user