mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Hide plugins page from viewers, and limit /api/plugins to only core plugins when called by viewer role (#21901)
* Hide plugins list from viewers * Made /api/plugins only return core plugins for users with viewer role Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
parent
935ec07cfd
commit
f345d7f6a3
@ -297,6 +297,7 @@ func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewDat
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.OrgRole == models.ROLE_ADMIN {
|
||||||
configNodes = append(configNodes, &dtos.NavLink{
|
configNodes = append(configNodes, &dtos.NavLink{
|
||||||
Text: "Plugins",
|
Text: "Plugins",
|
||||||
Id: "plugins",
|
Id: "plugins",
|
||||||
@ -305,7 +306,6 @@ func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewDat
|
|||||||
Url: setting.AppSubUrl + "/plugins",
|
Url: setting.AppSubUrl + "/plugins",
|
||||||
})
|
})
|
||||||
|
|
||||||
if c.OrgRole == models.ROLE_ADMIN {
|
|
||||||
configNodes = append(configNodes, &dtos.NavLink{
|
configNodes = append(configNodes, &dtos.NavLink{
|
||||||
Text: "Preferences",
|
Text: "Preferences",
|
||||||
Id: "org-settings",
|
Id: "org-settings",
|
||||||
@ -322,6 +322,7 @@ func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewDat
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(configNodes) > 0 {
|
||||||
data.NavTree = append(data.NavTree, &dtos.NavLink{
|
data.NavTree = append(data.NavTree, &dtos.NavLink{
|
||||||
Id: "cfg",
|
Id: "cfg",
|
||||||
Text: "Configuration",
|
Text: "Configuration",
|
||||||
@ -331,6 +332,7 @@ func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewDat
|
|||||||
SortWeight: dtos.WeightConfig,
|
SortWeight: dtos.WeightConfig,
|
||||||
Children: configNodes,
|
Children: configNodes,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if c.IsGrafanaAdmin {
|
if c.IsGrafanaAdmin {
|
||||||
adminNavLinks := []*dtos.NavLink{
|
adminNavLinks := []*dtos.NavLink{
|
||||||
|
@ -57,6 +57,11 @@ func (hs *HTTPServer) GetPluginList(c *models.ReqContext) Response {
|
|||||||
embeddedFilter := c.Query("embedded")
|
embeddedFilter := c.Query("embedded")
|
||||||
coreFilter := c.Query("core")
|
coreFilter := c.Query("core")
|
||||||
|
|
||||||
|
// For users with viewer role we only return core plugins
|
||||||
|
if !c.HasRole(models.ROLE_ADMIN) {
|
||||||
|
coreFilter = "1"
|
||||||
|
}
|
||||||
|
|
||||||
pluginSettingsMap, err := plugins.GetPluginSettings(c.OrgId)
|
pluginSettingsMap, err := plugins.GetPluginSettings(c.OrgId)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -71,7 +76,7 @@ func (hs *HTTPServer) GetPluginList(c *models.ReqContext) Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// filter out core plugins
|
// filter out core plugins
|
||||||
if coreFilter == "0" && pluginDef.IsCorePlugin {
|
if (coreFilter == "0" && pluginDef.IsCorePlugin) || (coreFilter == "1" && !pluginDef.IsCorePlugin) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user