Comments (3)
Add this class in a file next to your UserEndpoint.cs:
namespace MyApplication
{
using Serenity;
using Serenity.ComponentModel;
using System;
using System.Collections.Generic;
[ScriptInclude]
public class UserData
{
public String Username { get; set; }
public Dictionary<string, bool> Permissions { get; set; }
}
}
This method goes in UserEndpoint.cs to define a dynamic data script:
[NonAction, DataScript("UserData", CacheDuration = -1)]
public UserData GetUserData()
{
var result = new UserData();
var user = Authorization.UserDefinition as UserDefinition;
if (user == null)
{
result.Permissions = new Dictionary<string, bool>();
return result;
}
result.Username = user.Username;
result.Permissions = TwoLevelCache.GetLocalStoreOnly("UserPermissions:" + user.Id, TimeSpan.Zero,
UserPermissionRow.Fields.GenerationKey, () =>
{
var permissions = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
foreach (var permission in new UserPermissionRepository().ListPermissionKeys().Entities)
if (Authorization.HasPermission(permission))
permissions[permission] = true;
return permissions;
});
return result;
}
Build, transform templates and then place this class in MyApplication.Script
namespace MyApplication
{
using Serenity;
using System;
public class Authorization
{
public static UserData UserDefinition { get { return Q.GetRemoteData<UserData>("UserData"); } }
public static bool HasPermission(string permissionKey)
{
return UserDefinition.Permissions[permissionKey];
}
}
}
Now you can access user data / permissions from client side. Just don't trust this information as script side data can be modified by user anytime using developer console. Use it just for display purposes. Double check on server side.
from serenity.
Thanks !!!! I needed to show whether or not an "AddEqualityFilter " based on the user's role in the method CreateToolbarExtensions in a EntityGrid.
Thanks again
from serenity.
You're welcome
from serenity.
Related Issues (20)
- Inconsistent use of text settings for ApplyChangesButton vs other Buttons HOT 2
- [Bug report]: "The file is not a valid VSIX package" when trying to install the serene extension HOT 1
- [Bug report]: RTL Theme not Work with Farisi HOT 1
- [Bug report]: Sergen g Not work with oracle HOT 2
- [Bug report]: Run on IIS Error, help me HOT 1
- [Bug report]: grids are not using full height after upgrading to 6.8 HOT 5
- Opening the edit URL in a new browser tab first loads the listing page and then subsequently loads the entity. HOT 3
- Automatically displaying the editor popup within a panel when the 'Yes' option is selected in a confirmation popup. HOT 2
- [Bug report]: Dialog does not move to associated tab when a validation error occurs HOT 2
- [Bug report]: BasedOnRowPropertyNameAnalyzer inherited fields HOT 2
- HtmlContentEditor is not working when opened in Panel HOT 1
- .NET 8 Migration HOT 1
- Transitioning to System.Text.Json from Newtonsoft.Json HOT 1
- [Bug report]: Broken demo site sample: Other Form, One Toolbar HOT 1
- Autherization error HOT 3
- [Bug report]: Demo Site Northwind Orders Print Invoice HOT 2
- [Bug report]: getWidgetFrom not exist in corelib 8.1.5 HOT 1
- Multi Tenancy tutorial issue with claims principle
- [LookupEditor]: LookupEditor cannot be disabled HOT 1
- Column resizing not working in Firefox HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serenity.