Skip to content

Commit

Permalink
Fixes #13067: Update main menu: plugin at top level, techique editor …
Browse files Browse the repository at this point in the history
…in configuration policy
  • Loading branch information
fanf committed Aug 31, 2018
1 parent b77196d commit 4f889ee
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 314 deletions.
44 changes: 30 additions & 14 deletions rudder-web/src/main/scala/bootstrap/liftweb/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ import com.normation.rudder.rest.EndpointSchema
import com.normation.rudder.rest.{InfoApi => InfoApiDef}
import com.normation.rudder.rest.lift.InfoApi
import com.normation.rudder.rest.lift.LiftApiModuleProvider
import net.liftweb.sitemap.Loc.LocGroup
import net.liftweb.sitemap.Loc.LocGroup
import net.liftweb.sitemap.Loc.TestAccess
import net.liftweb.sitemap.Loc.TestAccess
import org.reflections.Reflections

/*
Expand Down Expand Up @@ -333,8 +337,9 @@ class Boot extends Loggable {

)

def buildManagerMenu(name:String) =
Menu(name+"ManagerHome", <i class="fa fa-gears"></i> ++ <span>{name.capitalize} policy</span>) /
def policyMenu = {
val name = "configuration"
Menu(name+"ManagerHome", <i class="fa fa-pencil"></i> ++ <span>{name.capitalize} policy</span>) /
"secure" / (name+"Manager") / "index" >> TestAccess ( ()
=> userIsAllowed("/secure/index",AuthorizationType.Configuration.Read) ) submenus (

Expand All @@ -348,11 +353,17 @@ class Boot extends Loggable {
>> LocGroup(name+"Group")
>> TestAccess( () => userIsAllowed("/secure/index",AuthorizationType.Directive.Read ) )

, Menu("techniqueEditor", <span>Techniques</span>) /
"secure" / (name+"Manager") / "techniqueEditor"
>> LocGroup((name+"Manager"))
>> TestAccess ( () => userIsAllowed("/secure/index",AuthorizationType.Technique.Read) )

, Menu(name+"ParameterManagement", <span>Parameters</span>) /
"secure" / (name+"Manager") / "parameterManagement"
>> LocGroup(name+"Group")
>> TestAccess( () => userIsAllowed("/secure/index",AuthorizationType.Directive.Read ) )
)
}

def administrationMenu =
Menu("AdministrationHome", <i class="fa fa-gear"></i> ++ <span>Settings</span>) /
Expand All @@ -364,26 +375,35 @@ class Boot extends Loggable {
>> LocGroup("administrationGroup")
>> TestAccess ( () => userIsAllowed("/secure/index",AuthorizationType.Administration.Read) )

, Menu("pluginManagement", <span>Plugins</span>) /
"secure" / "administration" / "pluginManagement"
>> LocGroup("administrationGroup")
>> TestAccess ( () => userIsAllowed("/secure/administration/policyServerManagement",AuthorizationType.Administration.Read) )

, Menu("databaseManagement", <span>Reports database</span>) /
"secure" / "administration" / "databaseManagement"
>> LocGroup("administrationGroup")
>> TestAccess ( () => userIsAllowed("/secure/administration/policyServerManagement",AuthorizationType.Administration.Read) )

, Menu("TechniqueLibraryManagement", <span>Techniques</span>) /
, Menu("TechniqueLibraryManagement", <span>Active Tree</span>) /
"secure" / "administration" / "techniqueLibraryManagement"
>> LocGroup("administrationGroup")
>> TestAccess( () => userIsAllowed("/secure/index",AuthorizationType.Technique.Read ) )

, Menu("apiManagement", <span>API accounts</span>) /
"secure" / "administration" / "apiManagement"
>> LocGroup("administrationGroup")
>> TestAccess ( () => userIsAllowed("/secure/administration/policyServerManagement",AuthorizationType.Administration.Write) )
)

def pluginsMenu = {
(Menu("PluginsHome", <i class="fa fa-puzzle-piece"></i> ++ <span>Plugins</span>) /
"secure" / "plugins" / "index"
>> LocGroup("pluginsGroup")
>> TestAccess ( () => userIsAllowed("/secure/index", AuthorizationType.Administration.Read)
)) submenus (
Menu("pluginInformation", <span>Plugin Information</span>) /
"secure" / "plugins" / "pluginInformation"
>> LocGroup("pluginsGroup")
>> TestAccess ( () => userIsAllowed("/secure/index", AuthorizationType.Administration.Read) )
)
}

def utilitiesMenu = {
// if we can't get the workflow property, default to false
// (don't give rights if you don't know)
Expand Down Expand Up @@ -426,11 +446,6 @@ class Boot extends Loggable {
"secure" / "utilities" / "eventLogs"
>> LocGroup("utilitiesGroup")
>> TestAccess ( () => userIsAllowed("/secure/index",AuthorizationType.Administration.Read) )

, Menu("techniqueEditor", <span>Technique editor</span>) /
"secure" / "utilities" / "techniqueEditor"
>> LocGroup("utilitiesGroup")
>> TestAccess ( () => userIsAllowed("/secure/index",AuthorizationType.Technique.Read) )
)
}

Expand All @@ -439,9 +454,10 @@ class Boot extends Loggable {
, Menu("Login") / "index" >> Hidden
, Menu("Templates") / "templates" / ** >> Hidden //allows access to html file use by js
, nodeManagerMenu
, buildManagerMenu("configuration")
, policyMenu
, utilitiesMenu
, administrationMenu
, pluginsMenu
).map( _.toMenu )

////////// import and init modules //////////
Expand Down
20 changes: 20 additions & 0 deletions rudder-web/src/main/scala/com/normation/plugins/PublicPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ package com.normation.plugins
import com.normation.rudder.domain.logger.ApplicationLogger
import com.typesafe.config.ConfigException
import com.typesafe.config.ConfigFactory
import net.liftweb.sitemap.Menu
import net.liftweb.util.Helpers

import scala.xml.NodeSeq
Expand Down Expand Up @@ -105,6 +106,25 @@ trait DefaultPluginDef extends RudderPluginDef {
}
</div>
)

/*
* By default, the plugin can provide a menu entry and it is added under the
* "Plugins" menu. Override that method if you want a more potent
* interaction with Rudder menu (at the risk of breaking it).
*/
def pluginMenuEntry: Option[Menu] = None

