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
fcdcd63d
Commit
fcdcd63d
authored
Nov 24, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get other accounts works
parent
f04932aa
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
6 deletions
+54
-6
pkg/models/account.go
+2
-2
pkg/models/collaborator.go
+2
-2
pkg/routes/api/api_account.go
+29
-2
pkg/routes/dtos/models.go
+7
-0
pkg/routes/index.go
+1
-0
pkg/stores/sqlstore/sqlstore.go
+1
-0
pkg/stores/sqlstore/sqlstore_accounts.go
+12
-0
No files found.
pkg/models/account.go
View file @
fcdcd63d
...
@@ -29,8 +29,8 @@ type CollaboratorLink struct {
...
@@ -29,8 +29,8 @@ type CollaboratorLink struct {
}
}
type
OtherAccount
struct
{
type
OtherAccount
struct
{
Id
int
`gorethink:"id"`
Id
int64
Name
string
Email
string
Role
string
Role
string
}
}
...
...
pkg/models/collaborator.go
View file @
fcdcd63d
...
@@ -27,11 +27,11 @@ type CollaboratorInfo struct {
...
@@ -27,11 +27,11 @@ type CollaboratorInfo struct {
Email
string
Email
string
}
}
func
NewCollaborator
(
accountId
int64
,
forAccountId
int64
)
*
Collaborator
{
func
NewCollaborator
(
accountId
int64
,
forAccountId
int64
,
role
RoleType
)
*
Collaborator
{
return
&
Collaborator
{
return
&
Collaborator
{
AccountId
:
accountId
,
AccountId
:
accountId
,
ForAccountId
:
forAccountId
,
ForAccountId
:
forAccountId
,
Role
:
ROLE_READ
,
Role
:
role
,
Created
:
time
.
Now
(),
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
Updated
:
time
.
Now
(),
}
}
...
...
pkg/routes/api/api_account.go
View file @
fcdcd63d
...
@@ -49,8 +49,7 @@ func AddCollaborator(c *middleware.Context) {
...
@@ -49,8 +49,7 @@ func AddCollaborator(c *middleware.Context) {
return
return
}
}
var
collaborator
=
models
.
NewCollaborator
(
accountToAdd
.
Id
,
c
.
UserAccount
.
Id
)
var
collaborator
=
models
.
NewCollaborator
(
accountToAdd
.
Id
,
c
.
UserAccount
.
Id
,
models
.
ROLE_READ_WRITE
)
collaborator
.
Role
=
models
.
ROLE_READ_WRITE
err
=
models
.
AddCollaborator
(
collaborator
)
err
=
models
.
AddCollaborator
(
collaborator
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -60,3 +59,31 @@ func AddCollaborator(c *middleware.Context) {
...
@@ -60,3 +59,31 @@ func AddCollaborator(c *middleware.Context) {
c
.
Status
(
204
)
c
.
Status
(
204
)
}
}
func
GetOtherAccounts
(
c
*
middleware
.
Context
)
{
otherAccounts
,
err
:=
models
.
GetOtherAccountsFor
(
c
.
UserAccount
.
Id
)
if
err
!=
nil
{
c
.
JSON
(
500
,
utils
.
DynMap
{
"message"
:
err
.
Error
()})
return
}
var
result
[]
*
dtos
.
OtherAccount
result
=
append
(
result
,
&
dtos
.
OtherAccount
{
Id
:
c
.
UserAccount
.
Id
,
Role
:
"owner"
,
IsUsing
:
c
.
UserAccount
.
Id
==
c
.
UserAccount
.
UsingAccountId
,
Name
:
c
.
UserAccount
.
Email
,
})
for
_
,
other
:=
range
otherAccounts
{
result
=
append
(
result
,
&
dtos
.
OtherAccount
{
Id
:
other
.
Id
,
Role
:
other
.
Role
,
Name
:
other
.
Email
,
IsUsing
:
other
.
Id
==
c
.
UserAccount
.
UsingAccountId
,
})
}
c
.
JSON
(
200
,
result
)
}
pkg/routes/dtos/models.go
View file @
fcdcd63d
...
@@ -25,6 +25,13 @@ type AccountInfo struct {
...
@@ -25,6 +25,13 @@ type AccountInfo struct {
Collaborators
[]
*
Collaborator
`json:"collaborators"`
Collaborators
[]
*
Collaborator
`json:"collaborators"`
}
}
type
OtherAccount
struct
{
Id
int64
`json:"id"`
Name
string
`json:"name"`
Role
string
`json:"role"`
IsUsing
bool
`json:"isUsing"`
}
type
Collaborator
struct
{
type
Collaborator
struct
{
AccountId
int64
`json:"accountId"`
AccountId
int64
`json:"accountId"`
Email
string
`json:"email"`
Email
string
`json:"email"`
...
...
pkg/routes/index.go
View file @
fcdcd63d
...
@@ -24,6 +24,7 @@ func Register(m *macaron.Macaron) {
...
@@ -24,6 +24,7 @@ func Register(m *macaron.Macaron) {
m
.
Get
(
"/account/"
,
auth
,
Index
)
m
.
Get
(
"/account/"
,
auth
,
Index
)
m
.
Get
(
"/api/account/"
,
auth
,
api
.
GetAccount
)
m
.
Get
(
"/api/account/"
,
auth
,
api
.
GetAccount
)
m
.
Post
(
"/api/account/collaborators/add"
,
auth
,
api
.
AddCollaborator
)
m
.
Post
(
"/api/account/collaborators/add"
,
auth
,
api
.
AddCollaborator
)
m
.
Get
(
"/api/account/others"
,
auth
,
api
.
GetOtherAccounts
)
// user register
// user register
m
.
Get
(
"/register/*_"
,
Index
)
m
.
Get
(
"/register/*_"
,
Index
)
...
...
pkg/stores/sqlstore/sqlstore.go
View file @
fcdcd63d
...
@@ -32,6 +32,7 @@ func Init() {
...
@@ -32,6 +32,7 @@ func Init() {
models
.
CreateAccount
=
CreateAccount
models
.
CreateAccount
=
CreateAccount
models
.
GetAccount
=
GetAccount
models
.
GetAccount
=
GetAccount
models
.
GetAccountByLogin
=
GetAccountByLogin
models
.
GetAccountByLogin
=
GetAccountByLogin
models
.
GetOtherAccountsFor
=
GetOtherAccountsFor
models
.
GetDashboard
=
GetDashboard
models
.
GetDashboard
=
GetDashboard
models
.
SaveDashboard
=
SaveDashboard
models
.
SaveDashboard
=
SaveDashboard
models
.
SearchQuery
=
SearchQuery
models
.
SearchQuery
=
SearchQuery
...
...
pkg/stores/sqlstore/sqlstore_accounts.go
View file @
fcdcd63d
...
@@ -60,9 +60,12 @@ func GetAccountByLogin(emailOrLogin string) (*models.Account, error) {
...
@@ -60,9 +60,12 @@ func GetAccountByLogin(emailOrLogin string) (*models.Account, error) {
func
GetCollaboratorsForAccount
(
accountId
int64
)
([]
*
models
.
CollaboratorInfo
,
error
)
{
func
GetCollaboratorsForAccount
(
accountId
int64
)
([]
*
models
.
CollaboratorInfo
,
error
)
{
collaborators
:=
make
([]
*
models
.
CollaboratorInfo
,
0
)
collaborators
:=
make
([]
*
models
.
CollaboratorInfo
,
0
)
sess
:=
x
.
Table
(
"Collaborator"
)
sess
:=
x
.
Table
(
"Collaborator"
)
sess
.
Join
(
"INNER"
,
"Account"
,
"Account.id=Collaborator.account_Id"
)
sess
.
Join
(
"INNER"
,
"Account"
,
"Account.id=Collaborator.account_Id"
)
sess
.
Where
(
"Collaborator.for_account_id=?"
,
accountId
)
err
:=
sess
.
Find
(
&
collaborators
)
err
:=
sess
.
Find
(
&
collaborators
)
return
collaborators
,
err
return
collaborators
,
err
}
}
...
@@ -85,3 +88,12 @@ func AddCollaborator(collaborator *models.Collaborator) error {
...
@@ -85,3 +88,12 @@ func AddCollaborator(collaborator *models.Collaborator) error {
return
nil
return
nil
}
}
func
GetOtherAccountsFor
(
accountId
int64
)
([]
*
models
.
OtherAccount
,
error
)
{
collaborators
:=
make
([]
*
models
.
OtherAccount
,
0
)
sess
:=
x
.
Table
(
"Collaborator"
)
sess
.
Join
(
"INNER"
,
"Account"
,
"Account.id=Collaborator.account_Id"
)
sess
.
Where
(
"Collaborator.account_id=?"
,
accountId
)
err
:=
sess
.
Find
(
&
collaborators
)
return
collaborators
,
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