True. It isn't really against the MVC paradigm, as it's kind-of on the edge
of the boundaries (by my reckoning). Is it logic? Or is it presentation?
Anyway, I see what you're trying to do, and can suggest some alternatives
that'll work nicely:
1) Use inheritance on the screens. We have different ACL checks and context
creation depending on the security level of the screen being requested,
which is stipulated by which screen class we inherit from.
2) Change your isAuthorized() method a little bit:
Instead of:
data.setLayoutTemplate("AdminDefault.vm")
Use:
data.getUserFromSession().setTemp("layout_template","AdminDefault.vm")
...and in your template use:
#set( $layTmpl = $data.getUserFromSession().getTemp("layout_template") )
$data.setLayoutTemplate($layTmpl)
3) Change your isAuthorized() method and only check for access in that
method. Add some extra code to the top of your doBuildTemplate(RunData,
Context):
public void doBuildTemplate(RunData data, Context context)
{
setContextACLs(data.getACL(), context);
.
.
.
Where:
protected void setContextACLs(AccessControlList acl, Context ctx)
{
if (acl == null)
return;
if (acl.hasPermission("admin_users"))
ctx.put("Admin", "1");
if (acl.hasPermission("client_access"))
ctx.put("Client", "1");
if (acl.hasPermission("staff_access"))
ctx.put("Staff", "1");
}
Then, in your Menu.vm navigation, or however you construct the menu:
#if($Admin)
Admin menu items
Admin menu items
Admin menu items
Admin menu items
#end
#if($Client)
.
.
.
#end
And so on... There's more than one way to do it, and if you're anything like
us then the vote goes different ways from week to week.
-Greg
> -----Original Message-----
> From: Naree Song [mailto:[EMAIL PROTECTED]
> Sent: Monday, 24 November 2003 1:16 p.m.
> To: Turbine Users List
> Subject: Re: Layout Template Change
>
> Hello Greg,
>
> I am trying to have a different set of menu depending on the permission of
> the user.
> This was implemented by creating Default.java where isAuthorised is used
> to
> set different layout
>
> protected boolean isAuthorized(RunData data) throws Exception
> {
> boolean isAuthorized = false;
>
> AccessControlList acl = data.getACL();
>
> if (acl == null || !acl.hasRole("turbine_root"))
> {
>
> data.setScreenTemplate(Turbine.getConfiguration().getString("template.logi
> n"
> ));
> isAuthorized = false;
> }
> else if (acl.hasRole("turbine_root") && acl.hasRole("admin"))
> {
> data.setLayoutTemplate("AdminDefault.vm");
> isAuthorized = true;
> }
> else if (acl.hasRole("turbine_root"))
> {
> isAuthorized = true;
> }
> return isAuthorized;
> }
>
> This worked out nicely until I tried to change the screen template and the
> layout template
> reverted back to Default.vm
>
> I prefered this way as I did not have to include the checking in every
> template.
>
> Is this going against the MVC paradigm?
>
> Is there inheritance in Velocity Template ?
>
> Regards,
> Naree
> --
> Media Equation
> 71 - 73 Thistlethwaite Street
> South Melbourne 3205
> Australia
> Tel: + 613 9673 8111
> Fax: + 613 9690 4244
>
> ----- Original Message -----
> From: "Greg Kerdemelidis" <[EMAIL PROTECTED]>
> To: "'Turbine Users List'" <[EMAIL PROTECTED]>
> Sent: Monday, November 24, 2003 9:03 AM
> Subject: RE: Layout Template Change
>
>
> >
> > Hmm. Generally, the accepted behaviour with layouts is to set them in
> the
> > template being rendered. It makes a degree of sense to re-initialise the
> > layout when rendering a "new" template, otherwise layout changes could
> > continue across all pages (whether you want it or not).
> >
> > If you really insist on setting the layout template in code (the MVC
> police
> > might get you), try re-arranging the order:
> >
> > data.setScreenTemplate("blah.vm");
> > data.setLayoutTemplate("layout.vm");
> >
> > It obvious that setLayoutTemplate() reassigns the layout. A much better
> > policy is something like:
> >
> > ------blah.vm----
> >
> > $data.setLayoutTemplate("/layout.vm")
> >
> > <p>Rest of template</p>
> >
> > -----------------
> >
> > It never hurts to be explicit about the way a page should be rendered.
> If
> it
> > has a number of different ways of being rendered, control it with a
> > parameter or a key in the context.
> >
> > Hope this helps.
> >
> > Regards,
> >
> > Greg Kerdemelidis
> >
> > > -----Original Message-----
> > > From: Naree Song [mailto:[EMAIL PROTECTED]
> > > Sent: Friday, 21 November 2003 7:21 p.m.
> > > To: Turbine Users List
> > > Subject: Layout Template Change
> > >
> > > Hello,
> > >
> > > I found a strange behaviour with Layout Template.
> > > It seems that when the Screen template gets changed
> > > in screen class using setScreenTemplate,
> > > the Layout template reverts back to the default Layout template.
> > >
> > > **** code *******
> > > else
> > > {
> > > log.info(data.getLayoutTemplate());
> > >
> > > data.setScreenTemplate("PayMe.vm");
> > >
> > > log.info(data.getLayoutTemplate());
> > > }
> > >
> > >
> > > ***** log ***
> > > 2003-11-21 17:09:59,942 [Thread-5] INFO
> > > com.me.mepay.modules.screens.PayMeResult - AdminDefault.vm
> > > 2003-11-21 17:09:59,947 [Thread-5] INFO
> > > com.me.mepay.modules.screens.PayMeResult - Default.vm
> > >
> > > Is this an expected behaviour?
> > >
> > > Regards,
> > > Naree
> > > --
> > > Media Equation
> > > 71 - 73 Thistlethwaite Street
> > > South Melbourne 3205
> > > Australia
> > > Tel: + 613 9673 8111
> > > Fax: + 613 9690 4244
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]