Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
9eccb4e7
Commit
9eccb4e7
authored
Jun 09, 2017
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: API - add dash permission
parent
bc6aa744
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
8 deletions
+39
-8
pkg/api/api.go
+1
-0
pkg/api/dashboard_acl.go
+20
-0
pkg/metrics/metrics.go
+2
-0
pkg/models/dashboard_acl.go
+12
-7
pkg/services/sqlstore/dashboard_acl.go
+4
-1
No files found.
pkg/api/api.go
View file @
9eccb4e7
...
@@ -250,6 +250,7 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -250,6 +250,7 @@ func (hs *HttpServer) registerRoutes() {
r
.
Group
(
"/:id/acl"
,
func
()
{
r
.
Group
(
"/:id/acl"
,
func
()
{
r
.
Get
(
"/"
,
wrap
(
GetDashboardAcl
))
r
.
Get
(
"/"
,
wrap
(
GetDashboardAcl
))
r
.
Post
(
"/"
,
quota
(
"acl"
),
bind
(
m
.
AddOrUpdateDashboardPermissionCommand
{}),
wrap
(
PostDashboardAcl
))
r
.
Delete
(
"/user/:userId"
,
wrap
(
DeleteDashboardAclByUser
))
r
.
Delete
(
"/user/:userId"
,
wrap
(
DeleteDashboardAclByUser
))
r
.
Delete
(
"/user-group/:userGroupId"
,
wrap
(
DeleteDashboardAclByUserGroup
))
r
.
Delete
(
"/user-group/:userGroupId"
,
wrap
(
DeleteDashboardAclByUserGroup
))
},
reqSignedIn
)
},
reqSignedIn
)
...
...
pkg/api/dashboard_acl.go
View file @
9eccb4e7
...
@@ -2,6 +2,7 @@ package api
...
@@ -2,6 +2,7 @@ package api
import
(
import
(
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/middleware"
m
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/guardian"
"github.com/grafana/grafana/pkg/services/guardian"
...
@@ -30,6 +31,25 @@ func GetDashboardAcl(c *middleware.Context) Response {
...
@@ -30,6 +31,25 @@ func GetDashboardAcl(c *middleware.Context) Response {
return
Json
(
200
,
&
query
.
Result
)
return
Json
(
200
,
&
query
.
Result
)
}
}
func
PostDashboardAcl
(
c
*
middleware
.
Context
,
cmd
m
.
AddOrUpdateDashboardPermissionCommand
)
Response
{
cmd
.
OrgId
=
c
.
OrgId
cmd
.
DashboardId
=
c
.
ParamsInt64
(
":id"
)
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrDashboardPermissionAlreadyAdded
{
return
ApiError
(
409
,
"Permission for user/user group already exists"
,
err
)
}
return
ApiError
(
500
,
"Failed to create permission"
,
err
)
}
metrics
.
M_Api_Dashboard_Acl_Create
.
Inc
(
1
)
return
Json
(
200
,
&
util
.
DynMap
{
"permissionId"
:
cmd
.
Result
.
Id
,
"message"
:
"Permission created"
,
})
}
func
DeleteDashboardAclByUser
(
c
*
middleware
.
Context
)
Response
{
func
DeleteDashboardAclByUser
(
c
*
middleware
.
Context
)
Response
{
dashboardId
:=
c
.
ParamsInt64
(
":id"
)
dashboardId
:=
c
.
ParamsInt64
(
":id"
)
userId
:=
c
.
ParamsInt64
(
":userId"
)
userId
:=
c
.
ParamsInt64
(
":userId"
)
...
...
pkg/metrics/metrics.go
View file @
9eccb4e7
...
@@ -36,6 +36,7 @@ var (
...
@@ -36,6 +36,7 @@ var (
M_Api_Dashboard_Snapshot_External
Counter
M_Api_Dashboard_Snapshot_External
Counter
M_Api_Dashboard_Snapshot_Get
Counter
M_Api_Dashboard_Snapshot_Get
Counter
M_Api_UserGroup_Create
Counter
M_Api_UserGroup_Create
Counter
M_Api_Dashboard_Acl_Create
Counter
M_Models_Dashboard_Insert
Counter
M_Models_Dashboard_Insert
Counter
M_Alerting_Result_State_Alerting
Counter
M_Alerting_Result_State_Alerting
Counter
M_Alerting_Result_State_Ok
Counter
M_Alerting_Result_State_Ok
Counter
...
@@ -94,6 +95,7 @@ func initMetricVars(settings *MetricSettings) {
...
@@ -94,6 +95,7 @@ func initMetricVars(settings *MetricSettings) {
M_Api_User_SignUpInvite
=
RegCounter
(
"api.user.signup_invite"
)
M_Api_User_SignUpInvite
=
RegCounter
(
"api.user.signup_invite"
)
M_Api_UserGroup_Create
=
RegCounter
(
"api.usergroup.create"
)
M_Api_UserGroup_Create
=
RegCounter
(
"api.usergroup.create"
)
M_Api_Dashboard_Acl_Create
=
RegCounter
(
"api.dashboard.acl.create"
)
M_Api_Dashboard_Save
=
RegTimer
(
"api.dashboard.save"
)
M_Api_Dashboard_Save
=
RegTimer
(
"api.dashboard.save"
)
M_Api_Dashboard_Get
=
RegTimer
(
"api.dashboard.get"
)
M_Api_Dashboard_Get
=
RegTimer
(
"api.dashboard.get"
)
...
...
pkg/models/dashboard_acl.go
View file @
9eccb4e7
package
models
package
models
import
"time"
import
(
"errors"
"time"
)
type
PermissionType
int
type
PermissionType
int
const
(
const
(
PERMISSION_
EDIT
PermissionType
=
1
<<
iota
PERMISSION_
VIEW
PermissionType
=
1
<<
iota
PERMISSION_READ_ONLY_EDIT
PERMISSION_READ_ONLY_EDIT
PERMISSION_
VIEW
PERMISSION_
EDIT
)
)
func
(
p
PermissionType
)
String
()
string
{
func
(
p
PermissionType
)
String
()
string
{
...
@@ -20,9 +23,9 @@ func (p PermissionType) String() string {
...
@@ -20,9 +23,9 @@ func (p PermissionType) String() string {
}
}
// Typed errors
// Typed errors
//
var (
var
(
// ErrDashboardPermissionAlreadyAdded = errors.New("A permission has
")
ErrDashboardPermissionAlreadyAdded
=
errors
.
New
(
"A permission for this user/user group already exists.
"
)
//
)
)
// Dashboard ACL model
// Dashboard ACL model
type
DashboardAcl
struct
{
type
DashboardAcl
struct
{
...
@@ -60,11 +63,13 @@ type DashboardAclInfoDTO struct {
...
@@ -60,11 +63,13 @@ type DashboardAclInfoDTO struct {
//
//
type
AddOrUpdateDashboardPermissionCommand
struct
{
type
AddOrUpdateDashboardPermissionCommand
struct
{
DashboardId
int64
`json:"
dashboardId" binding:"Required
"`
DashboardId
int64
`json:"
-
"`
OrgId
int64
`json:"-"`
OrgId
int64
`json:"-"`
UserId
int64
`json:"userId"`
UserId
int64
`json:"userId"`
UserGroupId
int64
`json:"userGroupId"`
UserGroupId
int64
`json:"userGroupId"`
PermissionType
PermissionType
`json:"permissionType" binding:"Required"`
PermissionType
PermissionType
`json:"permissionType" binding:"Required"`
Result
DashboardAcl
`json:"-"`
}
}
type
RemoveDashboardPermissionCommand
struct
{
type
RemoveDashboardPermissionCommand
struct
{
...
...
pkg/services/sqlstore/dashboard_acl.go
View file @
9eccb4e7
...
@@ -51,11 +51,14 @@ func AddOrUpdateDashboardPermission(cmd *m.AddOrUpdateDashboardPermissionCommand
...
@@ -51,11 +51,14 @@ func AddOrUpdateDashboardPermission(cmd *m.AddOrUpdateDashboardPermissionCommand
cols
=
append
(
cols
,
"user_group_id"
)
cols
=
append
(
cols
,
"user_group_id"
)
}
}
_
,
err
:=
sess
.
Cols
(
cols
...
)
.
Insert
(
&
entity
)
entityId
,
err
:=
sess
.
Cols
(
cols
...
)
.
Insert
(
&
entity
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
cmd
.
Result
=
entity
cmd
.
Result
.
Id
=
entityId
// Update dashboard HasAcl flag
dashboard
:=
m
.
Dashboard
{
dashboard
:=
m
.
Dashboard
{
HasAcl
:
true
,
HasAcl
:
true
,
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment