Commit fff7b706 by Daniel Lee

WIP: user group additions

parent 53d11d50
......@@ -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
......
......@@ -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 {
......
......@@ -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)
......
......@@ -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()">
<i class="fa fa-plus"></i>
Create User Group
</button>
</div>
<a class="btn btn-success" ng-click="ctrl.openUserGroupModal()">
<i class="fa fa-plus"></i>
Create User Group
</a>
</div>
<div class="search-field-wrapper pull-right width-18">
<span style="position: relative;">
......
......@@ -63,14 +63,14 @@ export default class UserGroupsCtrl {
.then(this.get.bind(this));
}
openModal() {
openUserGroupModal() {
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.$scope
scope: modalScope
});
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment