2018-11-26 21:17:33 +01:00
|
|
|
// Vikunja is a todo-list application to facilitate your life.
|
|
|
|
// Copyright 2018 Vikunja and contributors. All rights reserved.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2018-07-26 09:58:48 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
// Delete deletes a user from a team
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Summary Remove a user from a team
|
|
|
|
// @Description Remove a user from a team. This will also revoke any access this user might have via that team.
|
|
|
|
// @tags team
|
|
|
|
// @Produce json
|
2019-01-03 23:22:06 +01:00
|
|
|
// @Security JWTKeyAuth
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Param id path int true "Team ID"
|
|
|
|
// @Param userID path int true "User ID"
|
|
|
|
// @Success 200 {object} models.Message "The user was successfully removed from the team."
|
|
|
|
// @Failure 500 {object} models.Message "Internal error"
|
|
|
|
// @Router /teams/{id}/members/{userID} [delete]
|
2018-07-26 09:58:48 +02:00
|
|
|
func (tm *TeamMember) Delete() (err error) {
|
2018-07-27 19:20:49 +02:00
|
|
|
|
|
|
|
total, err := x.Where("team_id = ?", tm.TeamID).Count(&TeamMember{})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if total == 1 {
|
|
|
|
return ErrCannotDeleteLastTeamMember{tm.TeamID, tm.UserID}
|
|
|
|
}
|
|
|
|
|
2018-07-26 09:58:48 +02:00
|
|
|
_, err = x.Where("team_id = ? AND user_id = ?", tm.TeamID, tm.UserID).Delete(&TeamMember{})
|
|
|
|
return
|
|
|
|
}
|