I know this is only javascript secure but I was thinking of creating a plugin with some javascript to hide some tabs or properties from non admin users.
How easy is it to access the user type (ie Writer/Editor/Translator/Administrator) from javascript. I think this should be possible but not sure how.
Thanks
[update]
tested plugins to make sure I could run javascript but it seems to run before the back office has finished loading controls and tabs. Is there any way (short of a brute force setTimeout) to delay until Umbraco has done its stuff?
'Yes, this happens' popped up, but neither of the other alerts fired - I tried putting breakpoints in developer tools but it looks like the controller doesn't trigger .
I have created custom property editors and the controller triggers there - not sure why this one doesn't?
All I want to do is have some javascript/css on every document editing form that has access to the userService - which I think (from what you have said) means I need to use angularjs and a controller.
Ok, got it. So you can get your js loading up via a package.manifest but you need a view to bind the controller, only way I think you can do that is to add/hack it into a existing core view, likely just needs to be a single div with ng-controller
Custom js back office access user type
I know this is only javascript secure but I was thinking of creating a plugin with some javascript to hide some tabs or properties from non admin users.
How easy is it to access the user type (ie Writer/Editor/Translator/Administrator) from javascript. I think this should be possible but not sure how.
Thanks
[update] tested plugins to make sure I could run javascript but it seems to run before the back office has finished loading controls and tabs. Is there any way (short of a brute force setTimeout) to delay until Umbraco has done its stuff?
Hi Tim
I did this before which should work for you:
userService.getCurrentUser().then(function (user) { if (user.userType !== "admin") { hidesomething(); } });
Jeavon
Thanks Jeavon
As it looks like you were hiding something on the Umbraco canvas, did you find a way to delay until the controls were loaded?
Tried this
Uncaught ReferenceError: userService is not defined
What do I need to add to my js?
Thanks
I was hiding within the editor so didn't have a issue. You need to add the userService to your function to be injected
function myFunction($rootScope, $scope, userService) {
How about https://our.umbraco.org/projects/collaboration/backoffice-tweaking/
--Dirk
Sorry for being dense, but I am trying to get to grips with this stuff.
I tried putting this in my js file mentioned in the package.manifest
'Yes, this happens' popped up, but neither of the other alerts fired - I tried putting breakpoints in developer tools but it looks like the controller doesn't trigger .
I have created custom property editors and the controller triggers there - not sure why this one doesn't?
Assuming you have a view that utilises the controller?
How do you add a view : I have done it in custom property editors eg
but this is for a plugin for the whole page not just a property editor : can I just add
Something will need to load your view, is it a dashboard or tree or....?
All I want to do is have some javascript/css on every document editing form that has access to the userService - which I think (from what you have said) means I need to use angularjs and a controller.
It wouldn't be tied to any property editor.
Does that make any sense?
Ok, got it. So you can get your js loading up via a package.manifest but you need a view to bind the controller, only way I think you can do that is to add/hack it into a existing core view, likely just needs to be a single div with ng-controller
Maybe something like /Umbraco/Views/Content/edit.html
I'm gonna try this.
Thanks again.
is working on a reply...