add a button for team admins to re-enable disabled teams

pull/8833/head
Thibault Duplessis 2021-05-01 09:20:21 +02:00
parent e5d0b3402a
commit e6e23d9c32
4 changed files with 21 additions and 15 deletions

View File

@ -197,7 +197,7 @@ final class Team(
def disable(id: String) =
Auth { implicit ctx => me =>
WithOwnedTeam(id) { team =>
api.disable(team, me) >>
api.toggleEnabled(team, me) >>
env.mod.logApi.disableTeam(me.id, team.id, team.name) inject
Redirect(routes.Team show id).flashSuccess
}

View File

@ -87,6 +87,13 @@ object form {
cls := "text button button-empty button-red confirm",
st.title := "Deletes the team and its memberships. Cannot be reverted!"
)(trans.delete())
),
(t.disabled && isGranted(_.ManageTeam)) option
postForm(cls := "inline", action := routes.Team.disable(t.id))(
submitButton(
cls := "button button-empty confirm",
st.title := "Re-enables the team and restores memberships"
)("Re-enable")
)
)
)

View File

@ -271,18 +271,19 @@ final class TeamApi(
teamIds.nonEmpty ?? teamRepo.coll.exists($inIds(teamIds) ++ $doc("leaders" -> leader))
}
def enable(team: Team): Funit =
teamRepo.enable(team).void >>- (indexer ! InsertTeam(team))
def disable(team: Team, by: User): Funit =
if (lila.security.Granter(_.ManageTeam)(by) || team.createdBy == by.id || !team.leaders(team.createdBy))
teamRepo.disable(team).void >>
memberRepo.userIdsByTeam(team.id).map {
_ foreach cached.invalidateTeamIds
} >>
requestRepo.removeByTeam(team.id).void >>-
(indexer ! RemoveTeam(team.id))
else
def toggleEnabled(team: Team, by: User): Funit =
if (
lila.security.Granter(_.ManageTeam)(by) || team.createdBy == by.id ||
(team.leaders(by.id) && !team.leaders(team.createdBy))
) {
if (team.enabled)
teamRepo.disable(team).void >>
memberRepo.userIdsByTeam(team.id).map { _ foreach cached.invalidateTeamIds } >>
requestRepo.removeByTeam(team.id).void >>-
(indexer ! RemoveTeam(team.id))
else
teamRepo.enable(team).void >>- (indexer ! InsertTeam(team))
} else
teamRepo.setLeaders(team.id, team.leaders - by.id)
// delete for ever, with members but not forums

View File

@ -12,8 +12,6 @@ final private[team] class TeamCli(
def process = {
case "team" :: "enable" :: team :: Nil => perform(team)(api.enable)
case "team" :: "recompute" :: "nbMembers" :: "all" :: Nil =>
api.recomputeNbMembers
fuccess("In progress... it will take a while")