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
fff7b706
Commit
fff7b706
authored
May 22, 2017
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: user group additions
parent
53d11d50
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
6 deletions
+36
-6
pkg/models/user_group.go
+5
-0
pkg/services/sqlstore/user_group.go
+16
-0
pkg/services/sqlstore/user_group_test.go
+11
-0
public/app/features/org/partials/user_groups.html
+2
-4
public/app/features/org/user_groups_ctrl.ts
+2
-2
No files found.
pkg/models/user_group.go
View file @
fff7b706
...
...
@@ -45,6 +45,11 @@ type GetUserGroupByIdQuery struct {
Result
*
UserGroup
}
type
GetUserGroupsByUserQuery
struct
{
UserId
int64
`json:"userId"`
Result
[]
*
UserGroup
`json:"userGroups"`
}
type
SearchUserGroupsQuery
struct
{
Query
string
Name
string
...
...
pkg/services/sqlstore/user_group.go
View file @
fff7b706
...
...
@@ -16,6 +16,7 @@ func init() {
bus
.
AddHandler
(
"sql"
,
DeleteUserGroup
)
bus
.
AddHandler
(
"sql"
,
SearchUserGroups
)
bus
.
AddHandler
(
"sql"
,
GetUserGroupById
)
bus
.
AddHandler
(
"sql"
,
GetUserGroupsByUser
)
bus
.
AddHandler
(
"sql"
,
AddUserGroupMember
)
bus
.
AddHandler
(
"sql"
,
RemoveUserGroupMember
)
...
...
@@ -162,6 +163,21 @@ func GetUserGroupById(query *m.GetUserGroupByIdQuery) error {
return
nil
}
func
GetUserGroupsByUser
(
query
*
m
.
GetUserGroupsByUserQuery
)
error
{
query
.
Result
=
make
([]
*
m
.
UserGroup
,
0
)
sess
:=
x
.
Table
(
"user_group"
)
sess
.
Join
(
"INNER"
,
"user_group_member"
,
"user_group.id=user_group_member.user_group_id"
)
sess
.
Where
(
"user_group_member.user_id=?"
,
query
.
UserId
)
err
:=
sess
.
Find
(
&
query
.
Result
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
AddUserGroupMember
(
cmd
*
m
.
AddUserGroupMemberCommand
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
if
res
,
err
:=
sess
.
Query
(
"SELECT 1 from user_group_member WHERE user_group_id=? and user_id=?"
,
cmd
.
UserGroupId
,
cmd
.
UserId
);
err
!=
nil
{
...
...
pkg/services/sqlstore/user_group_test.go
View file @
fff7b706
...
...
@@ -67,6 +67,17 @@ func TestUserGroupCommandsAndQueries(t *testing.T) {
So
(
len
(
query2
.
Result
.
UserGroups
),
ShouldEqual
,
2
)
})
Convey
(
"Should be able to return all user groups a user is member of"
,
func
()
{
groupId
:=
group2
.
Result
.
Id
err
:=
AddUserGroupMember
(
&
m
.
AddUserGroupMemberCommand
{
OrgId
:
1
,
UserGroupId
:
groupId
,
UserId
:
userIds
[
0
]})
query
:=
&
m
.
GetUserGroupsByUserQuery
{
UserId
:
userIds
[
0
]}
err
=
GetUserGroupsByUser
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
So
(
query
.
Result
[
0
]
.
Name
,
ShouldEqual
,
"group2 name"
)
})
Convey
(
"Should be able to remove users from a group"
,
func
()
{
err
=
RemoveUserGroupMember
(
&
m
.
RemoveUserGroupMemberCommand
{
UserGroupId
:
group1
.
Result
.
Id
,
UserId
:
userIds
[
0
]})
So
(
err
,
ShouldBeNil
)
...
...
public/app/features/org/partials/user_groups.html
View file @
fff7b706
...
...
@@ -5,12 +5,10 @@
<div
class=
"page-header"
>
<h1>
User Groups
</h1>
<div
class=
"page-header-tabs"
>
<button
class=
"btn btn-success"
ng-click=
"ctrl.openModal()"
>
<a
class=
"btn btn-success"
ng-click=
"ctrl.openUserGroupModal()"
>
<i
class=
"fa fa-plus"
></i>
Create User Group
</button>
</div>
</a>
</div>
<div
class=
"search-field-wrapper pull-right width-18"
>
<span
style=
"position: relative;"
>
...
...
public/app/features/org/user_groups_ctrl.ts
View file @
fff7b706
...
...
@@ -63,14 +63,14 @@ export default class UserGroupsCtrl {
.
then
(
this
.
get
.
bind
(
this
));
}
openModal
()
{
open
UserGroup
Modal
()
{
var
modalScope
=
this
.
$scope
.
$new
();
modalScope
.
createUserGroup
=
this
.
createUserGroup
.
bind
(
this
);
this
.
$scope
.
appEvent
(
'show-modal'
,
{
src
:
'public/app/features/org/partials/create_user_group.html'
,
modalClass
:
'user-group-modal'
,
scope
:
this
.
$s
cope
scope
:
modalS
cope
});
}
}
...
...
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