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
6f63d63e
Commit
6f63d63e
authored
Jan 14, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on account collaborators
parent
50a5355d
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
24 deletions
+50
-24
grafana
+1
-1
pkg/api/account.go
+18
-7
pkg/api/api.go
+2
-1
pkg/models/account.go
+2
-2
pkg/models/collaborator.go
+11
-6
pkg/stores/sqlstore/accounts.go
+16
-7
No files found.
grafana
@
961ebbde
Subproject commit
733a9af6294c87acc72d1a519791e2be7d0f594
f
Subproject commit
961ebbde6b6540f03d3fb5a1741722614166099
f
pkg/api/account.go
View file @
6f63d63e
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/middleware"
"github.com/torkelo/grafana-pro/pkg/middleware"
m
"github.com/torkelo/grafana-pro/pkg/models"
m
"github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/util"
)
)
func
GetAccount
(
c
*
middleware
.
Context
)
{
func
GetAccount
(
c
*
middleware
.
Context
)
{
...
@@ -41,8 +40,8 @@ func AddCollaborator(c *middleware.Context) {
...
@@ -41,8 +40,8 @@ func AddCollaborator(c *middleware.Context) {
return
return
}
}
cmd
.
AccountId
=
accountToAdd
.
Id
cmd
.
AccountId
=
c
.
UserAccount
.
Id
cmd
.
ForAccountId
=
c
.
UserAccount
.
Id
cmd
.
CollaboratorId
=
accountToAdd
.
Id
cmd
.
Role
=
m
.
ROLE_READ_WRITE
cmd
.
Role
=
m
.
ROLE_READ_WRITE
err
=
bus
.
Dispatch
(
&
cmd
)
err
=
bus
.
Dispatch
(
&
cmd
)
...
@@ -54,23 +53,35 @@ func AddCollaborator(c *middleware.Context) {
...
@@ -54,23 +53,35 @@ func AddCollaborator(c *middleware.Context) {
c
.
JsonOK
(
"Collaborator added"
)
c
.
JsonOK
(
"Collaborator added"
)
}
}
func
RemoveCollaborator
(
c
*
middleware
.
Context
)
{
collaboratorId
:=
c
.
ParamsInt64
(
":id"
)
cmd
:=
m
.
RemoveCollaboratorCommand
{
AccountId
:
c
.
UserAccount
.
Id
,
CollaboratorId
:
collaboratorId
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to remove collaborator"
,
err
)
}
c
.
JsonOK
(
"Collaborator removed"
)
}
func
GetOtherAccounts
(
c
*
middleware
.
Context
)
{
func
GetOtherAccounts
(
c
*
middleware
.
Context
)
{
query
:=
m
.
GetOtherAccountsQuery
{
AccountId
:
c
.
UserAccount
.
Id
}
query
:=
m
.
GetOtherAccountsQuery
{
AccountId
:
c
.
UserAccount
.
Id
}
err
:=
bus
.
Dispatch
(
&
query
)
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
J
SON
(
500
,
util
.
DynMap
{
"message"
:
err
.
Error
()}
)
c
.
J
sonApiErr
(
500
,
"Failed to get other accounts"
,
err
)
return
return
}
}
result
:=
append
(
query
.
Result
,
&
m
.
OtherAccountDTO
{
result
:=
append
(
query
.
Result
,
&
m
.
OtherAccountDTO
{
Id
:
c
.
UserAccount
.
Id
,
AccountId
:
c
.
UserAccount
.
Id
,
Role
:
"owner"
,
Role
:
"owner"
,
Email
:
c
.
UserAccount
.
Email
,
Email
:
c
.
UserAccount
.
Email
,
})
})
for
_
,
ac
:=
range
result
{
for
_
,
ac
:=
range
result
{
if
ac
.
Id
==
c
.
UserAccount
.
UsingAccountId
{
if
ac
.
Account
Id
==
c
.
UserAccount
.
UsingAccountId
{
ac
.
IsUsing
=
true
ac
.
IsUsing
=
true
break
break
}
}
...
@@ -93,7 +104,7 @@ func validateUsingAccount(accountId int64, otherId int64) bool {
...
@@ -93,7 +104,7 @@ func validateUsingAccount(accountId int64, otherId int64) bool {
// validate that the account id in the list
// validate that the account id in the list
valid
:=
false
valid
:=
false
for
_
,
other
:=
range
query
.
Result
{
for
_
,
other
:=
range
query
.
Result
{
if
other
.
Id
==
otherId
{
if
other
.
Account
Id
==
otherId
{
valid
=
true
valid
=
true
}
}
}
}
...
...
pkg/api/api.go
View file @
6f63d63e
...
@@ -33,7 +33,8 @@ func Register(m *macaron.Macaron) {
...
@@ -33,7 +33,8 @@ func Register(m *macaron.Macaron) {
// account
// account
m
.
Group
(
"/account"
,
func
()
{
m
.
Group
(
"/account"
,
func
()
{
m
.
Get
(
"/"
,
GetAccount
)
m
.
Get
(
"/"
,
GetAccount
)
m
.
Post
(
"/collaborators/add"
,
AddCollaborator
)
m
.
Put
(
"/collaborators"
,
AddCollaborator
)
m
.
Delete
(
"/collaborators/:id"
,
RemoveCollaborator
)
m
.
Post
(
"/using/:id"
,
SetUsingAccount
)
m
.
Post
(
"/using/:id"
,
SetUsingAccount
)
m
.
Get
(
"/others"
,
GetOtherAccounts
)
m
.
Get
(
"/others"
,
GetOtherAccounts
)
})
})
...
...
pkg/models/account.go
View file @
6f63d63e
...
@@ -72,14 +72,14 @@ type GetAccountByLoginQuery struct {
...
@@ -72,14 +72,14 @@ type GetAccountByLoginQuery struct {
// DTO & Projections
// DTO & Projections
type
OtherAccountDTO
struct
{
type
OtherAccountDTO
struct
{
Id
int64
`json:"i
d"`
AccountId
int64
`json:"accountI
d"`
Email
string
`json:"email"`
Email
string
`json:"email"`
Role
string
`json:"role"`
Role
string
`json:"role"`
IsUsing
bool
`json:"isUsing"`
IsUsing
bool
`json:"isUsing"`
}
}
type
CollaboratorDTO
struct
{
type
CollaboratorDTO
struct
{
AccountId
int64
`json:"accountI
d"`
CollaboratorId
int64
`json:"i
d"`
Email
string
`json:"email"`
Email
string
`json:"email"`
Role
string
`json:"role"`
Role
string
`json:"role"`
}
}
...
...
pkg/models/collaborator.go
View file @
6f63d63e
...
@@ -13,25 +13,30 @@ type RoleType string
...
@@ -13,25 +13,30 @@ type RoleType string
type
Collaborator
struct
{
type
Collaborator
struct
{
Id
int64
Id
int64
AccountId
int64
`xorm:"not null unique(uix_account_id_for_account_id)"`
// The account that can use another account
AccountId
int64
`xorm:"not null unique(uix_account_id_for_account_id)"`
Role
RoleType
`xorm:"not null"`
// Permission type
Role
RoleType
`xorm:"not null"`
ForAccountId
int64
`xorm:"not null unique(uix_account_id_for_account_id)"`
// The account being given access to
CollaboratorId
int64
`xorm:"not null unique(uix_account_id_for_account_id)"`
Created
time
.
Time
Created
time
.
Time
Updated
time
.
Time
Updated
time
.
Time
}
}
type
RemoveCollaboratorCommand
struct
{
CollaboratorId
int64
AccountId
int64
}
type
AddCollaboratorCommand
struct
{
type
AddCollaboratorCommand
struct
{
Email
string
`json:"email" binding:"required"`
Email
string
`json:"email" binding:"required"`
AccountId
int64
`json:"-"`
AccountId
int64
`json:"-"`
ForAccount
Id
int64
`json:"-"`
Collaborator
Id
int64
`json:"-"`
Role
RoleType
`json:"-"`
Role
RoleType
`json:"-"`
}
}
func
NewCollaborator
(
accountId
int64
,
forAccount
Id
int64
,
role
RoleType
)
*
Collaborator
{
func
NewCollaborator
(
accountId
int64
,
collaborator
Id
int64
,
role
RoleType
)
*
Collaborator
{
return
&
Collaborator
{
return
&
Collaborator
{
AccountId
:
accountId
,
AccountId
:
accountId
,
ForAccountId
:
forAccount
Id
,
CollaboratorId
:
collaborator
Id
,
Role
:
role
,
Role
:
role
,
Created
:
time
.
Now
(),
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
Updated
:
time
.
Now
(),
...
...
pkg/stores/sqlstore/accounts.go
View file @
6f63d63e
...
@@ -11,13 +11,14 @@ import (
...
@@ -11,13 +11,14 @@ import (
func
init
()
{
func
init
()
{
bus
.
AddHandler
(
"sql"
,
GetAccountInfo
)
bus
.
AddHandler
(
"sql"
,
GetAccountInfo
)
bus
.
AddHandler
(
"sql"
,
AddCollaborator
)
bus
.
AddHandler
(
"sql"
,
GetOtherAccounts
)
bus
.
AddHandler
(
"sql"
,
GetOtherAccounts
)
bus
.
AddHandler
(
"sql"
,
CreateAccount
)
bus
.
AddHandler
(
"sql"
,
CreateAccount
)
bus
.
AddHandler
(
"sql"
,
SetUsingAccount
)
bus
.
AddHandler
(
"sql"
,
SetUsingAccount
)
bus
.
AddHandler
(
"sql"
,
GetAccountById
)
bus
.
AddHandler
(
"sql"
,
GetAccountById
)
bus
.
AddHandler
(
"sql"
,
GetAccountByLogin
)
bus
.
AddHandler
(
"sql"
,
GetAccountByLogin
)
bus
.
AddHandler
(
"sql"
,
GetAccountByToken
)
bus
.
AddHandler
(
"sql"
,
GetAccountByToken
)
bus
.
AddHandler
(
"sql"
,
AddCollaborator
)
bus
.
AddHandler
(
"sql"
,
RemoveCollaborator
)
}
}
func
CreateAccount
(
cmd
*
m
.
CreateAccountCommand
)
error
{
func
CreateAccount
(
cmd
*
m
.
CreateAccountCommand
)
error
{
...
@@ -66,8 +67,8 @@ func GetAccountInfo(query *m.GetAccountInfoQuery) error {
...
@@ -66,8 +67,8 @@ func GetAccountInfo(query *m.GetAccountInfoQuery) error {
}
}
sess
:=
x
.
Table
(
"collaborator"
)
sess
:=
x
.
Table
(
"collaborator"
)
sess
.
Join
(
"INNER"
,
"account"
,
"account.id=collaborator.
account_I
d"
)
sess
.
Join
(
"INNER"
,
"account"
,
"account.id=collaborator.
collaborator_i
d"
)
sess
.
Where
(
"collaborator.
for_
account_id=?"
,
query
.
Id
)
sess
.
Where
(
"collaborator.account_id=?"
,
query
.
Id
)
err
=
sess
.
Find
(
&
query
.
Result
.
Collaborators
)
err
=
sess
.
Find
(
&
query
.
Result
.
Collaborators
)
return
err
return
err
...
@@ -78,7 +79,7 @@ func AddCollaborator(cmd *m.AddCollaboratorCommand) error {
...
@@ -78,7 +79,7 @@ func AddCollaborator(cmd *m.AddCollaboratorCommand) error {
entity
:=
m
.
Collaborator
{
entity
:=
m
.
Collaborator
{
AccountId
:
cmd
.
AccountId
,
AccountId
:
cmd
.
AccountId
,
ForAccountId
:
cmd
.
ForAccount
Id
,
CollaboratorId
:
cmd
.
Collaborator
Id
,
Role
:
cmd
.
Role
,
Role
:
cmd
.
Role
,
Created
:
time
.
Now
(),
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
Updated
:
time
.
Now
(),
...
@@ -155,12 +156,20 @@ func GetAccountByLogin(query *m.GetAccountByLoginQuery) error {
...
@@ -155,12 +156,20 @@ func GetAccountByLogin(query *m.GetAccountByLoginQuery) error {
return
nil
return
nil
}
}
func
RemoveCollaborator
(
cmd
*
m
.
RemoveCollaboratorCommand
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
var
rawSql
=
"DELETE FROM collaborator WHERE collaborator_id=? and account_id=?"
_
,
err
:=
sess
.
Exec
(
rawSql
,
cmd
.
CollaboratorId
,
cmd
.
AccountId
)
return
err
})
}
func
GetOtherAccounts
(
query
*
m
.
GetOtherAccountsQuery
)
error
{
func
GetOtherAccounts
(
query
*
m
.
GetOtherAccountsQuery
)
error
{
query
.
Result
=
make
([]
*
m
.
OtherAccountDTO
,
0
)
query
.
Result
=
make
([]
*
m
.
OtherAccountDTO
,
0
)
sess
:=
x
.
Table
(
"collaborator"
)
sess
:=
x
.
Table
(
"collaborator"
)
sess
.
Join
(
"INNER"
,
"account"
,
"collaborator.
for_
account_id=account.id"
)
sess
.
Join
(
"INNER"
,
"account"
,
"collaborator.account_id=account.id"
)
sess
.
Where
(
"
account
_id=?"
,
query
.
AccountId
)
sess
.
Where
(
"
collaborator
_id=?"
,
query
.
AccountId
)
sess
.
Cols
(
"collaborator.id"
,
"collaborator.role"
,
"account.email"
)
sess
.
Cols
(
"collaborator.
account_
id"
,
"collaborator.role"
,
"account.email"
)
err
:=
sess
.
Find
(
&
query
.
Result
)
err
:=
sess
.
Find
(
&
query
.
Result
)
return
err
return
err
}
}
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