Added method to delete a user from a team

This commit is contained in:
konrad 2018-07-26 09:58:48 +02:00 committed by kolaente
parent bc580e0115
commit 9c451daf30
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 19 additions and 1 deletions

View 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
}

View file

@ -1,6 +1,17 @@
package models package models
// CanCreate checks if the user can add a new tem member
func (tm *TeamMember) CanCreate(user *User) bool { 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 // 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). exists, _ := x.Where("user_id = ? AND team_id = ? AND admin = ?", user.ID, tm.TeamID, true).