YAFLogo

niemiro
  • niemiro
  • 52.4% (Neutral)
  • YAF Forumling Topic Starter
12 years ago
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
12 years ago
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
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
12 years ago
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();
            }
johntigner
12 years ago
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
12 years ago
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
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
12 years ago

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

Originally Posted by: johntigner 

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();
            }

johntigner
12 years ago
`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
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
12 years ago

`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

Originally Posted by: johntigner 

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();
            }
johntigner
12 years ago
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
  • kdtbzvn
  • 50.2% (Neutral)
  • YAF Lover
12 years ago
I understand, thank you very much for the information above.
[URL="http://relam.vn"]mua sắm[/url]|[URL="http://tbz.vn"]rao vat[/URL] | [URL="http://dienhoatructuyen.com.vn"]Dien hoa[/URL]