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
55293503
Commit
55293503
authored
Apr 19, 2017
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: API methods for add/remove members to user group
parent
0a1df090
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
2 deletions
+31
-2
pkg/api/api.go
+3
-1
pkg/api/user_group_members.go
+26
-0
pkg/models/user_group_member.go
+1
-1
pkg/services/sqlstore/user_group.go
+1
-0
No files found.
pkg/api/api.go
View file @
55293503
...
@@ -140,7 +140,9 @@ func (hs *HttpServer) registerRoutes() {
...
@@ -140,7 +140,9 @@ func (hs *HttpServer) registerRoutes() {
r
.
Put
(
"/:userGroupId"
,
bind
(
m
.
UpdateUserGroupCommand
{}),
wrap
(
UpdateUserGroup
))
r
.
Put
(
"/:userGroupId"
,
bind
(
m
.
UpdateUserGroupCommand
{}),
wrap
(
UpdateUserGroup
))
r
.
Delete
(
"/:userGroupId"
,
wrap
(
DeleteUserGroupById
))
r
.
Delete
(
"/:userGroupId"
,
wrap
(
DeleteUserGroupById
))
r
.
Get
(
"/:userGroupId/members"
,
wrap
(
GetUserGroupMembers
))
r
.
Get
(
"/:userGroupId/members"
,
wrap
(
GetUserGroupMembers
))
},
reqGrafanaAdmin
)
r
.
Post
(
"/:userGroupId/members"
,
quota
(
"user-groups"
),
bind
(
m
.
AddUserGroupMemberCommand
{}),
wrap
(
AddUserGroupMember
))
r
.
Delete
(
"/:userGroupId/members/:userId"
,
wrap
(
RemoveUserGroupMember
))
},
reqOrgAdmin
)
// org information available to all users.
// org information available to all users.
r
.
Group
(
"/org"
,
func
()
{
r
.
Group
(
"/org"
,
func
()
{
...
...
pkg/api/user_group_members.go
View file @
55293503
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
"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/util"
)
)
// GET /api/user-groups/:userGroupId/members
// GET /api/user-groups/:userGroupId/members
...
@@ -16,3 +17,28 @@ func GetUserGroupMembers(c *middleware.Context) Response {
...
@@ -16,3 +17,28 @@ func GetUserGroupMembers(c *middleware.Context) Response {
return
Json
(
200
,
query
.
Result
)
return
Json
(
200
,
query
.
Result
)
}
}
// POST /api/user-groups/:userGroupId/members
func
AddUserGroupMember
(
c
*
middleware
.
Context
,
cmd
m
.
AddUserGroupMemberCommand
)
Response
{
cmd
.
UserGroupId
=
c
.
ParamsInt64
(
":userGroupId"
)
cmd
.
OrgId
=
c
.
OrgId
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrUserGroupMemberAlreadyAdded
{
return
ApiError
(
400
,
"User is already added to this user group"
,
err
)
}
return
ApiError
(
500
,
"Failed to add Member to User Group"
,
err
)
}
return
Json
(
200
,
&
util
.
DynMap
{
"message"
:
"Member added to User Group"
,
})
}
// DELETE /api/user-groups/:userGroupId/members/:userId
func
RemoveUserGroupMember
(
c
*
middleware
.
Context
)
Response
{
if
err
:=
bus
.
Dispatch
(
&
m
.
RemoveUserGroupMemberCommand
{
UserGroupId
:
c
.
ParamsInt64
(
":userGroupId"
),
UserId
:
c
.
ParamsInt64
(
":userId"
)});
err
!=
nil
{
return
ApiError
(
500
,
"Failed to remove Member from User Group"
,
err
)
}
return
ApiSuccess
(
"User Group Member removed"
)
}
pkg/models/user_group_member.go
View file @
55293503
...
@@ -25,9 +25,9 @@ type UserGroupMember struct {
...
@@ -25,9 +25,9 @@ type UserGroupMember struct {
// COMMANDS
// COMMANDS
type
AddUserGroupMemberCommand
struct
{
type
AddUserGroupMemberCommand
struct
{
UserId
int64
`json:"userId" binding:"Required"`
OrgId
int64
`json:"-"`
OrgId
int64
`json:"-"`
UserGroupId
int64
`json:"-"`
UserGroupId
int64
`json:"-"`
UserId
int64
`json:"-"`
}
}
type
RemoveUserGroupMemberCommand
struct
{
type
RemoveUserGroupMemberCommand
struct
{
...
...
pkg/services/sqlstore/user_group.go
View file @
55293503
...
@@ -33,6 +33,7 @@ func CreateUserGroup(cmd *m.CreateUserGroupCommand) error {
...
@@ -33,6 +33,7 @@ func CreateUserGroup(cmd *m.CreateUserGroupCommand) error {
userGroup
:=
m
.
UserGroup
{
userGroup
:=
m
.
UserGroup
{
Name
:
cmd
.
Name
,
Name
:
cmd
.
Name
,
OrgId
:
cmd
.
OrgId
,
Created
:
time
.
Now
(),
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
Updated
:
time
.
Now
(),
}
}
...
...
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