i want give logged in user possibility edit user account quick link.
for created link using correct gsp tag, , want pass user id spring security userdetails object, using correct helper.
the problem works, when in gsp tag, after edit user, not need it, in id attribute.
<g:link controller="user" action="show" id="${sec.loggedinuserinfo(field: "id")}"> edit user ${sec.loggedinuserinfo(field: "id")} </g:link>
expected:
<a href="/backoffice/user/show/1"> edit user 1 </a>
wrong result:
<a href="/backoffice/user/show"> edit user 1 </a>
the userdetails class security tag lib accessing here:
import org.codehaus.groovy.grails.plugins.springsecurity.grailsuser import org.springframework.security.core.grantedauthority class userdetails extends grailsuser { final string displayname final string email final string gravatarimage ...
the id defined object in grailsuser base class.
class grailsuser extends user {
private final object _id ...
}
and encoded html here:
/** * renders property (specified 'field' attribute) principal. * * @attr field required field name */ def loggedinuserinfo = { attrs, body -> // todo support 'var' , 'scope' , set result instead of writing string field = assertattribute('field', attrs, 'loggedinuserinfo') def source if (springsecurityservice.isloggedin()) { source = determinesource() (pathelement in field.split('\\.')) { source = source."$pathelement" if (source == null) { break } } } if (source) { out << source.encodeashtml() } else { out << body() } }
funny thing is: works. use consistent gsp syntax links, , understand why code posted on top not work.
<a href="${createlink( controller : "user", action : "show", id : sec.loggedinuserinfo(field: "id"))}">edit user</a>
looks wrong quoting - need escape "
inside of id="..."
. keep simple, try using field: 'id'
instead of field: "id"
.
Comments
Post a Comment