# Hack to enable invitations for Trust level 1 users

**URL:** https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103
**Category:** Support
**Created:** [May 12, 2016, 6:26am UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103 "2016-05-12T06:26:44Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![envieme](https://avatars.discourse-cdn.com/v4/letter/e/da6949/32.png) [@envieme](https://meta.discourse.org/u/envieme)
#### Post date: [May 12, 2016, 6:26am UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/1 "2016-05-12T06:26:44Z")

</div>

My community is based on invitations and I would really like to turn on the feature of inviting friends for my trust level 1 members. I have a lot of members in trust level 1 and its going to take some time before they can get to level 2 to be able to invite their friends. But since no new members are joining these days, less topics are being posted and there’s less engagement overall. So my trust level 1 members have also slowly stopping to visit. Am afraid the community will die like this unless I enable my trust level 1 members to invite their friends to their topics. And it a request that’s coming in from many users for them to have the ability to invite.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [May 12, 2016, 6:33am UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/2 "2016-05-12T06:33:17Z")

</div>

So promote them to trust level 2? Then they will have invites.

---

<div class="post-metadata">

### Author: ![envieme](https://avatars.discourse-cdn.com/v4/letter/e/da6949/32.png) [@envieme](https://meta.discourse.org/u/envieme)
#### Post date: [May 12, 2016, 7:10am UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/3 "2016-05-12T07:10:44Z")

</div>

Yes, that’s the only way I have but I do not want to do that unnecessarily and also give them extra privileges that they haven’t earned. It would be nice to have a setting to set the trust level for the invite feature. For now is there any other hack I can use on or within the app to get this done?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [May 12, 2016, 7:13am UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/4 "2016-05-12T07:13:05Z")

</div>

Well, if you trust them enough to send out invites, and ultimately achieve trust level 2 organically on their own to do so … why wouldn’t you trust them enough to grant them TL2 now? I’m not following this train of logic. 🚆

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [May 12, 2016, 7:37am UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/5 "2016-05-12T07:37:51Z")

</div>

If the goal is to increase the member base quickly, it might be better to lower the TL2 requirements than to simply grant TL2 to everyone

> tl2 requires topics entered - 20  
> How many topics a user must enter before promotion to trust level 2.  
> tl2 requires read posts - 100  
> How many posts a user must read before promotion to trust level 2.  
> tl2 requires time spent mins - 60  
> How many minutes a user must read posts before promotion to trust level 2.  
> tl2 requires days visited - 15  
> How many days a user must visit the site before promotion to trust level 2.  
> tl2 requires likes received - 1  
> How many likes a user must receive before promotion to trust level 2.  
> tl2 requires likes given - 1  
> How many likes a user must cast before promotion to trust level 2.  
> tl2 requires topic reply count - 3  
> How many topics user must reply to before promotion to trust level 2.

TBH I don’t see where any of those are that out of reach or unreasonably high

---

<div class="post-metadata">

### Author: ![envieme](https://avatars.discourse-cdn.com/v4/letter/e/da6949/32.png) [@envieme](https://meta.discourse.org/u/envieme)
#### Post date: [May 14, 2016, 6:19pm UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/6 "2016-05-14T18:19:05Z")

</div>

I want the process of gaining trust level 2 to happen naturally with users participating and gaining the level. My only requirement is they be able to invite others to their current topics and the forum in general without the need to wait until they finish reading 100 posts or all that listed above. I understand it is not unreasonably high but in my case, I also feel the time this would require is going to cost me user interest as well as new members. I am guesstimating out of 100 users at trust level 1, only 10 or so are going to stick around long enough to gain trust level 2. The others are going to just drop off. But before that, I would be interested if they can help invite a couple or so users themselves out of which a few may help build my community by participating well. And so on…

If there’s something I can do now to get my users at trust level 1 to use the invite feature without having to promote them to level 2 myself, let me know.

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [June 13, 2017, 6:25am UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/7 "2017-06-13T06:25:22Z")

</div>

> [@envieme](#):
>
> I want the process of gaining trust level 2 to happen naturally with users participating and gaining the level. My only requirement is they be able to invite others to their current topics and the forum in general

Same here! This would be a really great feature to have, given that new invites are what you need most of all on new forums…

---

<div class="post-metadata">

### Author: ![Rogue](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rogue/32/73696_2.png) [@Rogue](https://meta.discourse.org/u/Rogue)
#### Post date: [June 13, 2017, 9:10am UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/8 "2017-06-13T09:10:44Z")

</div>

Why was this not a feature?

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [June 13, 2017, 9:50am UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/9 "2017-06-13T09:50:09Z")

</div>

To enable Invites to TL1 users you can create a plugin. All you have to do is monkey patching the hard-coded TL value in below code

> <https://github.com/discourse/discourse/blob/908433a7a0d6e59c3867d3cc55592cb3c421bae0/lib/guardian.rb#L228>

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [June 13, 2017, 11:33am UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/10 "2017-06-13T11:33:03Z")

</div>

> [@vinothkannans](#):
>
> All you have to do is monkey patching the hard-coded TL value in below code

Could you give some more hints for the plugin noobs among us? I don’t expect a full tutorial (as that [already exists](https://meta.discourse.org/t/beginners-guide-to-creating-discourse-plugins-part-1/30515)), but perhaps some pointers as to where to start? (So far, the closest I have gotten to creating a plugin was to fork an existing one and change some of its settings…)

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [June 13, 2017, 11:47am UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/11 "2017-06-13T11:47:15Z")

</div>

```plaintext
after_initialize do
  Guardian.class_eval do
    def can_invite_to_forum?(groups=nil)
      authenticated? &&
      (SiteSetting.max_invites_per_day.to_i > 0 || is_staff?) &&
      !SiteSetting.enable_sso &&
      SiteSetting.enable_local_logins &&
      (
        (!SiteSetting.must_approve_users? && @user.has_trust_level?(TrustLevel[1])) ||
       is_staff?
      ) &&
      (groups.blank? || is_admin?)
    end
  end
end

```

I guess this is the code you need. Put it in `plugin.rb` file. Since I am not in PC I didn’t tested it.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [June 13, 2017, 12:29pm UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/12 "2017-06-13T12:29:18Z")

</div>

Is there a reason why we don’t move this into a site setting? Monkey patching isn’t a good way to go about doing this.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [June 13, 2017, 3:10pm UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/13 "2017-06-13T15:10:51Z")

</div>

Would it need a new setting or would testing for the existing bootstrap mode be good enough?

> <https://github.com/discourse/discourse/blob/main/config/site_settings.yml#L1275-L1283>

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [June 13, 2017, 7:24pm UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/14 "2017-06-13T19:24:11Z")

</div>

> [@Mittineague](#):
>
> Would it need a new setting or would testing for the existing bootstrap mode be good enough?

I think activating invites for TL1 users in bootstrap mode is an excellent idea but if there is no

> [@tgxworld](#):
>
> reason why we don’t move this into a site setting

I think that should also be done.

tl;dr Bootstrap mode: yes; site setting: yes

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [June 16, 2017, 7:13am UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/15 "2017-06-16T07:13:09Z")

</div>

Before I start messing up my instance: are there any plans for making this available as a site setting in the near future?

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [June 18, 2017, 11:00pm UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/16 "2017-06-18T23:00:37Z")

</div>

It’ll be @codinghorror’s call here.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [June 18, 2017, 11:35pm UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/17 "2017-06-18T23:35:11Z")

</div>

Not enough requests for it from paying customers at this time.

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [June 21, 2017, 10:00pm UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/18 "2017-06-21T22:00:13Z")

</div>

Thanks to @vinothkannans’s primer above, I managed to put together the [discourse-TL1-invites plugin](https://github.com/tophee/discourse-TL1-invites). 🎉 My first one, yeay! 🕶 And the best thing is: it works (from what I can tell so far).

The only thing I am a bit unsure about is that I am not 100% sure whether I am allowing TL1 users anything apart from forum invites and topic invites here:

> <https://github.com/papatistos/discourse-TL1-invites/blob/master/plugin.rb#L23-L38>

The only change I made is obviously the trustlevel in line 37, but I don’t quite grasp, what all the possible objects are that TL1 users can do invites for…

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [April 9, 2018, 8:20pm UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/19 "2018-04-09T20:20:17Z")

</div>

> [@tophee](#):
>
> return false unless SiteSetting.enable\_private\_messages?

Just a quick heads-up for anyone copying and pasting that code: unless I misunderstood something, that line should now read

```plaintext
return false unless SiteSetting.enable_personal_messages?

```

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [August 17, 2020, 10:30pm UTC](https://meta.discourse.org/t/hack-to-enable-invitations-for-trust-level-1-users/44103/20 "2020-08-17T22:30:34Z")

</div>


