Track declined team requests
Declined team requests are added to new collection team_request_declined and the users are not allowed to join the team if the request is declinedpull/9743/head
parent
aaa30878d6
commit
01f2d00218
|
@ -1,8 +1,10 @@
|
|||
package lila.app
|
||||
package mashup
|
||||
|
||||
import com.softwaremill.tagging._
|
||||
|
||||
import lila.forum.MiniForumPost
|
||||
import lila.team.{ RequestRepo, RequestWithUser, Team, TeamApi }
|
||||
import lila.team.{ DeclinedRequest, NewRequest, RequestRepo, RequestWithUser, Team, TeamApi }
|
||||
import lila.tournament.{ Tournament, TournamentApi }
|
||||
import lila.user.User
|
||||
import lila.swiss.{ Swiss, SwissApi }
|
||||
|
@ -12,6 +14,7 @@ case class TeamInfo(
|
|||
mine: Boolean,
|
||||
ledByMe: Boolean,
|
||||
requestedByMe: Boolean,
|
||||
isMyRequestDeclined: Boolean,
|
||||
subscribed: Boolean,
|
||||
requests: List[RequestWithUser],
|
||||
forum: Option[List[MiniForumPost]],
|
||||
|
@ -45,24 +48,27 @@ final class TeamInfoApi(
|
|||
tourApi: TournamentApi,
|
||||
swissApi: SwissApi,
|
||||
simulApi: SimulApi,
|
||||
requestRepo: RequestRepo
|
||||
requestRepo: RequestRepo @@ NewRequest,
|
||||
requestDeclinedRepo: RequestRepo @@ DeclinedRequest
|
||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
import TeamInfo._
|
||||
|
||||
def apply(team: Team, me: Option[User], withForum: Boolean => Boolean): Fu[TeamInfo] =
|
||||
for {
|
||||
requests <- (team.enabled && me.exists(m => team.leaders(m.id))) ?? api.requestsWithUsers(team)
|
||||
mine <- me.??(m => api.belongsTo(team.id, m.id))
|
||||
requestedByMe <- !mine ?? me.??(m => requestRepo.exists(team.id, m.id))
|
||||
subscribed <- me.ifTrue(mine) ?? { api.isSubscribed(team, _) }
|
||||
forumPosts <- withForum(mine) ?? forumRecent.team(team.id).dmap(some)
|
||||
tours <- tournaments(team, 5, 5)
|
||||
simuls <- simulApi.byTeamLeaders(team.id, team.leaders.toSeq)
|
||||
requests <- (team.enabled && me.exists(m => team.leaders(m.id))) ?? api.requestsWithUsers(team)
|
||||
mine <- me.??(m => api.belongsTo(team.id, m.id))
|
||||
requestedByMe <- !mine ?? me.??(m => requestRepo.exists(team.id, m.id))
|
||||
isMyRequestDeclined <- !mine ?? !requestedByMe ?? me.??(m => requestDeclinedRepo.exists(team._id, m.id))
|
||||
subscribed <- me.ifTrue(mine) ?? { api.isSubscribed(team, _) }
|
||||
forumPosts <- withForum(mine) ?? forumRecent.team(team.id).dmap(some)
|
||||
tours <- tournaments(team, 5, 5)
|
||||
simuls <- simulApi.byTeamLeaders(team.id, team.leaders.toSeq)
|
||||
} yield TeamInfo(
|
||||
mine = mine,
|
||||
ledByMe = me.exists(m => team.leaders(m.id)),
|
||||
requestedByMe = requestedByMe,
|
||||
isMyRequestDeclined = isMyRequestDeclined,
|
||||
subscribed = subscribed,
|
||||
requests = requests,
|
||||
forum = forumPosts,
|
||||
|
|
|
@ -97,6 +97,11 @@ object show {
|
|||
submitButton(cls := "button button-red button-empty confirm")(trans.cancel())
|
||||
)
|
||||
)
|
||||
else if (info.isMyRequestDeclined)
|
||||
frag(
|
||||
strong(requestDeclined()),
|
||||
a(cls := "button disabled button-metal")(joinTeam())
|
||||
)
|
||||
else ctx.isAuth option joinButton(t)
|
||||
),
|
||||
ctx.userId.ifTrue(t.enabled && info.mine) map { myId =>
|
||||
|
|
|
@ -377,7 +377,7 @@ lazy val forumSearch = module("forumSearch",
|
|||
|
||||
lazy val team = module("team",
|
||||
Seq(common, memo, db, user, forum, security, hub, notifyModule),
|
||||
reactivemongo.bundle
|
||||
reactivemongo.bundle ++ Seq(macwire.tagging)
|
||||
)
|
||||
|
||||
lazy val teamSearch = module("teamSearch",
|
||||
|
|
|
@ -1652,6 +1652,7 @@ val `kickSomeone` = new I18nKey("team:kickSomeone")
|
|||
val `whoToKick` = new I18nKey("team:whoToKick")
|
||||
val `willBeReviewed` = new I18nKey("team:willBeReviewed")
|
||||
val `beingReviewed` = new I18nKey("team:beingReviewed")
|
||||
val `requestDeclined` = new I18nKey("team:requestDeclined")
|
||||
val `subToTeamMessages` = new I18nKey("team:subToTeamMessages")
|
||||
val `teamBattle` = new I18nKey("team:teamBattle")
|
||||
val `teamBattleOverview` = new I18nKey("team:teamBattleOverview")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package lila.team
|
||||
|
||||
import com.softwaremill.tagging._
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import lila.memo.Syncache
|
||||
|
@ -8,7 +9,7 @@ import lila.user.User
|
|||
final class Cached(
|
||||
teamRepo: TeamRepo,
|
||||
memberRepo: MemberRepo,
|
||||
requestRepo: RequestRepo,
|
||||
requestRepo: RequestRepo @@ NewRequest,
|
||||
cacheApi: lila.memo.CacheApi
|
||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package lila.team
|
|||
|
||||
import akka.actor._
|
||||
import com.softwaremill.macwire._
|
||||
|
||||
import com.softwaremill.tagging._
|
||||
import lila.common.config._
|
||||
import lila.mod.ModlogApi
|
||||
import lila.notify.NotifyApi
|
||||
|
@ -29,7 +29,9 @@ final class Env(
|
|||
|
||||
lazy val teamRepo = new TeamRepo(db(CollName("team")))
|
||||
lazy val memberRepo = new MemberRepo(db(CollName("team_member")))
|
||||
lazy val requestRepo = new RequestRepo(db(CollName("team_request")))
|
||||
lazy val requestRepo = new RequestRepo(db(CollName("team_request"))).taggedWith[NewRequest]
|
||||
lazy val declinedRequestRepo =
|
||||
new RequestRepo(db(CollName("team_request_declined"))).taggedWith[DeclinedRequest]
|
||||
|
||||
lazy val forms = wire[TeamForm]
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ package lila.team
|
|||
import lila.db.dsl._
|
||||
import lila.user.User
|
||||
|
||||
trait NewRequest
|
||||
trait DeclinedRequest
|
||||
final class RequestRepo(val coll: Coll)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
import BSONHandlers._
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package lila.team
|
||||
|
||||
import actorApi._
|
||||
import com.softwaremill.tagging._
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.Period
|
||||
import play.api.libs.json.{ JsSuccess, Json }
|
||||
import reactivemongo.api.{ Cursor, ReadPreference }
|
||||
|
@ -16,11 +18,11 @@ import lila.hub.LeaderTeam
|
|||
import lila.memo.CacheApi._
|
||||
import lila.mod.ModlogApi
|
||||
import lila.user.{ User, UserRepo }
|
||||
|
||||
final class TeamApi(
|
||||
teamRepo: TeamRepo,
|
||||
memberRepo: MemberRepo,
|
||||
requestRepo: RequestRepo,
|
||||
requestRepo: RequestRepo @@ NewRequest,
|
||||
declinedRequestRepo: RequestRepo @@ DeclinedRequest,
|
||||
userRepo: UserRepo,
|
||||
cached: Cached,
|
||||
notifier: Notifier,
|
||||
|
@ -140,9 +142,10 @@ final class TeamApi(
|
|||
|
||||
def requestable(team: Team, user: User): Fu[Boolean] =
|
||||
for {
|
||||
belongs <- belongsTo(team.id, user.id)
|
||||
requested <- requestRepo.exists(team.id, user.id)
|
||||
} yield !belongs && !requested
|
||||
belongs <- belongsTo(team.id, user.id)
|
||||
requested <- requestRepo.exists(team.id, user.id)
|
||||
requestDeclined <- declinedRequestRepo.exists(team._id, user.id)
|
||||
} yield !belongs && !requested && !requestDeclined
|
||||
|
||||
def createRequest(team: Team, user: User, msg: String): Funit =
|
||||
requestable(team, user) flatMap {
|
||||
|
@ -168,6 +171,7 @@ final class TeamApi(
|
|||
userOption
|
||||
.filter(_ => accept)
|
||||
.??(user => doJoin(team, user) >> notifier.acceptRequest(team, request))
|
||||
_ <- !accept ?? declinedRequestRepo.coll.insert.one(request.copy(date = DateTime.now())).void
|
||||
} yield ()
|
||||
|
||||
def deleteRequestsByUserId(userId: User.ID) =
|
||||
|
|
|
@ -39,6 +39,8 @@ object Dependencies {
|
|||
val version = "2.4.1"
|
||||
val macros = "com.softwaremill.macwire" %% "macros" % version % "provided"
|
||||
val util = "com.softwaremill.macwire" %% "util" % version % "provided"
|
||||
val tagging = "com.softwaremill.common" %% "tagging" % "2.3.1"
|
||||
|
||||
def bundle = Seq(macros, util)
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
</plurals>
|
||||
<string name="willBeReviewed">Your join request will be reviewed by a team leader.</string>
|
||||
<string name="beingReviewed">Your join request is being reviewed by a team leader.</string>
|
||||
<string name="requestDeclined">Your join request was declined by a team leader.</string>
|
||||
<string name="subToTeamMessages">Subscribe to team messages</string>
|
||||
<string name="teamBattle">Team Battle</string>
|
||||
<string name="teamBattleOverview">A battle of multiple teams, each player scores points for their team</string>
|
||||
|
|
Loading…
Reference in New Issue