DD-31 dashboard anonymous accessible only with hash#56
Conversation
ghost
commented
Sep 13, 2018
- add hash to instance in order to access the dashboard report page with a special hash code, when not logged in
- change default routes from RouteConfig
- edit TimeZoneController action, because the id, which is a string in the timezone case, is mistaken as an action controller
- change report angular controller, to allow the page to be loaded if the user is logged and the page to be loaded in anonymous mode if the user is not logged and only if the hash is correct for that specific report page
DailyReportWeb/app/app.js
Outdated
| report: function ($http, $location, $route) { | ||
| var params = { instanceId: $route.current.params.instanceId, hash: $route.current.params.hash }; | ||
|
|
||
| $http.get('api/report/isDashboardAvailable', { params: params }) |
There was a problem hiding this comment.
Do we need this? Can't we just have the page with a message instead? Like "No content yet" or something like that.
There was a problem hiding this comment.
Yes, but before that I need to make sure the whole url is ok (instanceId and instance hash). Because I could just guess the instanceId, and just put a random string instead of hash. This method checks if the url is ok.
There was a problem hiding this comment.
Why not put directly the hash as a query string param? So it needs to match that in order to get you to the dashboard.
There was a problem hiding this comment.
I don't exactly understand. I still need to make a call to the server to check on that side if the hash is ok. The alternative would be to get the hash before and store it in the js, but that's just bad. Another alternative is to make the get of the dashboard with hash as well, and to throw an error which will come on js and check if it's the one related to the hash.
Are you talking about the last option?
There was a problem hiding this comment.
yes, i think he is thinking about the last option. it's kind of weird to have an endpoint that checks if the dashboard is available. when you request the dashboard, if it's not available, just return there a boolean or something
| routeTemplate: "api/{controller}/{id}", | ||
| defaults: new { id = RouteParameter.Optional } | ||
| defaults: new { id = RouteParameter.Optional }, | ||
| constraints: new { id = @"^$|\d+"} |
There was a problem hiding this comment.
Not sure this is the best solution. The id is not necessarily long. There can be string id's as well in the future.
There was a problem hiding this comment.
I came across this problem, but I found no other way to make it generic. If the id should be a string, then the method should be named exactly and the parameter received with FromUri.
There was a problem hiding this comment.
Where does this problem occur? So that I can have a look at the controller
There was a problem hiding this comment.
App.js, Timezone. I changed in this pull request as well.
There was a problem hiding this comment.
The instances controller works the same way. There is one method with Get() and one with Get(id). And they worked both.
The mistake that you do is that you pass the name of the method and it is considered to be the id. If you want the get the resources you do: http.get(api/controller) -> this gets the list. http.get(api/controller/id) -> gets the element. Try this way without the routes changed. It should work.
There was a problem hiding this comment.
Ok, and what happens if I want multiple parameters? Also, there is one hardcoded route for the account controller, so making a generic change for the difference between the id and action seems like a good thing to do.
DailyReportWeb/app/report.js
Outdated
| ctrl.isLoading = true; | ||
|
|
||
| $http.get("/api/report/" + ctrl.instanceId) | ||
| $http.get("/api/report/?instanceId=" + ctrl.instanceId + "&hash=" + ctrl.hash + "&isAuthenticated=" + isAuth) |
There was a problem hiding this comment.
remove the "/" here. it should be "report?instanceId="
| public List<DashboardItem> Items { get; set; } | ||
|
|
||
|
|
||
| public static DashboardData Unavailable |
There was a problem hiding this comment.
make this a method instead of a property. not all objects of type DashboardData have an invalid DashboardData property on them.
Instead, just make this as a method that returns the same thing. Also keep the name.