Added method to delete a user from a team
This commit is contained in:
parent
bc580e0115
commit
9c451daf30
2 changed files with 19 additions and 1 deletions
7
models/team_members_delete.go
Normal file
7
models/team_members_delete.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package models
|
||||
|
||||
// Delete deletes a user from a team
|
||||
func (tm *TeamMember) Delete() (err error) {
|
||||
_, err = x.Where("team_id = ? AND user_id = ?", tm.TeamID, tm.UserID).Delete(&TeamMember{})
|
||||
return
|
||||
}
|
|
@ -1,9 +1,20 @@
|
|||
package models
|
||||
|
||||
// CanCreate checks if the user can add a new tem member
|
||||
func (tm *TeamMember) CanCreate(user *User) bool {
|
||||
return tm.IsAdmin(user)
|
||||
}
|
||||
|
||||
// CanDelete checks if the user can delete a new team member
|
||||
func (tm *TeamMember) CanDelete(user *User) bool {
|
||||
return tm.IsAdmin(user)
|
||||
}
|
||||
|
||||
// IsAdmin checks if the user is team admin
|
||||
func (tm *TeamMember) IsAdmin(user *User) bool {
|
||||
|
||||
// A user can add a member to a team if he is admin of that team
|
||||
exists, _ := x.Where("user_id = ? AND team_id = ? AND admin = ?", user.ID, tm.TeamID, true).
|
||||
Get(&TeamMember{})
|
||||
return exists
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue