quit all teams when closing account

This commit is contained in:
Thibault Duplessis 2012-12-28 21:22:04 +01:00
parent 136ca64b8e
commit 6b863a7f04
3 changed files with 8 additions and 2 deletions

View file

@ -105,7 +105,7 @@ object User extends LilaController {
val closeConfirm = Auth { ctx
me
IORedirect {
userRepo disable me map { _
(userRepo disable me) >> env.team.api.quitAll(me.id) inject {
env.security.store deleteUsername me.username
routes.User show me.username
}

View file

@ -12,7 +12,7 @@ import org.joda.time.DateTime
// db.team_member.ensureIndex({team:1})
// db.team_member.ensureIndex({user:1})
// db.team_member.ensureIndex({date: -1})
final class MemberRepo(collection: MongoCollection)
private[team] final class MemberRepo(collection: MongoCollection)
extends SalatDAO[Member, String](collection) {
def userIdsByTeamId(teamId: String): IO[List[String]] = io {
@ -31,6 +31,10 @@ final class MemberRepo(collection: MongoCollection)
remove(teamIdQuery(teamId))
}
def removeByUserId(userId: String): IO[Unit] = io {
remove(userIdQuery(userId))
}
def exists(teamId: String, userId: String): IO[Boolean] = io {
collection.find(idQuery(teamId, userId)).limit(1).size != 0
}

View file

@ -125,6 +125,8 @@ final class TeamApi(
io(cached invalidateTeamIds userId)
} doIf belongsTo(team.id, userId)
def quitAll(userId: String): IO[Unit] = memberRepo.removeByUserId(userId)
def kick(team: Team, userId: String): IO[Unit] = doQuit(team, userId)
// delete for ever, with members but not forums