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
9a6446c2
Unverified
Commit
9a6446c2
authored
Sep 14, 2018
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new column for team_member table
parent
270b7363
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
23 deletions
+57
-23
pkg/api/team_members.go
+6
-0
pkg/models/team_member.go
+22
-17
pkg/services/sqlstore/migrations/team_mig.go
+3
-0
pkg/services/sqlstore/team.go
+10
-6
pkg/services/sqlstore/team_test.go
+16
-0
No files found.
pkg/api/team_members.go
View file @
9a6446c2
...
...
@@ -4,6 +4,7 @@ import (
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/bus"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
)
...
...
@@ -17,6 +18,11 @@ func GetTeamMembers(c *m.ReqContext) Response {
for
_
,
member
:=
range
query
.
Result
{
member
.
AvatarUrl
=
dtos
.
GetGravatarUrl
(
member
.
Email
)
member
.
Labels
=
[]
string
{}
if
setting
.
IsEnterprise
&&
setting
.
LdapEnabled
&&
member
.
External
{
member
.
Labels
=
append
(
member
.
Labels
,
"LDAP"
)
}
}
return
JSON
(
200
,
query
.
Result
)
...
...
pkg/models/team_member.go
View file @
9a6446c2
...
...
@@ -12,10 +12,11 @@ var (
// TeamMember model
type
TeamMember
struct
{
Id
int64
OrgId
int64
TeamId
int64
UserId
int64
Id
int64
OrgId
int64
TeamId
int64
UserId
int64
External
bool
Created
time
.
Time
Updated
time
.
Time
...
...
@@ -25,9 +26,10 @@ type TeamMember struct {
// COMMANDS
type
AddTeamMemberCommand
struct
{
UserId
int64
`json:"userId" binding:"Required"`
OrgId
int64
`json:"-"`
TeamId
int64
`json:"-"`
UserId
int64
`json:"userId" binding:"Required"`
OrgId
int64
`json:"-"`
TeamId
int64
`json:"-"`
External
bool
`json:"-"`
}
type
RemoveTeamMemberCommand
struct
{
...
...
@@ -40,20 +42,23 @@ type RemoveTeamMemberCommand struct {
// QUERIES
type
GetTeamMembersQuery
struct
{
OrgId
int64
TeamId
int64
UserId
int64
Result
[]
*
TeamMemberDTO
OrgId
int64
TeamId
int64
UserId
int64
External
bool
Result
[]
*
TeamMemberDTO
}
// ----------------------
// Projections and DTOs
type
TeamMemberDTO
struct
{
OrgId
int64
`json:"orgId"`
TeamId
int64
`json:"teamId"`
UserId
int64
`json:"userId"`
Email
string
`json:"email"`
Login
string
`json:"login"`
AvatarUrl
string
`json:"avatarUrl"`
OrgId
int64
`json:"orgId"`
TeamId
int64
`json:"teamId"`
UserId
int64
`json:"userId"`
External
bool
`json:"-"`
Email
string
`json:"email"`
Login
string
`json:"login"`
AvatarUrl
string
`json:"avatarUrl"`
Labels
[]
string
`json:"labels"`
}
pkg/services/sqlstore/migrations/team_mig.go
View file @
9a6446c2
...
...
@@ -51,4 +51,7 @@ func addTeamMigrations(mg *Migrator) {
Name
:
"email"
,
Type
:
DB_NVarchar
,
Nullable
:
true
,
Length
:
190
,
}))
mg
.
AddMigration
(
"Add column external to team_member table"
,
NewAddColumnMigration
(
teamMemberV1
,
&
Column
{
Name
:
"external"
,
Type
:
DB_Bool
,
Nullable
:
true
,
}))
}
pkg/services/sqlstore/team.go
View file @
9a6446c2
...
...
@@ -240,11 +240,12 @@ func AddTeamMember(cmd *m.AddTeamMemberCommand) error {
}
entity
:=
m
.
TeamMember
{
OrgId
:
cmd
.
OrgId
,
TeamId
:
cmd
.
TeamId
,
UserId
:
cmd
.
UserId
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
OrgId
:
cmd
.
OrgId
,
TeamId
:
cmd
.
TeamId
,
UserId
:
cmd
.
UserId
,
External
:
cmd
.
External
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
}
_
,
err
:=
sess
.
Insert
(
&
entity
)
...
...
@@ -289,7 +290,10 @@ func GetTeamMembers(query *m.GetTeamMembersQuery) error {
if
query
.
UserId
!=
0
{
sess
.
Where
(
"team_member.user_id=?"
,
query
.
UserId
)
}
sess
.
Cols
(
"user.org_id"
,
"team_member.team_id"
,
"team_member.user_id"
,
"user.email"
,
"user.login"
)
if
query
.
External
{
sess
.
Where
(
"team_member.external=?"
,
dialect
.
BooleanStr
(
true
))
}
sess
.
Cols
(
"team_member.org_id"
,
"team_member.team_id"
,
"team_member.user_id"
,
"user.email"
,
"user.login"
,
"team_member.external"
)
sess
.
Asc
(
"user.login"
,
"user.email"
)
err
:=
sess
.
Find
(
&
query
.
Result
)
...
...
pkg/services/sqlstore/team_test.go
View file @
9a6446c2
...
...
@@ -50,13 +50,29 @@ func TestTeamCommandsAndQueries(t *testing.T) {
err
=
AddTeamMember
(
&
m
.
AddTeamMemberCommand
{
OrgId
:
testOrgId
,
TeamId
:
team1
.
Id
,
UserId
:
userIds
[
0
]})
So
(
err
,
ShouldBeNil
)
err
=
AddTeamMember
(
&
m
.
AddTeamMemberCommand
{
OrgId
:
testOrgId
,
TeamId
:
team1
.
Id
,
UserId
:
userIds
[
1
],
External
:
true
})
So
(
err
,
ShouldBeNil
)
q1
:=
&
m
.
GetTeamMembersQuery
{
OrgId
:
testOrgId
,
TeamId
:
team1
.
Id
}
err
=
GetTeamMembers
(
q1
)
So
(
err
,
ShouldBeNil
)
So
(
q1
.
Result
,
ShouldHaveLength
,
2
)
So
(
q1
.
Result
[
0
]
.
TeamId
,
ShouldEqual
,
team1
.
Id
)
So
(
q1
.
Result
[
0
]
.
Login
,
ShouldEqual
,
"loginuser0"
)
So
(
q1
.
Result
[
0
]
.
OrgId
,
ShouldEqual
,
testOrgId
)
So
(
q1
.
Result
[
1
]
.
TeamId
,
ShouldEqual
,
team1
.
Id
)
So
(
q1
.
Result
[
1
]
.
Login
,
ShouldEqual
,
"loginuser1"
)
So
(
q1
.
Result
[
1
]
.
OrgId
,
ShouldEqual
,
testOrgId
)
So
(
q1
.
Result
[
1
]
.
External
,
ShouldEqual
,
true
)
q2
:=
&
m
.
GetTeamMembersQuery
{
OrgId
:
testOrgId
,
TeamId
:
team1
.
Id
,
External
:
true
}
err
=
GetTeamMembers
(
q2
)
So
(
err
,
ShouldBeNil
)
So
(
q2
.
Result
,
ShouldHaveLength
,
1
)
So
(
q2
.
Result
[
0
]
.
TeamId
,
ShouldEqual
,
team1
.
Id
)
So
(
q2
.
Result
[
0
]
.
Login
,
ShouldEqual
,
"loginuser1"
)
So
(
q2
.
Result
[
0
]
.
OrgId
,
ShouldEqual
,
testOrgId
)
So
(
q2
.
Result
[
0
]
.
External
,
ShouldEqual
,
true
)
})
Convey
(
"Should be able to search for teams"
,
func
()
{
...
...
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