Example #1
0
        /// <summary>
        /// Tells whether the given user is allowed to change visibility of the current snippet
        /// </summary>
        /// <param name="user"></param>
        /// <param name="toChangeGroupOrUnshare">true if this method is used to check if the user is able to change the group or unshare the snippet</param>
        /// <returns></returns>
        public bool IsAllowedToChangeVisibility(User user, bool toChangeGroupOrUnshare = false)
        {
            if (user == null)
                return false;

            if (toChangeGroupOrUnshare)
                return (CreatorID == user.ID) && user.BelongsToGroup(OwnerGroupID); //the user should be the creator and belong to the owner group
            else
                return user.AdministerGroup(OwnerGroupID); //the user should be an admin of the group that owns the snippet
        }
Example #2
0
        /// <summary>
        /// Tells whether the given user is allowed to modify the content of the current snippet and/or to delete it
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool IsAllowedToEdit(User user)
        {
            if (user == null)
                return false;

            //the user should be an admin of the group that owns the snippet:
            if (user.AdministerGroup(OwnerGroupID))
                return true;
            
            //or can be a simple user, if he is the creator of the snippet:
            return ((user.ID == CreatorID) && user.BelongsToGroup(OwnerGroupID));         
        }
Example #3
0
        /// <summary>
        /// Tells whether the given user is allowed to view the content of the current snippet
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool IsAllowedToView(User user)
        {
            if (Visibility >= ShareOption.Public)
                return true;
            if (user == null)
                return false;

            return user.BelongsToGroup(OwnerGroupID);
        }