[MM-10354] Add feature to remove team icon (#8684)
* set team.LastTeamIconUpdate to 0 when removing team icon * add APIv4 for removing team icon * removed comment and updated typo on AppError
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2e6b3da1d3
Коммит
30011f67e8
21
api4/team.go
21
api4/team.go
@@ -32,6 +32,7 @@ func (api *API) InitTeam() {
|
||||
|
||||
api.BaseRoutes.Team.Handle("/image", api.ApiSessionRequiredTrustRequester(getTeamIcon)).Methods("GET")
|
||||
api.BaseRoutes.Team.Handle("/image", api.ApiSessionRequired(setTeamIcon)).Methods("POST")
|
||||
api.BaseRoutes.Team.Handle("/image", api.ApiSessionRequired(removeTeamIcon)).Methods("DELETE")
|
||||
|
||||
api.BaseRoutes.TeamMembers.Handle("", api.ApiSessionRequired(getTeamMembers)).Methods("GET")
|
||||
api.BaseRoutes.TeamMembers.Handle("/ids", api.ApiSessionRequired(getTeamMembersByIds)).Methods("POST")
|
||||
@@ -812,3 +813,23 @@ func setTeamIcon(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("")
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func removeTeamIcon(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireTeamId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.App.RemoveTeamIcon(c.Params.TeamId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
c.LogAudit("")
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
@@ -2015,3 +2015,40 @@ func TestGetTeamIcon(t *testing.T) {
|
||||
_, resp = Client.GetTeamIcon(team.Id, "")
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestRemoveTeamIcon(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
team := th.BasicTeam
|
||||
|
||||
th.LoginTeamAdmin()
|
||||
data, _ := readTestFile("test.png")
|
||||
Client.SetTeamIcon(team.Id, data)
|
||||
|
||||
_, resp := Client.RemoveTeamIcon(team.Id)
|
||||
CheckNoError(t, resp)
|
||||
teamAfter, _ := th.App.GetTeam(team.Id)
|
||||
if teamAfter.LastTeamIconUpdate != 0 {
|
||||
t.Fatal("should update LastTeamIconUpdate to 0")
|
||||
}
|
||||
|
||||
Client.SetTeamIcon(team.Id, data)
|
||||
|
||||
_, resp = th.SystemAdminClient.RemoveTeamIcon(team.Id)
|
||||
CheckNoError(t, resp)
|
||||
teamAfter, _ = th.App.GetTeam(team.Id)
|
||||
if teamAfter.LastTeamIconUpdate != 0 {
|
||||
t.Fatal("should update LastTeamIconUpdate to 0")
|
||||
}
|
||||
|
||||
Client.SetTeamIcon(team.Id, data)
|
||||
Client.Logout()
|
||||
|
||||
_, resp = Client.RemoveTeamIcon(team.Id)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
th.LoginBasic()
|
||||
_, resp = Client.RemoveTeamIcon(team.Id)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user