Hi! David
My siteMap is defined dynamically from a database, in the Boot I have
some conditions for to construct the sitemap
def sitemap() = {
if (Usuario.currentUserId.isDefined){
if
((Usuario.findByKey(Usuario.currentUserId.get.toLong).get.password.match_?
(DefaultPassword.getDefaultPassword) ) || (!
Aplicacion.currentApplicationId.isDefined ))
{ SiteMap(Usuario.sitemap :_*) }
else
{ val perfilId = UsuarioAplicacionPerfil.findAll(
By(UsuarioAplicacionPerfil.usuario_Id,Usuario.currentUserId.get.toLong),
By(UsuarioAplicacionPerfil.aplicacion_Id,
Aplicacion.currentApplicationId.get.toLong),
MaxRows(1)).headOption match {
case None => 0
case Some(uap) => uap.perfil_Id.toLong
}
// head.perfil_Id.toLong
Log.info("PERFIL ACTUAL " + perfilId)
perfilId match {
case 0 => SiteMap(Usuario.sitemap :_*) // caso perfil 0,
cuando se quita la aplicacion a un usuario con sesion abierta
case _ => SiteMap(Usuario.sitemap :::
menu.getMenuPerfil(perfilId,
Aplicacion.currentApplicationId.get.toLong) :_*) } }
}
else { SiteMap(Usuario.sitemap :_*) }
}
LiftRules.setSiteMapFunc(sitemap)
Usuario.sitemap only has 3 options ( Home Login OR Home,Reset
Password,Logout )
And
menu.getMenuPerfil(...) get the dynamic Menu of the database
This is the function:
------------
codPerfil -> is a Profile
idAplicacion -> Is an Id of Application
Opcion -> Option of menu
OpcionPerfil -> the menu option of a profile
esReescrito -> If the menu has rewrite rules
nombreUnico -> unique name
nombrePagina -> name of menu (show this text)
getSubMenuPerfil -> recursive function for submenus
---------
def getMenuPerfil(codPerfil:Long, idAplicacion:Long): List[Menu] = {
Opcion.findAll( In(Opcion.id,OpcionPerfil.opcion_Id,By(OpcionPerfil.perfil_Id,
codPerfil), By(OpcionPerfil.aplicacion_Id, idAplicacion)),
OrderBy(Opcion.orden, Ascending)).filter(a => a.padre_id == 0).map(
menu => { if (menu.esReescrito)
Menu(Loc( menu.nombreUnico,menu.nombrePagina.split("/").toList ->
true ,menu.nombre.toString ),
getSubMenuPerfil(codPerfil,idAplicacion,
menu.id): _*)
else
Menu(Loc( menu.nombreUnico,menu.nombrePagina.split("/").toList ,menu.nombre.toString ),
getSubMenuPerfil(codPerfil, idAplicacion,
menu.id): _*)
}
)
}
def getSubMenuPerfil(codPerfil:Long, idAplicacion:Long,
codPadre:Long): List[Menu] = {
Opcion.findAll( In(Opcion.id,OpcionPerfil.opcion_Id,By(OpcionPerfil.perfil_Id,
codPerfil), By(OpcionPerfil.aplicacion_Id, idAplicacion)),
OrderBy(Opcion.orden, Ascending)).filter(a => a.padre_id ==
codPadre).map(
menu => { if (menu.esReescrito)
Menu(Loc( menu.nombreUnico,menu.nombrePagina.split("/").toList ->
true ,menu.nombre.toString ),
getSubMenuPerfil(codPerfil,idAplicacion,
menu.id) : _*)
else
Menu(Loc( menu.nombreUnico,menu.nombrePagina.split("/").toList ,menu.nombre.toString ),
getSubMenuPerfil(codPerfil,idAplicacion,
menu.id) : _*)
}
)
}
At one point my user can have permissions to access a menu option, but
if I remove that option (through an option in the application of
permits), the url to which to redirect it is no longer displayed, then
I wish I could redirect you to the home
Thanks for your help!!
Andrea Moruno
> >
liftweb+u...@googlegroups.com<
liftweb%2Bunsu...@googlegroups.com>
> > .
> Beginning Scalahttp://
www.apress.com/book/view/1430219890