In my system every user has an own public profile. I want to show an "Edit" button only on the profile page of the current logged user. Now I'm doing this by using this code
@subjectPresent() {
@if(userProfile == userLogged){
<button>Edit</button>
}
}
where userProfile
is the owner user of the current page, and userLogged
is the actual logged user.
Considering that I will have to do this check a lot of times, is there in Deadbolt or Scala a better (cleaner) way to do it?
As David suggested, you can wrap this up in your own tag. Tags are just functions, and look like other views (in fact, they are other views).
You can try something like
and save this in a file called foo.scala.html
You can then use this with
You'll need to use the correct type declarations or imports where necessary, e.g. User, importing the tag, etc. This depends on the structure of your project.
You will ultimately need to make the same logical checks that you're doing in the above snippet, so you can just create a new "tag" (another view) that takes in the "current" user and does both tests. You'll also probably want to create something similar to use on the controller side, like an extension of the SubjectPresentAction.