mkurz / deadbolt-2-scala

Idiomatic Scala API for Deadbolt 2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

not found: value restrict

chatzich opened this issue · comments

Hello,

Im using play 2.6.5 and deadbolt 2.6.1 java.

I am trying to add @restrict() {} but does not work.

im add the import

@import be.objectify.deadbolt.java.views.html.di.{restrict}

but all time say me

Compilation error
not found: value restrict

What am I doing wrong?

Thanks.

object restrictOr is not a member of package be.objectify.deadbolt.scala.views.html.di
[error] Note: class restrictOr exists, but it has no companion object.

Boy @ironexmaiden , you should use https://www.playframework.com/documentation/2.6.x/ScalaTemplatesDependencyInjection because now restrict, restrictOr they are using @this(...) construction, it means that these templates are injectable, so you can't just take them and put into your codebase

Just in case someone else is suffering through the upgrade, here's (part of) what I had to do to get Play 2.6 to run:

In the controller, I had to reference my views as follows:

class MyController @Inject() (
  configuration: Configuration, sessionManager: SessionManager,
  deadbolt: DeadboltActions, handlers: HandlerCache, actionBuilder: ActionBuilders,
  signinPageView: views.html.signinPage
) extends ControllerHelpers {
  ...

  def signin: Action[AnyContent] =  deadbolt.WithAuthRequest()() { implicit request =>
    Future {
       Results.Forbidden(signinPageView(configuration,  Some("Some message") ))\
    }
  }
...

and in template:

@import ....

@this(restrictTo: be.objectify.deadbolt.scala.views.html.di.restrict)
@(title: String)(implicit request: AuthenticatedRequest[Any], handler: DeadboltHandler)

<!DOCTYPE html>
<html lang="en">
    <head>
    </head>
    <body>
    ...
    @restrictTo(roles = List(Array("admin"))) {
      <div>restricted things</div>
    }
    ...
    </body>
</html>

hi @lorenzfischer, what do I have to make it work with play2.6-java?
I have added these two lines at the top of my filename.scala.html
@import be.objectify.deadbolt.java.views.html.{restrict, restrictOr}
@import be.objectify.deadbolt.java.utils.TemplateUtils.{allOf, anyOf, allOfGroup}
I get the following error
object restrict is not a member of package be.objectify.deadbolt.java.views.html

Hi, In java doesn't exist DeadboltActions class, can you help me pls?