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
477e035f
Commit
477e035f
authored
Mar 11, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed anonymous access mode, Closes #1586
parent
f3d4d278
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
25 additions
and
31 deletions
+25
-31
conf/defaults.ini
+1
-1
pkg/api/dataproxy.go
+3
-7
pkg/api/frontendsettings.go
+1
-1
pkg/middleware/auth.go
+2
-2
pkg/middleware/middleware.go
+9
-18
src/app/partials/sidemenu.html
+9
-2
No files found.
conf/defaults.ini
View file @
477e035f
...
...
@@ -75,7 +75,7 @@ auto_assign_org_role = Viewer
; enable anonymous access
enabled
=
false
; specify organization name that should be used for unauthenticated users
org_name
=
main
org_name
=
Main org.
; specify role for unauthenticated users
org_role
=
Viewer
...
...
pkg/api/dataproxy.go
View file @
477e035f
...
...
@@ -47,15 +47,11 @@ func NewReverseProxy(ds *m.DataSource, proxyPath string) *httputil.ReverseProxy
// TODO: need to cache datasources
func
ProxyDataSourceRequest
(
c
*
middleware
.
Context
)
{
id
:=
c
.
ParamsInt64
(
":id"
)
query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
id
,
OrgId
:
c
.
OrgId
}
query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
id
,
OrgId
:
c
.
OrgId
,
}
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Unable to load datasource meta data"
,
err
)
return
}
proxyPath
:=
c
.
Params
(
"*"
)
...
...
pkg/api/frontendsettings.go
View file @
477e035f
...
...
@@ -16,7 +16,7 @@ import (
func
getFrontendSettingsMap
(
c
*
middleware
.
Context
)
(
map
[
string
]
interface
{},
error
)
{
orgDataSources
:=
make
([]
*
m
.
DataSource
,
0
)
if
c
.
IsSignedIn
{
if
c
.
OrgId
!=
0
{
query
:=
m
.
GetDataSourcesQuery
{
OrgId
:
c
.
OrgId
}
err
:=
bus
.
Dispatch
(
&
query
)
...
...
pkg/middleware/auth.go
View file @
477e035f
...
...
@@ -23,7 +23,7 @@ func getRequestUserId(c *Context) int64 {
}
// TODO: figure out a way to secure this
if
c
.
Query
(
"render"
)
==
"1"
{
if
c
.
Req
.
URL
.
Query
()
.
Get
(
"render"
)
==
"1"
{
userId
:=
c
.
QueryInt64
(
SESS_KEY_USERID
)
c
.
Session
.
Set
(
SESS_KEY_USERID
,
userId
)
return
userId
...
...
@@ -75,7 +75,7 @@ func Auth(options *AuthOptions) macaron.Handler {
return
}
if
!
c
.
IsSignedIn
&&
options
.
ReqSignedIn
&&
!
c
.
HasAnonymousAcces
s
{
if
!
c
.
IsSignedIn
&&
options
.
ReqSignedIn
&&
!
c
.
AllowAnonymou
s
{
c
.
SetCookie
(
"redirect_to"
,
url
.
QueryEscape
(
setting
.
AppSubUrl
+
c
.
Req
.
RequestURI
),
0
,
setting
.
AppSubUrl
+
"/"
)
authDenied
(
c
)
return
...
...
pkg/middleware/middleware.go
View file @
477e035f
package
middleware
import
(
"encoding/json"
"strconv"
"strings"
...
...
@@ -21,18 +20,18 @@ type Context struct {
Session
session
.
Store
IsSignedIn
bool
HasAnonymousAcces
s
bool
IsSignedIn
bool
AllowAnonymou
s
bool
}
func
GetContextHandler
()
macaron
.
Handler
{
return
func
(
c
*
macaron
.
Context
,
sess
session
.
Store
)
{
ctx
:=
&
Context
{
Context
:
c
,
Session
:
sess
,
SignedInUser
:
&
m
.
SignedInUser
{},
IsSignedIn
:
false
,
HasAnonymousAcces
s
:
false
,
Context
:
c
,
Session
:
sess
,
SignedInUser
:
&
m
.
SignedInUser
{},
IsSignedIn
:
false
,
AllowAnonymou
s
:
false
,
}
// try get account id from request
...
...
@@ -76,12 +75,10 @@ func GetContextHandler() macaron.Handler {
}
else
if
setting
.
AnonymousEnabled
{
orgQuery
:=
m
.
GetOrgByNameQuery
{
Name
:
setting
.
AnonymousOrgName
}
if
err
:=
bus
.
Dispatch
(
&
orgQuery
);
err
!=
nil
{
if
err
==
m
.
ErrOrgNotFound
{
log
.
Error
(
3
,
"Anonymous access organization name does not exist"
,
nil
)
}
log
.
Error
(
3
,
"Anonymous access organization error"
,
nil
)
}
else
{
ctx
.
IsSignedIn
=
false
ctx
.
HasAnonymousAcces
s
=
true
ctx
.
AllowAnonymou
s
=
true
ctx
.
SignedInUser
=
&
m
.
SignedInUser
{}
ctx
.
OrgRole
=
m
.
RoleType
(
setting
.
AnonymousOrgRole
)
ctx
.
OrgId
=
orgQuery
.
Result
.
Id
...
...
@@ -141,9 +138,3 @@ func (ctx *Context) JsonApiErr(status int, message string, err error) {
ctx
.
JSON
(
status
,
resp
)
}
func
(
ctx
*
Context
)
JsonBody
(
model
interface
{})
bool
{
b
,
_
:=
ctx
.
Req
.
Body
()
.
Bytes
()
err
:=
json
.
Unmarshal
(
b
,
&
model
)
return
err
==
nil
}
src/app/partials/sidemenu.html
View file @
477e035f
...
...
@@ -28,7 +28,7 @@
<ul
class=
"sidemenu sidemenu-small"
style=
"margin-top:50px"
ng-if=
"!systemSection"
>
<li>
<li
ng-if=
"contextSrv.user.isSignedIn"
>
<a
href=
"profile"
class=
"sidemenu-item"
>
<img
ng-src=
"{{contextSrv.user.gravatarUrl}}"
>
<span
class=
"sidemenu-item-text"
>
{{contextSrv.user.name}}
</span>
...
...
@@ -61,12 +61,19 @@
</a>
</li>
<li>
<li
ng-if=
"contextSrv.isSignedIn"
>
<a
href=
"logout"
class=
"sidemenu-item"
target=
"_self"
>
<span
class=
"icon-circle sidemenu-icon"
><i
class=
"fa fa-fw fa-sign-out"
></i></span>
<span
class=
"sidemenu-item-text"
>
Sign out
</span>
</a>
</li>
<li
ng-if=
"!contextSrv.isSignedIn"
>
<a
href=
"login"
class=
"sidemenu-item"
target=
"_self"
>
<span
class=
"icon-circle sidemenu-icon"
><i
class=
"fa fa-fw fa-sign-in"
></i></span>
<span
class=
"sidemenu-item-text"
>
Sign in
</span>
</a>
</li>
</ul>
<ul
class=
"sidemenu sidemenu-small"
style=
"margin-top:50px"
ng-if=
"systemSection"
>
...
...
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