override def updateSiteMap(menus:List[Menu]) : List[Menu] = {
pluginMenuEntry match {
case None => menus
case Some(menu) =>
menus.map {
case m@Menu(l, _* ) if(l.name == "PluginsHome") =>
Menu(l , (m.kids.toSeq :+ menu):_* )
case m => m
}
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@
*************************************************************************************
*/

package com.normation.rudder.web.snippet.index
package com.normation.rudder.web.snippet

//lift std import
import scala.xml._
import net.liftweb.http._
import com.normation.rudder.web.model.CurrentUser
import com.normation.rudder.AuthorizationType
import bootstrap.liftweb.RudderConfig
import com.normation.rudder.AuthorizationType
import com.normation.rudder.web.model.CurrentUser
import net.liftweb.http._

import scala.xml._

/**
* Manage redirection for Utilities home page
* Manage redirection for index pages
*/
class Utilities {
class Index {

def index(xhtml:NodeSeq) : NodeSeq = {
def utilities(xhtml:NodeSeq) : NodeSeq = {
if ( CurrentUser.checkRights(AuthorizationType.Administration.Read) ) {
S.redirectTo("eventLogs")
} else {
Expand All @@ -67,4 +68,27 @@ class Utilities {
}
}
}

def administration(xhtml:NodeSeq) : NodeSeq = {
if ( CurrentUser.checkRights(AuthorizationType.Administration.Read) ) {
S.redirectTo("policyServerManagement")
} else {
if ( CurrentUser.checkRights(AuthorizationType.Technique.Read) ) {
S.redirectTo("techniqueLibraryManagement")
} else {
S.redirectTo("/secure/index")
}
}
}

def nodeManager(xhtml:NodeSeq) : NodeSeq = {
S.redirectTo("nodes")
}
def configurationManager(xhtml:NodeSeq) : NodeSeq = {
S.redirectTo("ruleManagement")
}

def plugins(xhtml:NodeSeq) : NodeSeq = {
S.redirectTo("pluginInformation")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class EditPolicyServerAllowedNetwork extends DispatchSnippet with Loggable {

def errorMessage(htmlId: String, b:EmptyBox) = {
val error = b ?~! "Error when processing allowed network"
logger.debug(error.messageChain, b)
logger.error(error.messageChain, b)

s"${htmlId} *" #> { (x:NodeSeq) =>
<div class="error">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ class PluginManagement extends DispatchSnippet with Loggable {

def display(xml:NodeSeq) : NodeSeq = {
(
".portlet *" #> PluginsInfo.plugins.map { case(name,pluginDef) =>
".inner-portlet *" #> PluginsInfo.plugins.map { case(name,pluginDef) =>
displayPlugin(pluginDef) _
}
).apply(xml)
}

private[this] def displayPlugin(p:RudderPluginDef)(xml:NodeSeq) : NodeSeq = {
(
".page-title *" #> p.displayName &
"#pluginId" #> (p.name.value + ": " + p.id) &
"#pluginVersion" #> p.version.toString &
"#pluginDescription" #> p.description &
"#pluginStatusInformation" #> p.statusInformation
"data-plugin=name *" #> p.displayName &
"data-plugin=id" #> (p.name.value + ": " + p.id) &
"data-plugin=version" #> p.version.toString &
"data-plugin=description" #> p.description &
"data-plugin=statusInformation" #> p.statusInformation
)(xml)
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4f889ee

Please sign in to comment.