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
158b708e
Commit
158b708e
authored
Sep 18, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small progress on adding collaborator
parent
4dfe8b6f
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
77 additions
and
21 deletions
+77
-21
grafana
+1
-1
pkg/api/api.go
+2
-0
pkg/api/api_account.go
+39
-0
pkg/api/api_login.go
+1
-12
pkg/models/dashboards.go
+13
-4
pkg/stores/rethinkdb_accounts.go
+17
-1
pkg/stores/rethinkdb_test.go
+3
-3
pkg/stores/store.go
+1
-0
No files found.
grafana
@
aa47eeff
Subproject commit
4f798cfe568db2491fe5eea3f06ddd3027117e90
Subproject commit
aa47eeffb2da4cdc8be8f5b1bb5233eeabcd5a03
pkg/api/api.go
View file @
158b708e
...
@@ -53,6 +53,8 @@ func (self *HttpServer) ListenAndServe() {
...
@@ -53,6 +53,8 @@ func (self *HttpServer) ListenAndServe() {
// register default route
// register default route
self
.
router
.
GET
(
"/"
,
self
.
auth
(),
self
.
index
)
self
.
router
.
GET
(
"/"
,
self
.
auth
(),
self
.
index
)
self
.
router
.
GET
(
"/dashboard/*_"
,
self
.
auth
(),
self
.
index
)
self
.
router
.
GET
(
"/dashboard/*_"
,
self
.
auth
(),
self
.
index
)
self
.
router
.
GET
(
"/admin/*_"
,
self
.
auth
(),
self
.
index
)
self
.
router
.
GET
(
"/account/*_"
,
self
.
auth
(),
self
.
index
)
self
.
router
.
Run
(
":"
+
self
.
port
)
self
.
router
.
Run
(
":"
+
self
.
port
)
}
}
...
...
pkg/api/api_account.go
0 → 100644
View file @
158b708e
package
api
import
"github.com/gin-gonic/gin"
func
init
()
{
addRoutes
(
func
(
self
*
HttpServer
)
{
self
.
router
.
POST
(
"/api/account/collaborators/add"
,
self
.
auth
(),
self
.
addCollaborator
)
})
}
type
addCollaboratorDto
struct
{
Email
string
`json:"email" binding:"required"`
}
func
(
self
*
HttpServer
)
addCollaborator
(
c
*
gin
.
Context
)
{
var
model
addCollaboratorDto
if
!
c
.
EnsureBody
(
&
model
)
{
c
.
JSON
(
400
,
gin
.
H
{
"status"
:
"bad request"
})
return
}
accountId
,
_
:=
c
.
Get
(
"accountId"
)
account
,
err
:=
self
.
store
.
GetAccount
(
accountId
.
(
int
))
if
err
!=
nil
{
c
.
JSON
(
401
,
gin
.
H
{
"status"
:
"Authentication error"
})
}
collaborator
,
err
:=
self
.
store
.
GetUserAccountLogin
(
model
.
Email
)
if
err
!=
nil
{
c
.
JSON
(
404
,
gin
.
H
{
"status"
:
"Collaborator not found"
})
}
account
.
AddCollaborator
(
collaborator
.
Id
)
self
.
store
.
SaveUserAccount
(
account
)
c
.
JSON
(
200
,
gin
.
H
{
"status"
:
"Collaborator added"
})
}
pkg/api/api_login.go
View file @
158b708e
...
@@ -36,7 +36,7 @@ func (self *HttpServer) loginPost(c *gin.Context) {
...
@@ -36,7 +36,7 @@ func (self *HttpServer) loginPost(c *gin.Context) {
session
,
_
:=
sessionStore
.
Get
(
c
.
Request
,
"grafana-session"
)
session
,
_
:=
sessionStore
.
Get
(
c
.
Request
,
"grafana-session"
)
session
.
Values
[
"login"
]
=
loginModel
.
Email
session
.
Values
[
"login"
]
=
loginModel
.
Email
session
.
Values
[
"accountId"
]
=
account
.
Database
Id
session
.
Values
[
"accountId"
]
=
account
.
Id
session
.
Save
(
c
.
Request
,
c
.
Writer
)
session
.
Save
(
c
.
Request
,
c
.
Writer
)
var
resp
=
&
LoginResultDto
{}
var
resp
=
&
LoginResultDto
{}
...
@@ -54,17 +54,6 @@ func (self *HttpServer) logoutPost(c *gin.Context) {
...
@@ -54,17 +54,6 @@ func (self *HttpServer) logoutPost(c *gin.Context) {
c
.
JSON
(
200
,
gin
.
H
{
"status"
:
"logged out"
})
c
.
JSON
(
200
,
gin
.
H
{
"status"
:
"logged out"
})
}
}
type
GrafanaReqContext
struct
{
}
type
authenticatedAuthRouteFunc
func
(
c
*
gin
.
Context
,
grc
GrafanaReqContext
)
func
(
self
*
HttpServer
)
addAuthRoute
(
route
string
,
handler
authenticatedAuthRouteFunc
)
{
self
.
router
.
GET
(
route
,
self
.
auth
(),
func
(
c
*
gin
.
Context
)
{
})
}
func
(
self
*
HttpServer
)
auth
()
gin
.
HandlerFunc
{
func
(
self
*
HttpServer
)
auth
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
return
func
(
c
*
gin
.
Context
)
{
session
,
_
:=
sessionStore
.
Get
(
c
.
Request
,
"grafana-session"
)
session
,
_
:=
sessionStore
.
Get
(
c
.
Request
,
"grafana-session"
)
...
...
pkg/models/dashboards.go
View file @
158b708e
...
@@ -21,22 +21,22 @@ type Dashboard struct {
...
@@ -21,22 +21,22 @@ type Dashboard struct {
Data
map
[
string
]
interface
{}
Data
map
[
string
]
interface
{}
}
}
type
UserAccount
Link
struct
{
type
Collaborator
Link
struct
{
UserId
int
AccountId
int
Role
string
Role
string
ModifiedOn
time
.
Time
ModifiedOn
time
.
Time
CreatedOn
time
.
Time
CreatedOn
time
.
Time
}
}
type
UserAccount
struct
{
type
UserAccount
struct
{
DatabaseId
int
`gorethink:"id"`
Id
int
`gorethink:"id"`
UserName
string
UserName
string
Login
string
Login
string
Email
string
Email
string
Password
string
Password
string
NextDashboardId
int
NextDashboardId
int
UsingAccountId
int
UsingAccountId
int
GrantedAccess
[]
UserAccount
Link
Collaborators
[]
Collaborator
Link
CreatedOn
time
.
Time
CreatedOn
time
.
Time
ModifiedOn
time
.
Time
ModifiedOn
time
.
Time
}
}
...
@@ -87,3 +87,12 @@ func (dash *Dashboard) UpdateSlug() {
...
@@ -87,3 +87,12 @@ func (dash *Dashboard) UpdateSlug() {
re2
:=
regexp
.
MustCompile
(
"
\\
s"
)
re2
:=
regexp
.
MustCompile
(
"
\\
s"
)
dash
.
Slug
=
re2
.
ReplaceAllString
(
re
.
ReplaceAllString
(
title
,
""
),
"-"
)
dash
.
Slug
=
re2
.
ReplaceAllString
(
re
.
ReplaceAllString
(
title
,
""
),
"-"
)
}
}
func
(
account
*
UserAccount
)
AddCollaborator
(
accountId
int
)
{
account
.
Collaborators
=
append
(
account
.
Collaborators
,
CollaboratorLink
{
AccountId
:
accountId
,
Role
:
"admin"
,
CreatedOn
:
time
.
Now
(),
ModifiedOn
:
time
.
Now
(),
})
}
pkg/stores/rethinkdb_accounts.go
View file @
158b708e
...
@@ -31,7 +31,7 @@ func (self *rethinkStore) SaveUserAccount(account *models.UserAccount) error {
...
@@ -31,7 +31,7 @@ func (self *rethinkStore) SaveUserAccount(account *models.UserAccount) error {
return
err
return
err
}
}
account
.
Database
Id
=
accountId
account
.
Id
=
accountId
resp
,
err
:=
r
.
Table
(
"accounts"
)
.
Insert
(
account
)
.
RunWrite
(
self
.
session
)
resp
,
err
:=
r
.
Table
(
"accounts"
)
.
Insert
(
account
)
.
RunWrite
(
self
.
session
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -61,6 +61,22 @@ func (self *rethinkStore) GetUserAccountLogin(emailOrName string) (*models.UserA
...
@@ -61,6 +61,22 @@ func (self *rethinkStore) GetUserAccountLogin(emailOrName string) (*models.UserA
return
&
account
,
nil
return
&
account
,
nil
}
}
func
(
self
*
rethinkStore
)
GetAccount
(
id
int
)
(
*
models
.
UserAccount
,
error
)
{
resp
,
err
:=
r
.
Table
(
"accounts"
)
.
Get
(
id
)
.
Run
(
self
.
session
)
if
err
!=
nil
{
return
nil
,
err
}
var
account
models
.
UserAccount
err
=
resp
.
One
(
&
account
)
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"Not found"
)
}
return
&
account
,
nil
}
func
(
self
*
rethinkStore
)
getNextDashboardNumber
(
accountId
int
)
(
int
,
error
)
{
func
(
self
*
rethinkStore
)
getNextDashboardNumber
(
accountId
int
)
(
int
,
error
)
{
resp
,
err
:=
r
.
Table
(
"accounts"
)
.
Get
(
accountId
)
.
Update
(
map
[
string
]
interface
{}{
resp
,
err
:=
r
.
Table
(
"accounts"
)
.
Get
(
accountId
)
.
Update
(
map
[
string
]
interface
{}{
"NextDashboardId"
:
r
.
Row
.
Field
(
"NextDashboardId"
)
.
Add
(
1
),
"NextDashboardId"
:
r
.
Row
.
Field
(
"NextDashboardId"
)
.
Add
(
1
),
...
...
pkg/stores/rethinkdb_test.go
View file @
158b708e
...
@@ -38,17 +38,17 @@ func TestRethinkStore(t *testing.T) {
...
@@ -38,17 +38,17 @@ func TestRethinkStore(t *testing.T) {
account
:=
&
models
.
UserAccount
{
UserName
:
"torkelo"
,
Email
:
"mupp"
,
Login
:
"test@test.com"
}
account
:=
&
models
.
UserAccount
{
UserName
:
"torkelo"
,
Email
:
"mupp"
,
Login
:
"test@test.com"
}
err
:=
store
.
SaveUserAccount
(
account
)
err
:=
store
.
SaveUserAccount
(
account
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
account
.
Database
Id
,
ShouldNotEqual
,
0
)
So
(
account
.
Id
,
ShouldNotEqual
,
0
)
read
,
err
:=
store
.
GetUserAccountLogin
(
"test@test.com"
)
read
,
err
:=
store
.
GetUserAccountLogin
(
"test@test.com"
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
read
.
Database
Id
,
ShouldEqual
,
account
.
DatabaseId
)
So
(
read
.
Id
,
ShouldEqual
,
account
.
DatabaseId
)
})
})
Convey
(
"can get next dashboard id"
,
t
,
func
()
{
Convey
(
"can get next dashboard id"
,
t
,
func
()
{
account
:=
&
models
.
UserAccount
{
UserName
:
"torkelo"
,
Email
:
"mupp"
}
account
:=
&
models
.
UserAccount
{
UserName
:
"torkelo"
,
Email
:
"mupp"
}
err
:=
store
.
SaveUserAccount
(
account
)
err
:=
store
.
SaveUserAccount
(
account
)
dashId
,
err
:=
store
.
getNextDashboardNumber
(
account
.
Database
Id
)
dashId
,
err
:=
store
.
getNextDashboardNumber
(
account
.
Id
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
dashId
,
ShouldEqual
,
1
)
So
(
dashId
,
ShouldEqual
,
1
)
})
})
...
...
pkg/stores/store.go
View file @
158b708e
...
@@ -11,6 +11,7 @@ type Store interface {
...
@@ -11,6 +11,7 @@ type Store interface {
Query
(
query
string
,
acccountId
int
)
([]
*
models
.
SearchResult
,
error
)
Query
(
query
string
,
acccountId
int
)
([]
*
models
.
SearchResult
,
error
)
SaveUserAccount
(
acccount
*
models
.
UserAccount
)
error
SaveUserAccount
(
acccount
*
models
.
UserAccount
)
error
GetUserAccountLogin
(
emailOrName
string
)
(
*
models
.
UserAccount
,
error
)
GetUserAccountLogin
(
emailOrName
string
)
(
*
models
.
UserAccount
,
error
)
GetAccount
(
id
int
)
(
*
models
.
UserAccount
,
error
)
Close
()
Close
()
}
}
...
...
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