Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Some help with delegates

edited April 2007 in Vanilla 1.0 Help
I've begun to write an extension, and have stumbled across a problem and was hoping I could get some help. I've tried searching around a bit here in the forums, but I haven't been able to find anything that really solves things for me so far.

The extension I'm writing is supposed to give users, under certain conditions, the ability to edit posts of other users. Now, adding the edit links went well, but the problem I'm having is that Vanilla detects that the post that is getting edited isn't getting edited by the author of the post, and understandably returns an error. So to beat Vanilla to it I am using the PreLoadData delegate in DiscussionForm. The problem is that when that delegate is called, I can't get all the data I need from the DiscussionForm.

I need to get the Category ID, and the User ID of whoever started the discussion, but I can't figure out how. The data can be accessed if I use PostLoadData, but then it's too late, and Vanilla will already have stopped things.

So I'm wondering if anyone can suggest how I should solve this, or point me in the right direction. I'd be grateful for any suggestions.

Comments

  • Options
    can't u create a "Edit Comments" role and temporary assign those roles to users that want to edit other comments
  • Options
    Wow. Fast reply. :)

    Yeah, that's kind of what I had in mind for setting the permissions (it's either changing the role, or changing PERMISSION_EDIT_COMMENTS). The problem isn't how I change the permissions though, it's how I get the Category ID and the User ID, because I need to know what they are before I start handing out permissions.
  • Options
    edited April 2007
    Ok
    function AllowEdit(&$CommentGrid) { $Comment = &$CommentGrid->DelegateParameters['Comment']; } $Context->AddToDelegate('CommentGrid', 'You have to find where it should go', 'AllowEdit');
    thats it
    check the $Comment array and u will find all sort of things like
    $Comment['CommentID'] $Comment['AuthUserID'] $Comment['CategoryID']
    plus whole bunch of stuff about that particular comment
  • Options
    Thanks for the suggestion, but alas, it didn't work. The problem is that all those things aren't set when I call them. The only things that get set before PreLoadData are the following: $this->Name = 'DiscussionForm'; $this->CommentFormAttributes = ''; $this->DiscussionFormAttributes = ''; $this->Constructor($Context); $this->FatalError = 0; $this->EditDiscussionID = 0; $this->CommentID = ForceIncomingInt('CommentID', 0); $this->DiscussionID = ForceIncomingInt('DiscussionID', 0); $this->DiscussionFormattedForDisplay = 0; $this->ValidActions = array('SaveDiscussion', 'SaveComment', 'Reply');
    Discussion, comment, discussionmanager, and commentmanager are all set after PreLoadData, and there's no delegate to hook on to after the data has loaded but before the validation is done.

    I thought of that I perhaps can just set PERMISSION_EDIT_COMMENTS to 1 for everyone at PreLoadData, and then copy over the permissions check and do it myself in a function that I call at PostLoadData. That doesn't seem very neat to me though, and I would prefer to somehow get the Discussion in the function that hooks on to PreLoadData, but if that isn't possible I guess I might give the alternative a try.
  • Options
    if ur doing it for urself then u just add a new delegate anywhere u want.
    if its going to be a extension then mention it in the readme that a new delegate is required
  • Options
    Well, I went with giving full editing rights to everyone at PreLoadData. Then at PostLoadData, I do the user & category check, and perform the normal permission checks (copied from DiscussionManager) for anyone who doesn't fall under my special case, and restore permissions to what they were from the start. It's not ideal but it works.

    I didn't want to add another delegate, in that case I might as well just have dropped the whole block of code right in there. But anyway, thanks for the help. :)
This discussion has been closed.