Click or drag to resize

IPermissions Interface

Manage the list of a user permissions.

Namespace:  AskiaPortalCmn.Common
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public interface IPermissions

The IPermissions type exposes the following members.

Properties
  NameDescription
Public propertyIsModified
Flag to indicates if the object has been modified since his initialization.
Top
Methods
  NameDescription
Public methodCan(PermissionTo)
Returns the value of the specified `AskiaPortal` permission as boolean.
Public methodCan(String, NullableGuid)
Returns the value of the specified permission as boolean.
Public methodCode exampleChange(AccessTo, AccessLevel)
Change the value of the specified `AskiaPortal` permission.
It will not save the change in the database unless you explicitly call the Save method.
Public methodChange(PermissionTo, Boolean)
Change the value of the specified `AskiaPortal` permission.
It will not save the change in the database unless you explicitly call the Save method.
Public methodCode exampleChange(String, AccessLevel, NullableGuid)
Change the value of the specified permission.
It will not save the change in the database unless you explicitly call the Save method.
Public methodChange(String, Boolean, NullableGuid)
Change the value of the specified permission.
It will not save the change in the database unless you explicitly call the Save method.
Public methodCode exampleClear
Remove all permissions of the user
It will not save the change in the database unless you explicitly call the Save method.
Public methodGetAllItems
Returns all permission items.
Public methodGetItems
Returns the permission items of the specified module guid.
Public methodGetLevel(AccessTo)
Returns the value of the specified `AskiaPortal` permission.
Public methodGetLevel(String, NullableGuid)
Returns the value of the specified permission.
Public methodReload
Reload the permissions using the current database values.
Public methodRemove(AccessTo)
Remove the specified AskiaPortal permission item.
It will not save the change in the database unless you explicitly call the Save method.
Public methodRemove(PermissionTo)
Remove the specified AskiaPortal permission item.
It will not save the change in the database unless you explicitly call the Save method.
Public methodRemove(String, NullableGuid)
Remove the specified permission item.
It will not save the change in the database unless you explicitly call the Save method.
Public methodRemoveAll
Remove all permissions of the specified module.
It will not save the change in the database unless you explicitly call the Save method.
Public methodSave
Save the modification in the database if the object has been modified.
Top
Examples

This example looks the permission of the current user to access `groups`.

using system;
using AskiaPortalCmn;

namespace MyApp 
{
    class Program
    {
         static void Main(string[] args)
         {
                // Initialize the current module
                AskiaPortalCmnApi.InitializeModule(Guid.Parse("26f6ab8b-2fdb-4f4f-ad14-7507892846a5"));

                var context = ContextFactory.CreateByLoginAndPassword("login", "secret");
                var contextValidation = context.Validate();
                if (!contextValidation.Success)
                {
                    Console.Error.Write(contextValidation.Exception.Message);
                    return;
                }
                switch (context.User.Permissions.GetLevel(AccessTo.Groups))
                {
                    case AccessLevel.None:
                        Console.WriteLine("You don't have permission to access groups");
                        break;
                    case AccessLevel.ReadOnly:
                        Console.WriteLine("You can only view groups");
                        break;
                    case AccessLevel.EditOnly:
                        Console.WriteLine("You can only edit groups");
                        break;
                    case AccessLevel.CreateAndEdit:
                        Console.WriteLine("You're allowed to view, create, edit groups");
                        break;
                    case AccessLevel.FullControl:
                        Console.WriteLine("You have full control on groups (view, create, edit, delete and restore)");
                        break;
                }
         }
    }
}
See Also