# Can I create a plugin that checks users and grant access to group based on activity?

**URL:** https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875
**Category:** Development
**Created:** [August 27, 2017, 1:43pm UTC](https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875 "2017-08-27T13:43:38Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![xgdgsc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xgdgsc/32/120755_2.png) [@xgdgsc](https://meta.discourse.org/u/xgdgsc)
#### Post date: [August 27, 2017, 1:43pm UTC](https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875/1 "2017-08-27T13:43:38Z")

</div>

Sorry if I post in the wrong category. I’ m new to discourse plugin development. I looked through the api doc. I wonder is it possible to run a program periodically to count how many posts a user posted in a category (which is for new users to show their ability) and grant access to some private groups after this checking. I’ m wondering if there is some plugin similar. Thanks!

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 27, 2017, 2:38pm UTC](https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875/2 "2017-08-27T14:38:32Z")

</div>

You can do that with custom badges. The feature is now turned off by default, but if you’re self hosted you can turn it on.

---

<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: [August 27, 2017, 10:06pm UTC](https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875/3 "2017-08-27T22:06:51Z")

</div>

Are you certain? The last time I looked it was more like  
“meet criteria → Badge granted”  
“meet criteria → TL group joined → TL Badge granted”  
but not  
“meet criteria → Badge granted → custom group joined”

I’ve often thought a “group query” feature would be nice, but as troublesome as the badge query feature can be, perhaps it wouldn’t be the best idea.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 27, 2017, 11:08pm UTC](https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875/4 "2017-08-27T23:08:16Z")

</div>

> [@Mittineague](#):
>
> Are you certain? The last time I looked

Hmm. I guess I’m not.

---

<div class="post-metadata">

### Author: ![xgdgsc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xgdgsc/32/120755_2.png) [@xgdgsc](https://meta.discourse.org/u/xgdgsc)
#### Post date: [August 28, 2017, 2:45pm UTC](https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875/5 "2017-08-28T14:45:28Z")

</div>

So it is not possible for now?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 28, 2017, 3:42pm UTC](https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875/6 "2017-08-28T15:42:59Z")

</div>

It looks like @Mittineague was right and there is no mechanism for automatically adding badge-earners to a group. You will need a custom plugin or an external program to manage the groups via the API.

---

<div class="post-metadata">

### Author: ![xgdgsc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xgdgsc/32/120755_2.png) [@xgdgsc](https://meta.discourse.org/u/xgdgsc)
#### Post date: [August 29, 2017, 2:22am UTC](https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875/7 "2017-08-29T02:22:30Z")

</div>

What do you mean by group query? Isn’ t get [https://meta.discourse.org/groups/search.json](https://meta.discourse.org/groups/search.json) what you want?

---

<div class="post-metadata">

### Author: ![xgdgsc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xgdgsc/32/120755_2.png) [@xgdgsc](https://meta.discourse.org/u/xgdgsc)
#### Post date: [August 29, 2017, 2:23am UTC](https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875/8 "2017-08-29T02:23:08Z")

</div>

Writing a custom plugin is exactly what I want to do. I’ m wondering if there is some user activity statistics api?

---

<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: [August 29, 2017, 5:31am UTC](https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875/9 "2017-08-29T05:31:12Z")

</div>

> [@xgdgsc](#):
>
> What do you mean by group query?

For custom Badges, when the ability to do so is enabled, queries can be put together and they will be routinely run, automatically granting / revoking Badges. Because a poorly written query can cause much pain, the ability requires some dev know how. Although Badges are under Admin, not all Admins are devs.

A similar feature for Groups would be a convenient UI, but would also present the same risks the Badge query UI presents.

A plugin that did not have a UI would be hacky but easier to write. The plugin could have the query(s) hard-coded and then there would need to be a way to have it run on schedule.

---

<div class="post-metadata">

### Author: ![xgdgsc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xgdgsc/32/120755_2.png) [@xgdgsc](https://meta.discourse.org/u/xgdgsc)
#### Post date: [August 29, 2017, 9:24am UTC](https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875/10 "2017-08-29T09:24:07Z")

</div>

A plugin without a UI would be adequate for me. What do you use to run such thing on schedule?

---

<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: [August 29, 2017, 7:37pm UTC](https://meta.discourse.org/t/can-i-create-a-plugin-that-checks-users-and-grant-access-to-group-based-on-activity/68875/11 "2017-08-29T19:37:05Z")

</div>

> [@xgdgsc](#):
>
> What do you use to run such thing on schedule?

I’ve not tried it myself, but this plugin by @david ties in to the Jobs module

> <https://github.com/discourse/discourse-whos-online/blob/main/plugin.rb#L96-L100>
