Here my problem:
I need to check in a controller the user permission using deadbolt and then add something to the request (using an ActionBuilder). Normally using Play Action Builders would be (action1 andThen action2)
but this doesn't work with DeadboltActions.
Here some code:
ActionBuilder
import javax.inject.Inject
import models.Item
import modules.item.services.ItemServiceClient
import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future}
class ItemRequest[A](val items: Seq[Item], request: Request[A]) extends WrappedRequest[A](request)
class ItemAction @Inject()(val parser: BodyParsers.Default)(implicit val executionContext: ExecutionContext)
extends ActionBuilder[ItemRequest, AnyContent] with ActionTransformer[Request, ItemRequest] {
def transform[A](request: Request[A]): Future[ItemRequest[A]] = {
ItemServiceClient.getItems.map{
new ItemRequest(_, request)
}recover{
case _ => new ItemRequest(Seq(), request)
}
}
}
Controller:
@Singleton
class ItemController @Inject()(cc: ControllerComponents, deadbolt: DeadboltActions, itemAction: ItemAction) extends AbstractController(cc) with I18nSupport {
def createSomething: Action[AnyContent] = (deadbolt.Pattern("Create_Something", PatternType.EQUALITY) andThen itemAction) { implicit request: ItemRequest[AnyContent] =>
Ok(modules.item.views.html.createSomething(Something.form, request.items))
}
}
[error] Unapplied methods are only converted to functions when a function type is expected. You can make this conversion explicit by writing
Pattern _
orPattern(_,_,_,_,_)(_)(_)
instead ofPattern
.[error] def createSomething: Action[AnyContent] = (deadbolt.Pattern("Create_Deck", PatternType.EQUALITY)() andThen itemAction).synchronized() { implicit request: ItemRequest[AnyContent] =>
Anyone who already dealt with this?