deadbolt-2-scala icon indicating copy to clipboard operation
deadbolt-2-scala copied to clipboard

not found: value restrict

Open chatzich opened this issue 8 years ago • 6 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.

chatzich avatar Dec 20 '17 10:12 chatzich

Same

Jacke avatar Jan 19 '18 11:01 Jacke

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.

Jacke avatar Jan 19 '18 11:01 Jacke

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

Jacke avatar Jan 19 '18 11:01 Jacke

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>

lorenzfischer avatar Feb 12 '18 23:02 lorenzfischer

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

SwapnilBorse123 avatar Jun 22 '18 16:06 SwapnilBorse123

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

luish192 avatar Mar 07 '23 23:03 luish192