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
9feb8a73
Commit
9feb8a73
authored
Jan 16, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added binding to tokens api and role validation
parent
f858f6b6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
25 additions
and
28 deletions
+25
-28
grafana
+1
-1
pkg/api/api.go
+4
-1
pkg/api/collaborators.go
+4
-0
pkg/api/token.go
+8
-15
pkg/models/collaborator.go
+2
-6
pkg/models/token.go
+6
-5
No files found.
grafana
@
d3cc6e51
Subproject commit
500e00066139b861a2898db6ef80ef87b8b8daa6
Subproject commit
d3cc6e518dfd2ceb26c0e568bc603b4473b11a02
pkg/api/api.go
View file @
9feb8a73
...
...
@@ -46,7 +46,10 @@ func Register(r *macaron.Macaron) {
})
// Token
r
.
Group
(
"/tokens"
,
func
()
{
r
.
Combo
(
"/"
)
.
Get
(
GetTokens
)
.
Put
(
AddToken
)
.
Post
(
UpdateToken
)
r
.
Combo
(
"/"
)
.
Get
(
GetTokens
)
.
Put
(
bind
(
m
.
AddTokenCommand
{}),
AddToken
)
.
Post
(
bind
(
m
.
UpdateTokenCommand
{}),
UpdateToken
)
r
.
Delete
(
"/:id"
,
DeleteToken
)
})
// Data sources
...
...
pkg/api/collaborators.go
View file @
9feb8a73
...
...
@@ -7,6 +7,10 @@ import (
)
func
AddCollaborator
(
c
*
middleware
.
Context
,
cmd
m
.
AddCollaboratorCommand
)
{
if
!
cmd
.
Role
.
IsValid
()
{
c
.
JsonApiErr
(
400
,
"Invalid role specified"
,
nil
)
return
}
userQuery
:=
m
.
GetAccountByLoginQuery
{
LoginOrEmail
:
cmd
.
LoginOrEmail
}
err
:=
bus
.
Dispatch
(
&
userQuery
)
...
...
pkg/api/token.go
View file @
9feb8a73
...
...
@@ -41,19 +41,12 @@ func DeleteToken(c *middleware.Context) {
c
.
JsonOK
(
"Token deleted"
)
}
func
AddToken
(
c
*
middleware
.
Context
)
{
cmd
:=
m
.
AddTokenCommand
{}
if
!
c
.
JsonBody
(
&
cmd
)
{
c
.
JsonApiErr
(
400
,
"Validation failed"
,
nil
)
func
AddToken
(
c
*
middleware
.
Context
,
cmd
m
.
AddTokenCommand
)
{
if
!
cmd
.
Role
.
IsValid
()
{
c
.
JsonApiErr
(
400
,
"Invalid role specified"
,
nil
)
return
}
// if cmd.Role != m.ROLE_READ_WRITE && cmd.Role != m.ROLE_READ {
// c.JsonApiErr(400, "Invalid role specified", nil)
// return
// }
cmd
.
AccountId
=
c
.
Account
.
Id
cmd
.
Token
=
util
.
GetRandomString
(
64
)
...
...
@@ -61,20 +54,20 @@ func AddToken(c *middleware.Context) {
c
.
JsonApiErr
(
500
,
"Failed to add token"
,
err
)
return
}
result
:=
&
m
.
TokenDTO
{
Id
:
cmd
.
Result
.
Id
,
Name
:
cmd
.
Result
.
Name
,
Role
:
cmd
.
Result
.
Role
,
Token
:
cmd
.
Result
.
Token
,
}
c
.
JSON
(
200
,
result
)
}
func
UpdateToken
(
c
*
middleware
.
Context
)
{
cmd
:=
m
.
UpdateTokenCommand
{}
if
!
c
.
JsonBody
(
&
cmd
)
{
c
.
JsonApiErr
(
400
,
"Validation failed"
,
nil
)
func
UpdateToken
(
c
*
middleware
.
Context
,
cmd
m
.
UpdateTokenCommand
)
{
if
!
cmd
.
Role
.
IsValid
()
{
c
.
JsonApiErr
(
400
,
"Invalid role specified"
,
nil
)
return
}
...
...
pkg/models/collaborator.go
View file @
9feb8a73
...
...
@@ -19,12 +19,8 @@ const (
ROLE_ADMIN
RoleType
=
"Admin"
)
func
(
r
RoleType
)
Validate
()
error
{
if
r
==
ROLE_OWNER
||
r
==
ROLE_VIEWER
||
r
==
ROLE_ADMIN
||
r
==
ROLE_EDITOR
{
return
nil
}
return
ErrInvalidRoleType
func
(
r
RoleType
)
IsValid
()
bool
{
return
r
==
ROLE_VIEWER
||
r
==
ROLE_ADMIN
||
r
==
ROLE_EDITOR
}
type
Collaborator
struct
{
...
...
pkg/models/token.go
View file @
9feb8a73
...
...
@@ -25,11 +25,12 @@ type AddTokenCommand struct {
}
type
UpdateTokenCommand
struct
{
Id
int64
`json:"id"`
Name
string
`json:"name"`
AccountId
int64
`json:"-"`
Role
RoleType
`json:"role"`
Result
*
Token
`json:"-"`
Id
int64
`json:"id"`
Name
string
`json:"name"`
Role
RoleType
`json:"role"`
AccountId
int64
`json:"-"`
Result
*
Token
`json:"-"`
}
type
DeleteTokenCommand
struct
{
...
...
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