Esempio n. 1
0
 /// <summary>
 /// The Grant
 /// </summary>
 /// <param name="grants">The <see cref="PermissionSet"/></param>
 /// <param name="resourceType">The <see cref="PermissionResourceType"/></param>
 /// <param name="resourceId">The <see cref="string"/></param>
 /// <param name="childType">The <see cref="PermissionResourceType"/></param>
 /// <param name="subjectType">The <see cref="PermissionSubjectType"/></param>
 /// <param name="subjectId">The <see cref="string"/></param>
 public void Grant(PermissionSet grants, PermissionResourceType resourceType, string resourceId, PermissionResourceType childType, PermissionSubjectType subjectType, string subjectId)
 {
     Permission.Grant(client, grants, resourceType, resourceId, childType, subjectType, subjectId);
 }
Esempio n. 2
0
 //
 /// <summary>
 /// The Revoke
 /// </summary>
 /// <param name="grants">The <see cref="PermissionSet"/></param>
 /// <param name="resourceType">The <see cref="PermissionResourceType"/></param>
 /// <param name="subjectType">The <see cref="PermissionSubjectType"/></param>
 /// <param name="subjectId">The <see cref="string"/></param>
 public void Revoke(PermissionSet grants, PermissionResourceType resourceType, PermissionSubjectType subjectType, string subjectId)
 {
     Revoke(grants, resourceType, string.Empty, subjectType, subjectId);
 }
Esempio n. 3
0
 /// <summary>
 /// The Grant
 /// </summary>
 /// <param name="grants">The <see cref="PermissionSet"/></param>
 /// <param name="resourceType">The <see cref="PermissionResourceType"/></param>
 /// <param name="resourceId">The <see cref="string"/></param>
 /// <param name="subjectType">The <see cref="PermissionSubjectType"/></param>
 /// <param name="subjectId">The <see cref="string"/></param>
 public void Grant(PermissionSet grants, PermissionResourceType resourceType, string resourceId, PermissionSubjectType subjectType, string subjectId)
 {
     Grant(grants, resourceType, resourceId, PermissionResourceType.none, subjectType, subjectId);
 }
Esempio n. 4
0
 /// <summary>
 /// The Revoke
 /// </summary>
 /// <param name="client">The <see cref="RestClient"/></param>
 /// <param name="grants">The <see cref="PermissionSet"/></param>
 /// <param name="resourceType">The <see cref="PermissionResourceType"/></param>
 /// <param name="resourceId">The <see cref="string"/></param>
 /// <param name="childType">The <see cref="PermissionResourceType"/></param>
 /// <param name="subjectType">The <see cref="PermissionSubjectType"/></param>
 /// <param name="subjectId">The <see cref="string"/></param>
 public static void Revoke(RestClient client, PermissionSet grants, PermissionResourceType resourceType, string resourceId, PermissionResourceType childType, PermissionSubjectType subjectType, string subjectId)
 {
     ChangePermission(client, PermissionAction.revoke, grants, resourceType, resourceId, childType, subjectType, subjectId);
 }
Esempio n. 5
0
 /// <summary>
 /// The Revoke
 /// </summary>
 /// <param name="client">The <see cref="RestClient"/></param>
 /// <param name="grants">The <see cref="PermissionSet"/></param>
 /// <param name="resourceType">The <see cref="PermissionResourceType"/></param>
 /// <param name="resourceId">The <see cref="string"/></param>
 /// <param name="subjectType">The <see cref="PermissionSubjectType"/></param>
 /// <param name="subjectId">The <see cref="string"/></param>
 public static void Revoke(RestClient client, PermissionSet grants, PermissionResourceType resourceType, string resourceId, PermissionSubjectType subjectType, string subjectId)
 {
     Revoke(client, grants, resourceType, resourceId, PermissionResourceType.none, subjectType, subjectId);
 }
Esempio n. 6
0
 /// <summary>
 /// The Grant
 /// </summary>
 /// <param name="client">The <see cref="RestClient"/></param>
 /// <param name="grants">The <see cref="PermissionSet"/></param>
 /// <param name="resourceType">The <see cref="PermissionResourceType"/></param>
 /// <param name="subjectType">The <see cref="PermissionSubjectType"/></param>
 /// <param name="subjectId">The <see cref="string"/></param>
 public static void Grant(RestClient client, PermissionSet grants, PermissionResourceType resourceType, PermissionSubjectType subjectType, string subjectId)
 {
     Grant(client, grants, resourceType, string.Empty, subjectType, subjectId);
 }
Esempio n. 7
0
        /// <summary>
        /// The ChangePermissionsion
        /// </summary>
        /// <param name="client">The <see cref="RestClient"/></param>
        /// <param name="action">The <see cref="PermissionAction"/></param>
        /// <param name="grants">The <see cref="PermissionSet"/></param>
        /// <param name="resourceType">The <see cref="PermissionResourceType"/></param>
        /// <param name="resourceId">The <see cref="string"/></param>
        /// <param name="childType">The <see cref="PermissionResourceType"/></param>
        /// <param name="subjectType">The <see cref="PermissionSubjectType"/></param>
        /// <param name="subjectId">The <see cref="string"/></param>
        private static void ChangePermission(RestClient client, PermissionAction action, PermissionSet grants,
                                             PermissionResourceType resourceType, string resourceId, PermissionResourceType childType,
                                             PermissionSubjectType subjectType, string subjectId)
        {
            var uri = string.Format("/perms/{0}/{1}/{2}/{3}/{4}/{5}",
                                    action.ToString().ToLower(),
                                    resourceType.ToString().ToLower(),
                                    resourceId,
                                    childType == PermissionResourceType.none ? string.Empty : childType.ToString(),
                                    subjectType.ToString().ToLower(),
                                    subjectId
                                    );

            var permsManage           = PermissionsToList(grants.Manage);                    //.Where(o=>o == "R" ||o=="U" || o == "D");
            var permsAuthorize        = PermissionsToList(grants.Authorize);                 //.Where(o=>o =="R" || o == "U" || o == "D"  || o == "A");
            var permsCreatedManage    = PermissionsToList(grants.CreatedDocument.Manage);    //.Where(o => o == "R" || o == "U" || o == "D");
            var permsCreatedAuthorize = PermissionsToList(grants.CreatedDocument.Authorize); // .Where(o => o == "R" || o == "U" || o == "D" || o == "A");

            object grantBody = new { };

            if (!permsCreatedManage.Any() && !permsCreatedAuthorize.Any())
            {
                grantBody = new
                {
                    manage    = permsManage,
                    authorize = permsAuthorize
                };
            }
            else
            {
                var created = new
                {
                    manage    = permsCreatedManage,
                    authorize = permsCreatedAuthorize,
                };

                grantBody = new
                {
                    manage           = permsManage,
                    authorize        = permsAuthorize,
                    created_document = created
                };
            }

            uri = uri.Replace("//", "/");

            var request = new RestRequest(uri, Method.POST);

#if DEBUG
            var bodyTxt = JsonConvert.SerializeObject(grantBody);
#endif

            Rest.Execute <BasicResponse>(client, request, grantBody);
        }