Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Is there a way to make a user account undeletable?

pcchenardpcchenard New
edited November 2014 in Vanilla 2.0 - 2.8

I want to give the moderators the ability to manage accounts. But I do not want them to be able to delete any user accounts and certainly not the main administrator account, whether on purpose or accidentally. I have given them ADD, APPROVE & EDIT permissions for "Users" in the Garden settings thinking that not giving them the DELETE permission would take care of it, but then they can't even see the user list. The only way they can see the user list is if they have been granted ALL permissions.

Is there at least some way to make my main admin user account undeletable?

Thanks.

Comments

  • Options
    peregrineperegrine MVP
    edited November 2014

    if for example you Don't want UserID 5 to be deleted.

    try this:

        public function UserController_BeforeUserDelete_Handler($Sender) {
          if($Sender->User->UserID == "5")
             trigger_error(ErrorMessage("You cannot delete the user:" . $Sender->User->UserID . " Permission Denied"), E_USER_ERROR);
    
        }
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    hgtonighthgtonight ∞ · New Moderator
    edited November 2014

    Make a plugin. Add a column to the user table called 'Indelible'. Tiny int 1 is fine. Default to 0. Check this on delete.

    public function UserController_BeforeUserDelete_Handler($Sender) {
      if($Sender->User->Indelible && !Gdn::Session()->User->Admin) {
        $Sender->EventArguments['CanDelete'] = FALSE;
      }
    }
    
    public function Structure() {
      Gdn::Structure()
        ->Table('Discussion')
        ->Column('Indelible', 'tinyiny(1)', '0')
        ->Set();
    }
    
    public function Setup() {
      $this->Structure();
    }
    

    You could extend this with a nice interface for setting the users to indelible, but I am a little lazy right now.

    EDIT - @peregrine beat me to it!

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    peregrineperegrine MVP
    edited November 2014

    aside from the options above. if they don't have delete option.

    they could still edit your role if you give them edit permissions.

    but you could probably trigger on a handler to take care of that as well

    add these to a plugin.

       public function UserController_BeforeUserEdit_Handler($Sender) {
          if($Sender->User->UserID == "6")
             trigger_error(ErrorMessage("You cannot Edit the user:" . $Sender->User->UserID . " Permission Denied"), E_USER_ERROR);
    
        }
    
    
        public function UserController_BeforeUserDelete_Handler($Sender) {
          if($Sender->User->UserID == "6")
             trigger_error(ErrorMessage("You cannot delete the user:" . $Sender->User->UserID . " Permission Denied"), E_USER_ERROR);
    
        }
    

    Best to stick with Moderators you can trust.

    By the way, they could see a user list with

    http://vanillaforums.org/addon/memberslistenh-plugin

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    businessdadbusinessdad Stealth contributor MVP
    edited November 2014

    @hgtonight said:

    public function Setup() {
      $this->Setup();
    }
    

    Aaaaaaand you will get a nice infinite recursion! :D

  • Options
    hgtonighthgtonight ∞ · New Moderator

    @businessdad said:
    Aaaaaaand you will get a nice infinite recursion! :D

    Oh dear!

    This is why you shouldn't type things from memory when you have a perfectly good source file to copy from.

    Nice catch!

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    @peregrine said:
    aside from the options above. if they don't have delete option.

    they could still edit your role if you give them edit permissions.

    but you could probably trigger on a handler to take care of that as well

    add these to a plugin.

       public function UserController_BeforeUserEdit_Handler($Sender) {
          if($Sender->User->UserID == "6")
             trigger_error(ErrorMessage("You cannot Edit the user:" . $Sender->User->UserID . " Permission Denied"), E_USER_ERROR);
    
        }
    
    
        public function UserController_BeforeUserDelete_Handler($Sender) {
          if($Sender->User->UserID == "6")
             trigger_error(ErrorMessage("You cannot delete the user:" . $Sender->User->UserID . " Permission Denied"), E_USER_ERROR);
    
        }
    

    Best to stick with Moderators you can trust.

    By the way, they could see a user list with

    http://vanillaforums.org/addon/memberslistenh-plugin

    Cool! Thanks. One question. How do you know what each users number is? It does not show that in the user properties box when you go to "edit" a user, nor does it show when you view a users profile.

  • Options
    peregrineperegrine MVP
    edited November 2014

    Cool! Thanks. One question. How do you know what each users number is?

    an easy way is to hover over the users name or click on the users profile.

    http://vanillaforums.org/profile/56931/pcchenard

    or right click on a users name - it will show a number in front of the users name in the url - that is the userid.

    you can also load the http://vanillaforums.org/addon/memberslistenh-plugin

    and it will show as well in the userid column.

    or use phpmyadmin and look at the user table.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    @peregrine said:

    I loaded the memberslistenh plugin and configured which rows I want see, but I don't see a link anywhere on the site or in the dashboard to actually pull up the list. Am I missing something?

  • Options
    peregrineperegrine MVP
    edited November 2014

    @pcchenard said:
    I loaded the memberslistenh plugin and configured which rows I want see, but I don't see a link anywhere on the site or in the dashboard to actually pull up the list. Am I missing something?

    An entirely different question from your Opening Title demands a new discussion.

    • this helps other people.
    • not trying to make it difficult for you.
    • Trying to make it easier for people who have the same question or issues later in the future.

    please read:

    some info on Asking Questions - that may prove useful. (to help us help you).

    http://vanillaforums.org/discussion/18015/how-to-ask-questions-on-the-internet
    
    http://vanillaforums.org/discussion/23130/forum-post-ettikett-etiquette
    
    http://vanillaforums.org/discussion/25115/how-to-how-can-a-new-user-better-help-the-community-
    
    http://vanillaforums.org/discussion/17954/food-for-thought-forum-etiquette
    
    http://vanillaforums.org/discussion/23483/advice-for-all-those-just-starting-out-with-vanilla
    

    http://vanillaforums.org/addon/memberslistenh-plugin

    go to the plugin you have a question about. choose ask question.

    although the question you have is probably already answered in the comments and the Tip

    Also, before using a plugin, I personally try to read all the other comments related to the plugin, it usually helps me, I recommend that to everyone.

    • Before Installing a plugin
    • read the description
    • read the readme
    • AND read the associated discussions listed in the add-ons section of the plugin

    these may help you.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    You brought up the use of the plugin in this discussion not me, so any discussion related to that plugin is entirely relevant to this discussion. But I understand what you are saying.

  • Options
    peregrineperegrine MVP
    edited November 2014

    @pcchenard said:
    You brought up the use of the plugin in this discussion not me, so any discussion related to that plugin is entirely relevant to this discussion. But I understand what you are saying.

    i'm glad we understand each other :smile:

    and you are welcome in advance if any information provided to you proved insightful.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.