ShareFactoryFindRule Method (IContext, String, Int32, IUser, NullableInt32, NullableGuid) |
Namespace: AskiaPortalCmn
public static IShareRule FindRule( IContext context, string objectType, int objectId, IUser user, Nullable<int> surveyId = null, Nullable<Guid> moduleGuid = null )
This method return the more accurate share.
- If the share is apply on the group and the user, the share of the user will be returned.
- The share apply on group closer to the user will be returned.
The rule find could be a database record or a calculated rule, specially for administrators.
A user that can manage a group is like a membership of that group.
Find if the `template` with id 5, is share to the user.
var context = ContextFactory.CreateByUserGuid(Guid.Parse("20BE5F84-F006-49A0-9674-4B16A090AF2D")); var contextValidation = context.Validate(); if (!contextValidation.Success) { throw contextValidation.Exception; } var user = UserFactory.FindById(context, 2); if (user == null) { Console.WriteLine("The specified user doesn't exist, or the current user within the context could not access it"); } var share = ShareFactory.FindRule(context, "template", 5, user); if (share != null) { Console.WriteLine($@"The user {user.FirstName} {user.LastName} have the {share.Permission} on the `{share.ObjectType}` {share.ObjectId}"); } else { Console.WriteLine($@"The user {user.FirstName} {user.LastName} could not access the specified `template` object"); }