Please upgrade here. These earlier versions are no longer being updated and have security issues.

inconsistent permission behavior on new forum migrated from smf2

Im using latest vanilla

After the migrations, users had no groups and were not verified :anguished: .
So i ran this code on sql:
insert ignore GDN_UserRole(UserID, RoleID)
select UserID, RoleID
from GDN_User
where Admin = 0

With roledid being the proper value of course. It added everyone to the members role.
Under the members role ppl cant announce anything, yet, in my forum ppl can...
currently when i visit any profile what i see is:
Roles: Not Verified, , Member

I'm worried that the , , part is giving users unintended permissions, what should i do? I'm new to vanilla, I actually have a lot of questions, that's the first one.

Thanks for any response!

Tagged:
«1

Comments

  • I think i found the problem, it seems to want to set the new member to role 8, except "member" is not role 8 on my system due to the import from smf... so it fails and creates bogus structures that i have to clean later on.

  • Also, its shameful vanilla doesnt have a way to send a newsletter or similar to users form the dashboard.

  • RiverRiver MVP
    edited August 2016

    @Kiori said:
    I think i found the problem, it seems to want to set the new member to role 8, except "member" is not role 8 on my system due to the import from smf... so it fails and creates bogus structures that i have to clean later on.

    Yep - imports can be troublesome with respect to roles and roleid's use the standard roles and roleids - things will be smoother sailing.

    @Kiori said:
    Also, its shameful vanilla doesnt have a way to send a newsletter or similar to users form the dashboard.

    You could change that shame by writing a plugin that does what you want. or you could use mailchimp and let users subscribe if they want it, rathen than forcing it down their throats. There is also a email subscribe and emaildiscussion plugin which could do something similar. But the tools, hooks etc are available to create you own template and bombard users who sign up for forum rather they want it or not.

    essentially - you want to look at the tables role, permissions, and role type tables

    I'm worried that the , , part is giving users unintended permissions, what should i do? I'm new to vanilla, I actually have a lot of questions, that's the first one.

    after you change the users to standard roles and roleids. verify permissions for each role.

    then test each role to see if what you think you have is what you have.

    https://vanillaforums.org/discussion/comment/241722/#Comment_241722

    https://vanillaforums.org/discussion/comment/233489/#Comment_233489

    essentially - you want to look at the threads above if you haven't seen them and waltz around.

    Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.

  • I did a load of database edits and fixed it.
    About the newsletter, well to me it was an essential feature because it allows to send announcements to everyone in case of dire need. But I see your point, and I will look into plugin making later on.

    Another question, do you know how the categories are sorted, on the side nav/bar, in the modern layout? I thought it was a db thing and edited the discussion's sort property but it altered nothing. It's clearly not related to that. Is it automated, do you know?

    I'm using the bootstrap theme for the moment.

    Thanks again!

  • RiverRiver MVP
    edited August 2016

    You should be able to sort drag and drop categories in dashboard to sort categories.

    you can sort "modules" in panel see here....

    https://vanillaforums.org/discussion/28420/frequently-asked-questions

    crude but might be useful, if you don't have lots of users. A dedicated program other than vanilla might be better if large user base.

    https://vanillaforums.org/addon/emaildiscussion-plugin

    Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.

    R_J
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    @River said:
    crude but might be useful, if you don't have lots of users. A dedicated program other than vanilla might be better if large user base.

    There is a this plugin https://vanillaforums.org/addon/mailchimpintegration-plugin
    But I do not know if it is working and I know there have been discussions concerning MailChimp as a service, though I do not remember why...

    I did not know about that plugin! This is a great idea. That would also be great for forum Messages...


  • I figured out the board problem. The imported categories had to be manually recreated, then everything just worked.

    I have a question, I want discussion tags to show beside their title. Kinda like categories do. Anyone know how to do that?

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    @Kiori said:
    I have a question, I want discussion tags to show beside their title. Kinda like categories do. Anyone know how to do that?

    Oh this would make a beautiful beginners plugin. Are you ready to take the challenge? I promise that you will not even need a dozen lines of code for that! (not counted is the plugin and class definition)


  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Start by copying the example plugin from GitHub https://github.com/vanilla/addons/blob/master/plugins/example/class.example.plugin.php
    Change everything in the header to reflect what you want.
    Delete the content between the curly braces of the class.
    Mind that now wherever you read "example" or "Example" you should replace it with a nice name you can think of "TagsAfterTitle" of whatever, but mind the upper/lower case spelling. You should stick to what you see (anywhere you see "example" start with a lower case letter and everywhere you see "Example" start with an upper case letter)

    Ready?

    Now where do you like to extend what you see/on which page? On .../discussions? That's what I guess. If it is .../discussion/123/anything then replace "discussions" with "discussion" in the next few lines.

    You have the possibility to insert snippets by using the event system in Vanilla. All you need to now is the controller ("discussions") and the event name. Go to /applications/vanilla/views/discussions and make a fulltext search for "fireEvent". If I do that (with notepad++) I get the following list:

     /vanilla/applications/vanilla/views/discussions/helper_functions.php (14 hits)
        Line 107:         $Sender->fireEvent('BeforeDiscussionName');
        Line 117:             $Sender->fireEvent('BetweenDiscussion');
        Line 128:             $Sender->fireEvent('BeforeDiscussionContent');
        Line 144:                     $Sender->fireEvent('AfterDiscussionTitle');
        Line 171:                     $Sender->fireEvent('AfterCountMeta');
        Line 190:                     $Sender->fireEvent('DiscussionMeta');
        Line 194:             <?php $Sender->fireEvent('AfterDiscussionContent'); ?>
        Line 304:         Gdn::controller()->fireEvent('BeforeDiscussionMeta');
        Line 309:         Gdn::controller()->fireEvent('AfterDiscussionLabels');
        Line 352:                 <?php $Sender->fireEvent('BeforeDiscussionTabs'); ?>
        Line 354:                 <?php $Sender->fireEvent('AfterAllDiscussionsTab'); ?>
        Line 369:                     $Sender->fireEvent('AfterBookmarksTab');
        Line 381:                 $Sender->fireEvent('AfterDiscussionTabs');
        Line 429:             $Sender->fireEvent('DiscussionOptions');
     /vanilla/applications/vanilla/views/discussions/index.php (2 hits)
        Line 14: $this->fireEvent('AfterPageTitle');
        Line 18: $this->fireEvent('AfterCategorySubtree');
     /vanilla/applications/vanilla/views/discussions/table.php (1 hit)
        Line 26: $this->fireEvent('AfterDescription');
     /vanilla/applications/vanilla/views/discussions/table_functions.php (3 hits)
        Line 57:         $Sender->fireEvent('BeforeDiscussionName');
        Line 70:             <?php $Sender->fireEvent('BeforeDiscussionContent'); ?>
        Line 83:                     $Sender->fireEvent('AfterDiscussionTitle');
    

    Now in theory everything you read here will allow you to insert something with the following lines in your plugin:

    public function discussionsController_SomeEventNameFromAbove_handler($sender, $args) {
        echo 'Hello World!';
    }
    

    There is an event called "AfterDiscussionTitle", have you spotted it already? Sounds promising. Put that in your plugin and look at the recent discussions...

    public function discussionsController_afterDiscussionTitle_handler($sender, $args) {
        echo 'Hello World!';
    }
    

    Magic!


    whu606Kiori
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator
    edited August 2016

    But you need "dynamic" content, no dumb "Hello World". You need information that is attached to the discussion.

    See those mysterious $sender, $args? $sender is a conventionally used name for an instance of the calling class. It took me a long time to understand that, but we do not have to understand it this time.

    If you have taken a look at the file where there was that fireEvent(), you might have seen "EventArguments". Almost everytime when an event is fired, there is some context information added as arguments and this arguments are passed to your plugins "event handler" as second parameter. We call this by convention $args. So $args is nothing more than an array with some values in there.
    One of those values is the "current" discussion. So you have access to the discussions Information by using $args['Discussion']. Test it!

    public function discussionsController_afterDiscussionTitle_handler($sender, $args) {
        echo 'The title is '.strlen($args['Discussion']).' characters long';
    }
    

    Not that this makes any sense and you wanted to work with tags. So look at that!

    public function discussionsController_afterDiscussionTitle_handler($sender, $args) {
        if (
            !property_exists($args['Discussion'], 'Tags') ||
            (count($args['Discussion']->Tags) == 0)
        ) {
            // No tags, nothing to do.
            return;
        }
        echo 'This discussion has '.count($args['Discussion']->Tags).' tag(s)';
    }
    

    Impressive, isn't it? We're almost there although we've just started! You were not interested in the number of tags but in the tags themselves, so let's proceed.

    public function discussionsController_afterDiscussionTitle_handler($sender, $args) {
        if (!property_exists($args['Discussion'], 'Tags')) {
            // No tags, nothing to do.
            return;
        }
        foreach ($args['Discussion']->Tags as $tag) {
            echo ' <span class="Tag">'.$tag['FullName'].'</span>';
        }
    }
    

    And that's it. Really. 9 lines of code. BAM!


    whu606Kiori
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    "How could I know what's in $args?"
    "How should I know about this Tags property?"

    All those are valid questions and it wouldn't be fair to expect that a beginner knows about that, but you would learn something like that very quick, believe me. Most of the time it starts with a decho(array_keys($args));...


    whu606Kiori
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    In the PluginInfo array, you could add some helpful things. I would add this 'RequiredApplications' => array('Vanilla' => '>=2.2'), to encourage users use the current version of Vanilla (and to show that you are not willing to support older versions) and this 'RequiredPlugins' => array('Tagging' => '>=1.8'),. Your plugin would be useless if the tagging plugin is not used. This makes an enabled tagging plugin a requirement for your plugin.


    whu606Kiori
  • RiverRiver MVP
    edited August 2016

    @R_J said:

    @River said:
    crude but might be useful, if you don't have lots of users. A dedicated program other than vanilla might be better if large user base.

    There is a this plugin https://vanillaforums.org/addon/mailchimpintegration-plugin
    But I do not know if it is working and I know there have been discussions concerning MailChimp as a service, though I do not remember why...

    Mailchimp plugin should be deleted @linc It will kill the ability to register and novice admins will never know why people can no longer register for the forum. The plugin will enable and then the views will break the forum. Should be moved to broken plugin category so none downloads it by mistake, if not deleted.

    Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.

  • @R_J
    Thanks for the reply, tomorrow i'll get on it and tell you how it went. If it works i hope to extend a lot of features to the tags system(like color coded styling).

  • @R_J
    Ok, first of thank you for the input.
    I was able to get the tag to show beside the title and styled the way i wanted,
    however I ideally I wanted it at the end of the meta tag, beside the category name. I tried search but there seems to be no helper function for that.
    Will I have to implement my own helper function to get it done?

    Another problem was I also want some tags to show beforeDiscussionTitle, also no helper for that.

    And on the disscussion proper, there is no after disscussion title helper, the closet i got was BeforeDiscussionDisplay which is bellow the title.

    Another issue is that you if i want this on the categories, disscussions, and on the discussion proper i have to expose the 3 different functions so i end up repeating myself. But that's alright i guess given the fine grained control.

    If you can help me with the above it's much appreciate, otherwise, thanks for the heads up!

    Regardless, later on I wanted to extend it in the dashboard, so there is a setting's portion where you can set the background-color of each tag, etc.

  • take a look at this for general placement.

    https://vanillaforums.org/addon/eventi-plugin

    easier to visualize. you can always use css to position as you are well aware

    Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    There is "DiscussionMeta" which will eventuallly serve that purpose.

    Look at this version:

        public function discussionsController_discussionMeta_handler($sender, $args) {
            if (!property_exists($args['Discussion'], 'Tags')) {
                // No tags, nothing to do.
                return;
            }
            echo '<span class="MItem Tags">';
            foreach ($args['Discussion']->Tags as $tag) {
                echo ' <span class="Count ',
                    'Tag-', Gdn_Format::text($tag['Name']),
                    '">',
                    Gdn_Format::text($tag['FullName']),
                    '</span>';
            }
            echo '</span>';
        }
    

    Besides of using another event, it is also changed a bit concerning the markup:
    There is a span that encapsulates all tags.
    Tags have the class "Count", which looks nicer than class "Tag" at this place.
    I've added the Tags name as a class name so that they can be styled individually.
    Tag Name and FullName are converted to plain text so that they couldn't be misused.


  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    If you like to enclose a css file create plugins/yourpluginsname/design/yourpluginsname.css

    And add this method to your plugin:

        public function discussionsController_render_before($sender) {
            $sender->addCssFile('yourpluginsname.css', 'plugins/yourpluginsname'));
            // The below lines show other ways to add your css file, but I would use the line above.
            // $sender->addCssFile($this->getResource('design/yourpluginsname.css', false, false));
            // $sender->addCssFile('plugins/yourpluginsname/design/yourpluginsname.css');
        }
    


  • KioriKiori New
    edited August 2016

    Thanks, that did it. But why "Gdn_Format::text"? Does this force upperCase or something?

    Also, i just realized it's not working on the "categories" page, i thought it was. What to do?.
    The CSS thing i had already got working, thanks!

    Also, about permissions, what permission do i have to set in roles so that a user's post needs to be approved before posting?

    Btw is there any guide, or real world explanation on permissions?

Sign In or Register to comment.