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
705455d5
Commit
705455d5
authored
Dec 15, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set active account now works again
parent
973b9cad
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
49 additions
and
36 deletions
+49
-36
pkg/api/api.go
+1
-0
pkg/api/api_account.go
+34
-25
pkg/api/api_login_oauth.go
+1
-1
pkg/api/api_register.go
+1
-1
pkg/models/account.go
+1
-2
pkg/stores/sqlstore/sqlstore.go
+1
-1
pkg/stores/sqlstore/sqlstore_accounts.go
+9
-5
pkg/stores/sqlstore/sqlstore_dashboards.go
+1
-1
No files found.
pkg/api/api.go
View file @
705455d5
...
@@ -22,6 +22,7 @@ func Register(m *macaron.Macaron) {
...
@@ -22,6 +22,7 @@ func Register(m *macaron.Macaron) {
m
.
Get
(
"/account/"
,
auth
,
Index
)
m
.
Get
(
"/account/"
,
auth
,
Index
)
m
.
Get
(
"/api/account/"
,
auth
,
GetAccount
)
m
.
Get
(
"/api/account/"
,
auth
,
GetAccount
)
m
.
Post
(
"/api/account/collaborators/add"
,
auth
,
AddCollaborator
)
m
.
Post
(
"/api/account/collaborators/add"
,
auth
,
AddCollaborator
)
m
.
Post
(
"/api/account/using/:id"
,
auth
,
SetUsingAccount
)
m
.
Get
(
"/api/account/others"
,
auth
,
GetOtherAccounts
)
m
.
Get
(
"/api/account/others"
,
auth
,
GetOtherAccounts
)
// user register
// user register
...
...
pkg/api/api_account.go
View file @
705455d5
package
api
package
api
import
(
import
(
"github.com/gin-gonic/gin"
"github.com/torkelo/grafana-pro/pkg/api/dtos"
"github.com/torkelo/grafana-pro/pkg/api/dtos"
"github.com/torkelo/grafana-pro/pkg/middleware"
"github.com/torkelo/grafana-pro/pkg/middleware"
"github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/models"
...
@@ -88,28 +89,36 @@ func GetOtherAccounts(c *middleware.Context) {
...
@@ -88,28 +89,36 @@ func GetOtherAccounts(c *middleware.Context) {
c
.
JSON
(
200
,
result
)
c
.
JSON
(
200
,
result
)
}
}
// func SetUsingAccount(c *middleware.Context) {
func
SetUsingAccount
(
c
*
middleware
.
Context
)
{
// idString := c.Params.ByName("id")
usingAccountId
:=
c
.
ParamsInt64
(
":id"
)
// id, _ := strconv.Atoi(idString)
//
account
:=
c
.
UserAccount
// account := auth.userAccount
otherAccounts
,
err
:=
models
.
GetOtherAccountsFor
(
c
.
UserAccount
.
Id
)
// otherAccount, err := self.store.GetAccount(id)
// if err != nil {
if
err
!=
nil
{
// c.JSON(500, gin.H{"message": err.Error()})
c
.
JSON
(
500
,
gin
.
H
{
"message"
:
err
.
Error
()})
// return
return
// }
}
//
// if otherAccount.Id != account.Id && !otherAccount.HasCollaborator(account.Id) {
// validate that the account id in the list
// c.Abort(401)
valid
:=
false
// return
for
_
,
other
:=
range
otherAccounts
{
// }
if
other
.
Id
==
usingAccountId
{
//
valid
=
true
// account.UsingAccountId = otherAccount.Id
}
// err = self.store.UpdateAccount(account)
}
// if err != nil {
// c.JSON(500, gin.H{"message": err.Error()})
if
!
valid
{
// return
c
.
Status
(
401
)
// }
return
//
}
// c.Abort(204)
// }
account
.
UsingAccountId
=
usingAccountId
err
=
models
.
SaveAccount
(
account
)
if
err
!=
nil
{
c
.
JSON
(
500
,
gin
.
H
{
"message"
:
err
.
Error
()})
return
}
c
.
Status
(
204
)
}
pkg/api/api_login_oauth.go
View file @
705455d5
...
@@ -59,7 +59,7 @@ func OAuthLogin(ctx *middleware.Context) {
...
@@ -59,7 +59,7 @@ func OAuthLogin(ctx *middleware.Context) {
Company
:
userInfo
.
Company
,
Company
:
userInfo
.
Company
,
}
}
if
err
=
models
.
Creat
eAccount
(
account
);
err
!=
nil
{
if
err
=
models
.
Sav
eAccount
(
account
);
err
!=
nil
{
ctx
.
Handle
(
500
,
"Failed to create account"
,
err
)
ctx
.
Handle
(
500
,
"Failed to create account"
,
err
)
return
return
}
}
...
...
pkg/api/api_register.go
View file @
705455d5
...
@@ -27,7 +27,7 @@ func CreateAccount(c *middleware.Context) {
...
@@ -27,7 +27,7 @@ func CreateAccount(c *middleware.Context) {
Password
:
registerModel
.
Password
,
Password
:
registerModel
.
Password
,
}
}
err
:=
models
.
Creat
eAccount
(
&
account
)
err
:=
models
.
Sav
eAccount
(
&
account
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
2
,
"Failed to create user account, email: %v, error: %v"
,
registerModel
.
Email
,
err
)
log
.
Error
(
2
,
"Failed to create user account, email: %v, error: %v"
,
registerModel
.
Email
,
err
)
c
.
JSON
(
500
,
utils
.
DynMap
{
"status"
:
"failed to create account"
})
c
.
JSON
(
500
,
utils
.
DynMap
{
"status"
:
"failed to create account"
})
...
...
pkg/models/account.go
View file @
705455d5
...
@@ -6,8 +6,7 @@ import (
...
@@ -6,8 +6,7 @@ import (
)
)
var
(
var
(
CreateAccount
func
(
acccount
*
Account
)
error
SaveAccount
func
(
account
*
Account
)
error
UpdateAccount
func
(
acccount
*
Account
)
error
GetAccountByLogin
func
(
emailOrName
string
)
(
*
Account
,
error
)
GetAccountByLogin
func
(
emailOrName
string
)
(
*
Account
,
error
)
GetAccount
func
(
accountId
int64
)
(
*
Account
,
error
)
GetAccount
func
(
accountId
int64
)
(
*
Account
,
error
)
GetOtherAccountsFor
func
(
accountId
int64
)
([]
*
OtherAccount
,
error
)
GetOtherAccountsFor
func
(
accountId
int64
)
([]
*
OtherAccount
,
error
)
...
...
pkg/stores/sqlstore/sqlstore.go
View file @
705455d5
...
@@ -29,7 +29,7 @@ var (
...
@@ -29,7 +29,7 @@ var (
func
Init
()
{
func
Init
()
{
tables
=
append
(
tables
,
new
(
models
.
Account
),
new
(
models
.
Dashboard
),
new
(
models
.
Collaborator
))
tables
=
append
(
tables
,
new
(
models
.
Account
),
new
(
models
.
Dashboard
),
new
(
models
.
Collaborator
))
models
.
CreateAccount
=
Creat
eAccount
models
.
SaveAccount
=
Sav
eAccount
models
.
GetAccount
=
GetAccount
models
.
GetAccount
=
GetAccount
models
.
GetAccountByLogin
=
GetAccountByLogin
models
.
GetAccountByLogin
=
GetAccountByLogin
models
.
GetOtherAccountsFor
=
GetOtherAccountsFor
models
.
GetOtherAccountsFor
=
GetOtherAccountsFor
...
...
pkg/stores/sqlstore/sqlstore_accounts.go
View file @
705455d5
package
sqlstore
package
sqlstore
import
(
import
"github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/models"
)
func
Creat
eAccount
(
account
*
models
.
Account
)
error
{
func
Sav
eAccount
(
account
*
models
.
Account
)
error
{
var
err
error
var
err
error
sess
:=
x
.
NewSession
()
sess
:=
x
.
NewSession
()
...
@@ -14,7 +12,13 @@ func CreateAccount(account *models.Account) error {
...
@@ -14,7 +12,13 @@ func CreateAccount(account *models.Account) error {
return
err
return
err
}
}
if
_
,
err
=
sess
.
Insert
(
account
);
err
!=
nil
{
if
account
.
Id
==
0
{
_
,
err
=
sess
.
Insert
(
account
)
}
else
{
_
,
err
=
sess
.
Id
(
account
.
Id
)
.
Update
(
account
)
}
if
err
!=
nil
{
sess
.
Rollback
()
sess
.
Rollback
()
return
err
return
err
}
else
if
err
=
sess
.
Commit
();
err
!=
nil
{
}
else
if
err
=
sess
.
Commit
();
err
!=
nil
{
...
...
pkg/stores/sqlstore/sqlstore_dashboards.go
View file @
705455d5
...
@@ -15,7 +15,7 @@ func SaveDashboard(dash *models.Dashboard) error {
...
@@ -15,7 +15,7 @@ func SaveDashboard(dash *models.Dashboard) error {
if
dash
.
Id
==
0
{
if
dash
.
Id
==
0
{
_
,
err
=
sess
.
Insert
(
dash
)
_
,
err
=
sess
.
Insert
(
dash
)
}
else
{
}
else
{
_
,
err
=
sess
.
Update
(
dash
)
_
,
err
=
sess
.
Id
(
dash
.
Id
)
.
Update
(
dash
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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