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
0a1df090
Commit
0a1df090
authored
Apr 18, 2017
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: add update user group command
parent
00ac446b
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
0 deletions
+83
-0
pkg/api/api.go
+3
-0
pkg/api/user_group.go
+28
-0
pkg/api/user_group_members.go
+18
-0
pkg/models/user_group.go
+5
-0
pkg/services/sqlstore/user_group.go
+29
-0
No files found.
pkg/api/api.go
View file @
0a1df090
...
@@ -134,9 +134,12 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -134,9 +134,12 @@ func (hs *HttpServer) registerRoutes() {
// user group (admin permission required)
// user group (admin permission required)
r
.
Group
(
"/user-groups"
,
func
()
{
r
.
Group
(
"/user-groups"
,
func
()
{
r
.
Get
(
"/:userGroupId"
,
wrap
(
GetUserGroupById
))
r
.
Get
(
"/search"
,
wrap
(
SearchUserGroups
))
r
.
Get
(
"/search"
,
wrap
(
SearchUserGroups
))
r
.
Post
(
"/"
,
quota
(
"user-groups"
),
bind
(
m
.
CreateUserGroupCommand
{}),
wrap
(
CreateUserGroup
))
r
.
Post
(
"/"
,
quota
(
"user-groups"
),
bind
(
m
.
CreateUserGroupCommand
{}),
wrap
(
CreateUserGroup
))
r
.
Put
(
"/:userGroupId"
,
bind
(
m
.
UpdateUserGroupCommand
{}),
wrap
(
UpdateUserGroup
))
r
.
Delete
(
"/:userGroupId"
,
wrap
(
DeleteUserGroupById
))
r
.
Delete
(
"/:userGroupId"
,
wrap
(
DeleteUserGroupById
))
r
.
Get
(
"/:userGroupId/members"
,
wrap
(
GetUserGroupMembers
))
},
reqGrafanaAdmin
)
},
reqGrafanaAdmin
)
// org information available to all users.
// org information available to all users.
...
...
pkg/api/user_group.go
View file @
0a1df090
...
@@ -26,6 +26,19 @@ func CreateUserGroup(c *middleware.Context, cmd m.CreateUserGroupCommand) Respon
...
@@ -26,6 +26,19 @@ func CreateUserGroup(c *middleware.Context, cmd m.CreateUserGroupCommand) Respon
})
})
}
}
// PUT /api/user-groups/:userGroupId
func
UpdateUserGroup
(
c
*
middleware
.
Context
,
cmd
m
.
UpdateUserGroupCommand
)
Response
{
cmd
.
Id
=
c
.
ParamsInt64
(
":userGroupId"
)
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrUserGroupNameTaken
{
return
ApiError
(
400
,
"User Group name taken"
,
err
)
}
return
ApiError
(
500
,
"Failed to update User Group"
,
err
)
}
return
ApiSuccess
(
"User Group updated"
)
}
// DELETE /api/user-groups/:userGroupId
// DELETE /api/user-groups/:userGroupId
func
DeleteUserGroupById
(
c
*
middleware
.
Context
)
Response
{
func
DeleteUserGroupById
(
c
*
middleware
.
Context
)
Response
{
if
err
:=
bus
.
Dispatch
(
&
m
.
DeleteUserGroupCommand
{
Id
:
c
.
ParamsInt64
(
":userGroupId"
)});
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
m
.
DeleteUserGroupCommand
{
Id
:
c
.
ParamsInt64
(
":userGroupId"
)});
err
!=
nil
{
...
@@ -64,3 +77,18 @@ func SearchUserGroups(c *middleware.Context) Response {
...
@@ -64,3 +77,18 @@ func SearchUserGroups(c *middleware.Context) Response {
return
Json
(
200
,
query
.
Result
)
return
Json
(
200
,
query
.
Result
)
}
}
// GET /api/user-groups/:userGroupId
func
GetUserGroupById
(
c
*
middleware
.
Context
)
Response
{
query
:=
m
.
GetUserGroupByIdQuery
{
Id
:
c
.
ParamsInt64
(
":userGroupId"
)}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
==
m
.
ErrUserGroupNotFound
{
return
ApiError
(
404
,
"User Group not found"
,
err
)
}
return
ApiError
(
500
,
"Failed to get User Group"
,
err
)
}
return
Json
(
200
,
&
query
.
Result
)
}
pkg/api/user_group_members.go
0 → 100644
View file @
0a1df090
package
api
import
(
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/middleware"
m
"github.com/grafana/grafana/pkg/models"
)
// GET /api/user-groups/:userGroupId/members
func
GetUserGroupMembers
(
c
*
middleware
.
Context
)
Response
{
query
:=
m
.
GetUserGroupMembersQuery
{
UserGroupId
:
c
.
ParamsInt64
(
":userGroupId"
)}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to get User Group Members"
,
err
)
}
return
Json
(
200
,
query
.
Result
)
}
pkg/models/user_group.go
View file @
0a1df090
...
@@ -31,6 +31,11 @@ type CreateUserGroupCommand struct {
...
@@ -31,6 +31,11 @@ type CreateUserGroupCommand struct {
Result
UserGroup
`json:"-"`
Result
UserGroup
`json:"-"`
}
}
type
UpdateUserGroupCommand
struct
{
Id
int64
Name
string
}
type
DeleteUserGroupCommand
struct
{
type
DeleteUserGroupCommand
struct
{
Id
int64
Id
int64
}
}
...
...
pkg/services/sqlstore/user_group.go
View file @
0a1df090
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
func
init
()
{
func
init
()
{
bus
.
AddHandler
(
"sql"
,
CreateUserGroup
)
bus
.
AddHandler
(
"sql"
,
CreateUserGroup
)
bus
.
AddHandler
(
"sql"
,
UpdateUserGroup
)
bus
.
AddHandler
(
"sql"
,
DeleteUserGroup
)
bus
.
AddHandler
(
"sql"
,
DeleteUserGroup
)
bus
.
AddHandler
(
"sql"
,
SearchUserGroups
)
bus
.
AddHandler
(
"sql"
,
SearchUserGroups
)
bus
.
AddHandler
(
"sql"
,
GetUserGroupById
)
bus
.
AddHandler
(
"sql"
,
GetUserGroupById
)
...
@@ -44,6 +45,34 @@ func CreateUserGroup(cmd *m.CreateUserGroupCommand) error {
...
@@ -44,6 +45,34 @@ func CreateUserGroup(cmd *m.CreateUserGroupCommand) error {
})
})
}
}
func
UpdateUserGroup
(
cmd
*
m
.
UpdateUserGroupCommand
)
error
{
return
inTransaction2
(
func
(
sess
*
session
)
error
{
if
isNameTaken
,
err
:=
isUserGroupNameTaken
(
cmd
.
Name
,
cmd
.
Id
,
sess
);
err
!=
nil
{
return
err
}
else
if
isNameTaken
{
return
m
.
ErrUserGroupNameTaken
}
userGroup
:=
m
.
UserGroup
{
Name
:
cmd
.
Name
,
Updated
:
time
.
Now
(),
}
affectedRows
,
err
:=
sess
.
Id
(
cmd
.
Id
)
.
Update
(
&
userGroup
)
if
err
!=
nil
{
return
err
}
if
affectedRows
==
0
{
return
m
.
ErrUserGroupNotFound
}
return
nil
})
}
func
DeleteUserGroup
(
cmd
*
m
.
DeleteUserGroupCommand
)
error
{
func
DeleteUserGroup
(
cmd
*
m
.
DeleteUserGroupCommand
)
error
{
return
inTransaction2
(
func
(
sess
*
session
)
error
{
return
inTransaction2
(
func
(
sess
*
session
)
error
{
if
res
,
err
:=
sess
.
Query
(
"SELECT 1 from user_group WHERE id=?"
,
cmd
.
Id
);
err
!=
nil
{
if
res
,
err
:=
sess
.
Query
(
"SELECT 1 from user_group WHERE id=?"
,
cmd
.
Id
);
err
!=
nil
{
...
...
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