Yet Another Forum.NET
»
YAF Development
»
YAF Customizing
»
Only thread starters and moderators can read a topic
Rank: YAF Forumling
Joined: 5/3/2010(UTC) Posts: 4
|
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.
|
|
|
|
|
|
|
|
|
|
Rank: YAF Forumling
Joined: 5/3/2010(UTC) Posts: 4
|
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: Code:
else if (!this.PageContext.ForumReadAccess)
{
YafBuildLink.AccessDenied();
}
to this: Code:
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 
|
|
|
|
|
|
 Rank: YAF DeveloperJoined: 3/6/2010(UTC) Posts: 2,134   Location: Berlin, Germany Thanks: 52 times Was thanked: 742 time(s) in 635 post(s)
|
Simply change the forum read access and add a check if the current user matches the topic starter user id Code:
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();
}
|
|
|
|
|
|
|
Rank: YAF Forumling
Joined: 4/2/2012(UTC) Posts: 4
|
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
|
|
|
|
|
|
Rank: YAF Forumling
Joined: 4/2/2012(UTC) Posts: 4
|
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
|
|
|
|
|
|
 Rank: YAF DeveloperJoined: 3/6/2010(UTC) Posts: 2,134   Location: Berlin, Germany Thanks: 52 times Was thanked: 742 time(s) in 635 post(s)
|
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 Code:
// 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();
}
|
|
|
|
|
|
|
Rank: YAF Forumling
Joined: 4/2/2012(UTC) Posts: 4
|
`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
|
|
|
|
|
|
 Rank: YAF DeveloperJoined: 3/6/2010(UTC) Posts: 2,134   Location: Berlin, Germany Thanks: 52 times Was thanked: 742 time(s) in 635 post(s)
|
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... Code:
// 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();
}
|
|
|
|
|
|
|
Rank: YAF Forumling
Joined: 4/2/2012(UTC) Posts: 4
|
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
|
|
|
|
|
|
Rank: YAF Camper
Joined: 7/23/2012(UTC) Posts: 28   Location: Ha Noi Thanks: 6 times
|
I understand, thank you very much for the information above. |
|
|
|
|
|
|
| Users browsing this topic |
|
guest
|
Yet Another Forum.NET
»
YAF Development
»
YAF Customizing
»
Only thread starters and moderators can read a topic
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.