Click or drag to resize

ShareFactoryFindRule Method (IContext, ShareObjectType, Int32, IUser, NullableInt32)

Find or calculate the appropriate share rule applied on the specified `AskiaPortal` object and user, return null if no rule found.

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public static IShareRule FindRule(
	IContext context,
	ShareObjectType objectType,
	int objectId,
	IUser user,
	Nullable<int> surveyId = null
)

Parameters

context
Type: AskiaPortalCmnIContext
Context of execution.
objectType
Type: AskiaPortalCmnShareObjectType
Type of `AskiaPortal` object to find.
objectId
Type: SystemInt32
Id of the object to find.
user
Type: AskiaPortalCmnIUser
Contact to find.
surveyId (Optional)
Type: SystemNullableInt32
Id of the survey, to scope the search.

Return Value

Type: IShareRule
Return null if the share rule was not found or if the user within the context doesn't have enough right to access it
Remarks

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.

Examples

Find if the `AskiaPortal` survey 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, ShareObjectType.Survey, 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");
}
See Also