2018-07-26 09:53:32 +02:00
|
|
|
package models
|
|
|
|
|
2018-07-26 09:58:48 +02:00
|
|
|
// CanCreate checks if the user can add a new tem member
|
2018-07-26 09:53:32 +02:00
|
|
|
func (tm *TeamMember) CanCreate(user *User) bool {
|
2018-07-26 09:58:48 +02:00
|
|
|
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 {
|
2018-07-26 09:53:32 +02:00
|
|
|
|
|
|
|
// 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
|
2018-07-26 09:58:48 +02:00
|
|
|
}
|