Example #1
0
        /// <summary>
        /// Gets the highest permission (role) name that the current user has if they have access to the object
        /// </summary>
        /// <param name="webUrl">The URL for the SP site</param>
        /// <param name="securableObject">An object that contains the Parent and Object ID's
        ///                                 SecurableParentUid: The ID of the securable parent (Guid.Empty for projects),
        ///                                 SecurableObjectUid: The ID of the securable object (root map UID or project UID if securing a project)</param>
        /// <returns>The Glyma permission level name if the user has access or null if the user doens't have access</returns>
        public GetPermissionLevelResponse GetPermissionLevelForObject(string webUrl, GlymaSecurableObject securableObject)
        {
            GetPermissionLevelResponse result = new GetPermissionLevelResponse()
            {
                HasError = false
            };

            SecurityContextManager securityContext = new SecurityContextManager(webUrl);

            if (securityContext.CurrentUser.IsUserMapReader())
            {
                GlymaPermissionLevel highestPermissionLevel = GlymaPermissionLevel.None;
                try
                {
                    GetCurrentUserAccessToObjectResponse response = securityContext.CurrentUser.GetCurrentUserAccessToObject(securableObject, false);
                    if (!response.HasError)
                    {
                        if (response.HasAccess)
                        {
                            //if the user has access to the object (project or root map) get there highest permission level
                            highestPermissionLevel = response.HighestPermissionLevel;
                        }
                        else
                        {
                            //The user has no access
                            result.Result = GlymaPermissionLevel.None;
                        }
                    }
                    else
                    {
                        result.HasError     = true;
                        result.ErrorMessage = response.ErrorMessage;
                    }
                }
                catch (Exception ex)
                {
                    result.HasError     = true;
                    result.ErrorMessage = ex.Message;
                }
                if (!result.HasError)
                {
                    result.Result = highestPermissionLevel;
                }
            }
            else
            {
                result.HasError     = true;
                result.ErrorMessage = "Access Denied. User does not have permissions to access this web service method.";
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Gets the highest permission level that a user has
        /// </summary>
        /// <param name="webUrl"></param>
        /// <returns></returns>
        public GetPermissionNameResponse GetUsersPermissionLevelName(string webUrl)
        {
            GetPermissionNameResponse result = new GetPermissionNameResponse()
            {
                HasError = false
            };

            GetPermissionLevelResponse response = GetUsersPermissionLevel(webUrl);

            if (!response.HasError)
            {
                result.Result = GlymaPermissionLevelHelper.GetPermissionLevelName(response.Result);
            }
            else
            {
                result.HasError     = true;
                result.ErrorMessage = response.ErrorMessage;
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// Gets the highest permission (role) name that the current user has if they have access to the object
        /// </summary>
        /// <param name="webUrl">The URL for the SP site</param>
        /// <param name="securableObject">An object that contains the Parent and Object ID's
        ///                                 SecurableParentUid: The ID of the securable parent (Guid.Empty for projects),
        ///                                 SecurableObjectUid: The ID of the securable object (root map UID or project UID if securing a project)</param>
        /// <returns>The Glyma permission level name if the user has access or null if the user doens't have access</returns>
        public GetPermissionNameResponse GetPermissionNameForObject(string webUrl, GlymaSecurableObject securableObject)
        {
            GetPermissionNameResponse result = new GetPermissionNameResponse()
            {
                HasError = false
            };

            GetPermissionLevelResponse response = GetPermissionLevelForObject(webUrl, securableObject);

            if (!response.HasError)
            {
                result.Result = GlymaPermissionLevelHelper.GetPermissionLevelName(response.Result);
            }
            else
            {
                result.HasError     = true;
                result.ErrorMessage = response.ErrorMessage;
            }

            return(result);
        }
Example #4
0
        /// <summary>
        /// Gets the highest permission level that a user has
        /// </summary>
        /// <param name="webUrl"></param>
        /// <returns></returns>
        public GetPermissionLevelResponse GetUsersPermissionLevel(string webUrl)
        {
            GetPermissionLevelResponse result = new GetPermissionLevelResponse()
            {
                HasError = false
            };
            GlymaPermissionLevel permissionLevel = GlymaPermissionLevel.None;

            GetIsUserGlymaSecurityManagerResponse isSecurityManager = GetIsUserGlymaSecurityManager(webUrl);

            if (!isSecurityManager.HasError)
            {
                if (isSecurityManager.Result)
                {
                    permissionLevel = GlymaPermissionLevel.GlymaSecurityManager;
                    result.Result   = permissionLevel;
                }
                else
                {
                    try
                    {
                        SecurityContextManager context    = new SecurityContextManager(webUrl);
                        IGlymaPermission       permission = context.CurrentUser.GetHighestPermissionLevel();
                        permissionLevel = permission.PermissionLevel;
                        result.Result   = permissionLevel;
                    }
                    catch (Exception e)
                    {
                        result.HasError     = true;
                        result.ErrorMessage = e.Message;
                    }
                }
            }
            else
            {
                result.HasError     = true;
                result.ErrorMessage = isSecurityManager.ErrorMessage;
            }
            return(result);
        }