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
5dcf6ff2
Commit
5dcf6ff2
authored
Dec 19, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring set using account
parent
607b0c0c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
32 deletions
+64
-32
grafana
+1
-1
pkg/api/api_account.go
+40
-31
pkg/models/account.go
+5
-0
pkg/stores/sqlstore/accounts.go
+12
-0
pkg/stores/sqlstore/accounts_test.go
+6
-0
No files found.
grafana
@
ad910939
Subproject commit
4e542d8b83844f8faa4d5ae3edab593950aaa344
Subproject commit
ad91093902bdfc0d2a87bb362a76a9057aef4361
pkg/api/api_account.go
View file @
5dcf6ff2
...
@@ -76,36 +76,45 @@ func GetOtherAccounts(c *middleware.Context) {
...
@@ -76,36 +76,45 @@ func GetOtherAccounts(c *middleware.Context) {
c
.
JSON
(
200
,
result
)
c
.
JSON
(
200
,
result
)
}
}
func
validateUsingAccount
(
accountId
int64
,
otherId
int64
)
bool
{
if
accountId
==
otherId
{
return
true
}
query
:=
m
.
GetOtherAccountsQuery
{
AccountId
:
accountId
}
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
return
false
}
// validate that the account id in the list
valid
:=
false
for
_
,
other
:=
range
query
.
Result
{
if
other
.
Id
==
otherId
{
valid
=
true
}
}
return
valid
}
func
SetUsingAccount
(
c
*
middleware
.
Context
)
{
func
SetUsingAccount
(
c
*
middleware
.
Context
)
{
// usingAccountId := c.ParamsInt64(":id")
usingAccountId
:=
c
.
ParamsInt64
(
":id"
)
//
// account := c.UserAccount
if
!
validateUsingAccount
(
c
.
UserAccount
.
Id
,
usingAccountId
)
{
// otherAccounts, err := m.GetOtherAccountsFor(c.UserAccount.Id)
c
.
JsonApiErr
(
401
,
"Not a valid account"
,
nil
)
//
return
// if err != nil {
}
// c.JSON(500, utils.DynMap{"message": err.Error()})
// return
cmd
:=
m
.
SetUsingAccountCommand
{
// }
AccountId
:
c
.
UserAccount
.
Id
,
//
UsingAccountId
:
usingAccountId
,
// // validate that the account id in the list
}
// valid := false
// for _, other := range otherAccounts {
err
:=
bus
.
Dispatch
(
&
cmd
)
// if other.Id == usingAccountId {
if
err
!=
nil
{
// valid = true
c
.
JsonApiErr
(
500
,
"Failed to update account"
,
err
)
// }
return
// }
}
//
// if !valid {
c
.
JsonOK
(
"Active account changed"
)
// c.Status(401)
// return
// }
//
// account.UsingAccountId = usingAccountId
// err = m.SaveAccount(account)
// if err != nil {
// c.JSON(500, utils.DynMap{"message": err.Error()})
// return
// }
//
// c.Status(204)
}
}
pkg/models/account.go
View file @
5dcf6ff2
...
@@ -64,6 +64,11 @@ type CreateAccountCommand struct {
...
@@ -64,6 +64,11 @@ type CreateAccountCommand struct {
Result
Account
`json:"-"`
Result
Account
`json:"-"`
}
}
type
SetUsingAccountCommand
struct
{
AccountId
int64
UsingAccountId
int64
}
// returns a view projection
// returns a view projection
type
GetAccountInfoQuery
struct
{
type
GetAccountInfoQuery
struct
{
Id
int64
Id
int64
...
...
pkg/stores/sqlstore/accounts.go
View file @
5dcf6ff2
...
@@ -14,6 +14,7 @@ func init() {
...
@@ -14,6 +14,7 @@ func init() {
bus
.
AddHandler
(
"sql"
,
AddCollaborator
)
bus
.
AddHandler
(
"sql"
,
AddCollaborator
)
bus
.
AddHandler
(
"sql"
,
GetOtherAccounts
)
bus
.
AddHandler
(
"sql"
,
GetOtherAccounts
)
bus
.
AddHandler
(
"sql"
,
CreateAccount
)
bus
.
AddHandler
(
"sql"
,
CreateAccount
)
bus
.
AddHandler
(
"sql"
,
SetUsingAccount
)
}
}
func
CreateAccount
(
cmd
*
m
.
CreateAccountCommand
)
error
{
func
CreateAccount
(
cmd
*
m
.
CreateAccountCommand
)
error
{
...
@@ -33,6 +34,17 @@ func CreateAccount(cmd *m.CreateAccountCommand) error {
...
@@ -33,6 +34,17 @@ func CreateAccount(cmd *m.CreateAccountCommand) error {
})
})
}
}
func
SetUsingAccount
(
cmd
*
m
.
SetUsingAccountCommand
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
account
:=
m
.
Account
{}
sess
.
Id
(
cmd
.
AccountId
)
.
Get
(
&
account
)
account
.
UsingAccountId
=
cmd
.
UsingAccountId
_
,
err
:=
sess
.
Id
(
account
.
Id
)
.
Update
(
&
account
)
return
err
})
}
func
GetAccountInfo
(
query
*
m
.
GetAccountInfoQuery
)
error
{
func
GetAccountInfo
(
query
*
m
.
GetAccountInfoQuery
)
error
{
var
account
m
.
Account
var
account
m
.
Account
has
,
err
:=
x
.
Id
(
query
.
Id
)
.
Get
(
&
account
)
has
,
err
:=
x
.
Id
(
query
.
Id
)
.
Get
(
&
account
)
...
...
pkg/stores/sqlstore/accounts_test.go
View file @
5dcf6ff2
...
@@ -61,6 +61,12 @@ func TestAccountDataAccess(t *testing.T) {
...
@@ -61,6 +61,12 @@ func TestAccountDataAccess(t *testing.T) {
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
[
0
]
.
Email
,
ShouldEqual
,
"ac1@test.com"
)
So
(
query
.
Result
[
0
]
.
Email
,
ShouldEqual
,
"ac1@test.com"
)
})
})
Convey
(
"Can set using account"
,
func
()
{
cmd
:=
m
.
SetUsingAccountCommand
{
AccountId
:
ac2
.
Id
,
UsingAccountId
:
ac1
.
Id
}
err
:=
SetUsingAccount
(
&
cmd
)
So
(
err
,
ShouldBeNil
)
})
})
})
})
})
})
})
...
...
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