feat: allow a user to remove themselves from a team
This commit is contained in:
parent
b331fdd29a
commit
b8769c746c
6 changed files with 14 additions and 5 deletions
|
@ -79,7 +79,7 @@ func (tm *TeamMember) Create(s *xorm.Session, a web.Auth) (err error) {
|
||||||
|
|
||||||
// Delete deletes a user from a team
|
// Delete deletes a user from a team
|
||||||
// @Summary Remove a user from a team
|
// @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.
|
// @Description Remove a user from a team. This will also revoke any access this user might have via that team. A user can remove themselves from the team if they are not the last user in the team.
|
||||||
// @tags team
|
// @tags team
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security JWTKeyAuth
|
// @Security JWTKeyAuth
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
"code.vikunja.io/web"
|
"code.vikunja.io/web"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
@ -28,6 +29,13 @@ func (tm *TeamMember) CanCreate(s *xorm.Session, a web.Auth) (bool, error) {
|
||||||
|
|
||||||
// CanDelete checks if the user can delete a new team member
|
// CanDelete checks if the user can delete a new team member
|
||||||
func (tm *TeamMember) CanDelete(s *xorm.Session, a web.Auth) (bool, error) {
|
func (tm *TeamMember) CanDelete(s *xorm.Session, a web.Auth) (bool, error) {
|
||||||
|
u, err := user.GetUserByUsername(s, tm.Username)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if u.ID == a.GetID() {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
return tm.IsAdmin(s, a)
|
return tm.IsAdmin(s, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ type TeamMember struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName makes beautiful table names
|
// TableName makes beautiful table names
|
||||||
func (TeamMember) TableName() string {
|
func (*TeamMember) TableName() string {
|
||||||
return "team_members"
|
return "team_members"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6167,7 +6167,7 @@ const docTemplate = `{
|
||||||
"JWTKeyAuth": []
|
"JWTKeyAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Remove a user from a team. This will also revoke any access this user might have via that team.",
|
"description": "Remove a user from a team. This will also revoke any access this user might have via that team. A user can remove themselves from the team if they are not the last user in the team.",
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
|
|
@ -6158,7 +6158,7 @@
|
||||||
"JWTKeyAuth": []
|
"JWTKeyAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Remove a user from a team. This will also revoke any access this user might have via that team.",
|
"description": "Remove a user from a team. This will also revoke any access this user might have via that team. A user can remove themselves from the team if they are not the last user in the team.",
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
|
|
@ -5554,7 +5554,8 @@ paths:
|
||||||
/teams/{id}/members/{userID}:
|
/teams/{id}/members/{userID}:
|
||||||
delete:
|
delete:
|
||||||
description: Remove a user from a team. This will also revoke any access this
|
description: Remove a user from a team. This will also revoke any access this
|
||||||
user might have via that team.
|
user might have via that team. A user can remove themselves from the team
|
||||||
|
if they are not the last user in the team.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Team ID
|
- description: Team ID
|
||||||
in: path
|
in: path
|
||||||
|
|
Loading…
Reference in a new issue