Bool bReturn = true;



  • Directly from our beloved forum software:

            public static bool Validate(Section section, Permission permission, User user, Post p)
            {

       if(user.IsBlogAdministrator)
        return true;

                if(section == null || section.PermissionSet == null || user == null )
                    return false;

                bool bReturn = true;
                WeblogPermission fpFinal = section.ResolvePermission(user) as WeblogPermission;

                if((permission == (permission | Permission.Administer)) && bReturn )
                    bReturn &= fpFinal.Administer;

                if((permission == (permission | Permission.Attachment)) && bReturn )
                    bReturn &= fpFinal.Attachment;

                if((permission == (permission | Permission.Delete)) && bReturn )
                    bReturn &= fpFinal.Delete;

                if((permission == (permission | Permission.Post)) && bReturn )
                    bReturn &= fpFinal.Post;

                if((permission == (permission | Permission.Reply)) && bReturn )
                    bReturn &= fpFinal.Reply;

                if((permission == (permission | Permission.Sticky)) && bReturn )
                    bReturn &= fpFinal.Sticky;

                if((permission == (permission | Permission.View)) && bReturn )
                    bReturn &= fpFinal.View;

                return bReturn;
            }



  • @Savior said:

                WeblogPermission fpFinal = section.ResolvePermission(user) as WeblogPermission;

    Casting like this calls for a 'null reference check', otherwise cast the standard way:

                WeblogPermission fpFinal = (WeblogPermission)section.ResolvePermission(user);

    Maybe I overlooked, but this is the only WTF I found!


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.