niemiro
  •  niemiro
  • 52.4% (Neutral)
  • YAF Forumling Topic Starter
2012-03-04T19:02:01Z
Hello all!

I am hoping that this isn't too big a job. Basically, I want to create a single forum of my board which allows read access only to thread starters and moderators. I still want anyone to be able to create threads, just not read each other's threads.

I have looked around the source code a little, and I see that I need to call YafBuildLink.AccessDenied(). However, I don't know where I need to call this from (I see lots of places which look like they might be suitable), and I don't know how to check if the user is the thread starter.

Any help any of you could offer would be very greatly appreciated.
Sponsor
niemiro
  •  niemiro
  • 52.4% (Neutral)
  • YAF Forumling Topic Starter
2012-03-10T08:30:38Z
Hello,

I still need a little bit of help here, and any you could offer would be very greatly appreciated. I am thinking about editing the posts.ascx.cs file, and in the Page_Load event, changing this:

else if (!this.PageContext.ForumReadAccess)
{
	YafBuildLink.AccessDenied();
}

to this:

else if (!this.PageContext.ForumReadAccess || (this.PageContext.PageForumID == 3 && !this.PageContext.ForumModeratorAccess && !Thread_Starter))
{
	YafBuildLink.AccessDenied();
}

However, I am still having trouble working out the thread starter: "!Thread_Starter"

Please help me 🙂
tha_watcha
2012-03-10T10:45:50Z
Simply change the forum read access and add a check if the current user matches the topic starter user id

if (this.PageContext.IsGuest && !this.PageContext.ForumReadAccess)
            {
                // attempt to get permission by redirecting to login...
                this.Get<IPermissions>().HandleRequest(ViewPermissions.RegisteredUsers);
            }
            else if (!this.PageContext.ForumReadAccess)
            {
                YafBuildLink.AccessDenied();
            }
            
           // Check if user is topic starter
            if (this.PageContext.PageUserID != this._topic["UserID"].ToType<int>())
            {
                 YafBuildLink.AccessDenied();
            }

UserPostedImage
johntigner
2012-04-04T04:30:52Z
Basically i'm a newbie to Yaf and need some help. .......I was wondering if someone could help me understand how to implement this code.

Thanks
johntigner
2012-04-19T12:48:27Z
After I put the code in, now only the threadstarter can open the topic. admin and moderators or no one else can open the topic.
Someone please help
tha_watcha
2012-04-19T13:05:50Z
Originally Posted by: johntigner 

After I put the code in, now only the threadstarter can open the topic. admin and moderators or no one else can open the topic.
Someone please help



Then you need to check if the user is an admin or a mod

// Check if user is topic starter or admin or forum moderator
            if (this.PageContext.PageUserID != this._topic["UserID"].ToType<int>() && (!this.PageContext.IsAdmin || !this.PageContext.IsForumModerator))
            {
                YafBuildLink.AccessDenied();
            }


UserPostedImage
johntigner
2012-04-27T19:29:57Z
`Thanks watcha this code is better it blocks everyone but the thread starter and the admins ..... i created the role moderator with is mod checked ...if i assign a user the moderator role they cannot open the topic ... only the thread_starter and admin can open the topics .... mods have mod acess in the forum.

Please tell me what i,m doing wrong ...... i donnot want the moderators to be able to change the Yaf confirugations
tha_watcha
2012-04-28T15:03:41Z
Originally Posted by: johntigner 

`Thanks watcha this code is better it blocks everyone but the thread starter and the admins ..... i created the role moderator with is mod checked ...if i assign a user the moderator role they cannot open the topic ... only the thread_starter and admin can open the topics .... mods have mod acess in the forum.

Please tell me what i,m doing wrong ...... i donnot want the moderators to be able to change the Yaf confirugations



sorry code was wrong try this...

// Check if user is topic starter or admin or forum moderator
            if (this.PageContext.PageUserID != this._topic["UserID"].ToType<int>() && !this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess)
            {
                YafBuildLink.AccessDenied();
            }

UserPostedImage
johntigner
2012-05-04T13:18:04Z
Thanks for your code update i will replace with the new code tomorrow and send you an update.

Just one other thing Even though unauthorized people cannot read the topic, they can still see the topic title .....Can we hide the topic titles as well?

Thank You For All Your Help
John



kdtbzvn
2012-07-24T03:34:18Z
I understand, thank you very much for the information above.

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved