api/models/teams_rights.go

44 lines
1.1 KiB
Go
Raw Normal View History

2018-07-14 15:34:59 +00:00
package models
// CanCreate checks if the user can create a new team
func (t *Team) CanCreate(user *User) bool {
2018-07-14 15:34:59 +00:00
// This is currently a dummy function, later on we could imagine global limits etc.
return true
2018-07-14 15:37:46 +00:00
}
2018-07-14 16:29:24 +00:00
// CanUpdate checks if the user can update a team
func (t *Team) CanUpdate(user *User, id int64) bool {
// Check if the current user is in the team and has admin rights in it
exists, _ := x.Where("team_id = ?", id).
And("user_id = ?", user.ID).
And("is_admin = ?", true).
Get(&TeamMember{})
return exists
}
2018-07-16 06:18:15 +00:00
2018-07-16 06:45:38 +00:00
// CanDelete checks if a user can delete a team
func (t *Team) CanDelete(user *User) bool {
//t.ID = id
2018-07-16 06:18:15 +00:00
return t.IsAdmin(user)
}
2018-07-16 06:45:38 +00:00
// IsAdmin returns true when the user is admin of a team
2018-07-16 06:18:15 +00:00
func (t *Team) IsAdmin(user *User) bool {
exists, _ := x.Where("team_id = ?", t.ID).
And("user_id = ?", user.ID).
And("is_admin = ?", true).
Get(&TeamMember{})
return exists
2018-07-16 06:43:47 +00:00
}
2018-07-16 06:45:38 +00:00
// CanRead returns true if the user has read access to the team
2018-07-16 06:43:47 +00:00
func (t *Team) CanRead(user *User) bool {
// Check if the user is in the team
exists, _ := x.Where("team_id = ?", t.ID).
And("user_id = ?", user.ID).
Get(&TeamMember{})
return exists
}