Skip to content

feat(entitlement): Introduce Feature and Privilege models #3873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 2, 2025

Conversation

julienbourdeau
Copy link
Contributor

@julienbourdeau julienbourdeau commented Jun 26, 2025

Introduce Feature and Privilege models, only the left part shown on this chart.

Note that everything (most things) are namespaced under Entitlement::.

drawSQL-image-export-2025-06-28 (2)

Also adds new endpoints to API to manage features.

                  Prefix Verb                      URI Pattern                                               Controller#Action
api_v1_feature_privilege DELETE                    /api/v1/features/:feature_code/privileges/:code(.:format) api/v1/features/privileges#destroy {code: /.*/, feature_code: /.*/}
         api_v1_features GET                       /api/v1/features(.:format)                                api/v1/features#index
                         POST                      /api/v1/features(.:format)                                api/v1/features#create
          api_v1_feature GET                       /api/v1/features/:code(.:format)                          api/v1/features#show {code: /.*/}
                         PATCH                     /api/v1/features/:code(.:format)                          api/v1/features#update {code: /.*/}
                         PUT                       /api/v1/features/:code(.:format)                          api/v1/features#update {code: /.*/}
                         DELETE                    /api/v1/features/:code(.:format)                          api/v1/features#destroy {code: /.*/}

Next PRs

  1. Add Feature to plan (entitlements)
  2. Add webhooks feature.*
  3. Add AuditLogs

@julienbourdeau julienbourdeau self-assigned this Jun 26, 2025
@julienbourdeau julienbourdeau force-pushed the ent/feature-base-models branch 3 times, most recently from 35c71d0 to 93458ab Compare June 27, 2025 09:02
@julienbourdeau julienbourdeau changed the base branch from main to cursor/new-rules-and-matcher June 27, 2025 09:03
@julienbourdeau julienbourdeau force-pushed the cursor/new-rules-and-matcher branch from 7b14c7c to 77ca90c Compare June 27, 2025 12:36
@julienbourdeau julienbourdeau force-pushed the ent/feature-base-models branch 2 times, most recently from 0816050 to c5147e6 Compare June 27, 2025 12:57
Base automatically changed from cursor/new-rules-and-matcher to main June 30, 2025 07:24
@julienbourdeau julienbourdeau force-pushed the ent/feature-base-models branch from c5147e6 to 7889631 Compare June 30, 2025 09:15
@julienbourdeau julienbourdeau force-pushed the ent/feature-base-models branch from 7889631 to c0de389 Compare June 30, 2025 09:43
@julienbourdeau julienbourdeau marked this pull request as ready for review June 30, 2025 11:20
@julienbourdeau julienbourdeau force-pushed the ent/feature-base-models branch from c0de389 to f90da85 Compare June 30, 2025 12:27
Copy link
Contributor

@groyoh groyoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I left quite a few comments but it's nothing major.

julienbourdeau and others added 2 commits July 1, 2025 17:09
Co-authored-by: Yohan Robert <7434196+groyoh@users.noreply.github.com>
@julienbourdeau julienbourdeau force-pushed the ent/feature-base-models branch from a6cf265 to ff928c6 Compare July 1, 2025 15:10
@julienbourdeau julienbourdeau force-pushed the ent/feature-base-models branch from ff928c6 to deee340 Compare July 1, 2025 16:04
@julienbourdeau julienbourdeau force-pushed the ent/feature-base-models branch from a7553fe to 1cf4245 Compare July 2, 2025 06:50
@julienbourdeau julienbourdeau merged commit d6cc2c8 into main Jul 2, 2025
14 checks passed
@julienbourdeau julienbourdeau deleted the ent/feature-base-models branch July 2, 2025 07:10
julienbourdeau added a commit that referenced this pull request Jul 4, 2025
This PR follows #3873

It adds a way to attach features and privilges to a plan.

In serialized plans, you get

```rb
"entitlements" => [
  {
    "code"        => "seats",
    "name"        => "Seats",
    "description" => "Nb users",
    "privileges"  => {
      "max" => {
        "code"       => "max",
        "name"       => nil,
        "value_type" => "integer",
        "value"      => 100,     # <<-------
        "config"     => {}
      }
    }
  }
]
```

**Now, the core is only missing the subscription override.**

![drawSQL-image-export-2025-06-28
(2)](https://github.com/user-attachments/assets/4d728a7d-cb1e-43bc-ac44-486f0e681f73)

```
                           Prefix Verb                      URI Pattern                                                                        Controller#Action
api_v1_plan_entitlement_privilege DELETE                    /api/v1/plans/:plan_code/entitlements/:entitlement_code/privileges/:code(.:format) api/v1/plans/entitlements/privileges#destroy {code: /.*/, plan_code: /.*/, entitlement_code: /.*/}
         api_v1_plan_entitlements GET                       /api/v1/plans/:plan_code/entitlements(.:format)                                    api/v1/plans/entitlements#index {plan_code: /.*/}
                                  POST                      /api/v1/plans/:plan_code/entitlements(.:format)                                    api/v1/plans/entitlements#create {plan_code: /.*/}
          api_v1_plan_entitlement GET                       /api/v1/plans/:plan_code/entitlements/:code(.:format)                              api/v1/plans/entitlements#show {code: /.*/, plan_code: /.*/}
                                  PATCH                     /api/v1/plans/:plan_code/entitlements/:code(.:format)                              api/v1/plans/entitlements#update {code: /.*/, plan_code: /.*/}
                                  PUT                       /api/v1/plans/:plan_code/entitlements/:code(.:format)                              api/v1/plans/entitlements#update {code: /.*/, plan_code: /.*/}
                                  DELETE                    /api/v1/plans/:plan_code/entitlements/:code(.:format)                              api/v1/plans/entitlements#destroy {code: /.*/, plan_code: /.*/}
```


### Next PR

* Dispatch `plan.updated` webhooks
* Create and dispatch `feature.*` webhooks
diegocharles pushed a commit that referenced this pull request Jul 11, 2025
Introduce `Feature` and `Privilege` models, only the left part shown on
this chart.

Note that everything (most things) are namespaced under `Entitlement::`.

![drawSQL-image-export-2025-06-28
(2)](https://github.com/user-attachments/assets/4d728a7d-cb1e-43bc-ac44-486f0e681f73)


Also adds new endpoints to API to manage features.

```
                  Prefix Verb                      URI Pattern                                               Controller#Action
api_v1_feature_privilege DELETE                    /api/v1/features/:feature_code/privileges/:code(.:format) api/v1/features/privileges#destroy {code: /.*/, feature_code: /.*/}
         api_v1_features GET                       /api/v1/features(.:format)                                api/v1/features#index
                         POST                      /api/v1/features(.:format)                                api/v1/features#create
          api_v1_feature GET                       /api/v1/features/:code(.:format)                          api/v1/features#show {code: /.*/}
                         PATCH                     /api/v1/features/:code(.:format)                          api/v1/features#update {code: /.*/}
                         PUT                       /api/v1/features/:code(.:format)                          api/v1/features#update {code: /.*/}
                         DELETE                    /api/v1/features/:code(.:format)                          api/v1/features#destroy {code: /.*/}
```

### Next PR

- Add Feature to plan (entitlements)
- Add webhooks `feature.*`
- Add AuditLogs

---------

Co-authored-by: Yohan Robert <7434196+groyoh@users.noreply.github.com>
diegocharles pushed a commit that referenced this pull request Jul 11, 2025
This PR follows #3873

It adds a way to attach features and privilges to a plan.

In serialized plans, you get

```rb
"entitlements" => [
  {
    "code"        => "seats",
    "name"        => "Seats",
    "description" => "Nb users",
    "privileges"  => {
      "max" => {
        "code"       => "max",
        "name"       => nil,
        "value_type" => "integer",
        "value"      => 100,     # <<-------
        "config"     => {}
      }
    }
  }
]
```

**Now, the core is only missing the subscription override.**

![drawSQL-image-export-2025-06-28
(2)](https://github.com/user-attachments/assets/4d728a7d-cb1e-43bc-ac44-486f0e681f73)

```
                           Prefix Verb                      URI Pattern                                                                        Controller#Action
api_v1_plan_entitlement_privilege DELETE                    /api/v1/plans/:plan_code/entitlements/:entitlement_code/privileges/:code(.:format) api/v1/plans/entitlements/privileges#destroy {code: /.*/, plan_code: /.*/, entitlement_code: /.*/}
         api_v1_plan_entitlements GET                       /api/v1/plans/:plan_code/entitlements(.:format)                                    api/v1/plans/entitlements#index {plan_code: /.*/}
                                  POST                      /api/v1/plans/:plan_code/entitlements(.:format)                                    api/v1/plans/entitlements#create {plan_code: /.*/}
          api_v1_plan_entitlement GET                       /api/v1/plans/:plan_code/entitlements/:code(.:format)                              api/v1/plans/entitlements#show {code: /.*/, plan_code: /.*/}
                                  PATCH                     /api/v1/plans/:plan_code/entitlements/:code(.:format)                              api/v1/plans/entitlements#update {code: /.*/, plan_code: /.*/}
                                  PUT                       /api/v1/plans/:plan_code/entitlements/:code(.:format)                              api/v1/plans/entitlements#update {code: /.*/, plan_code: /.*/}
                                  DELETE                    /api/v1/plans/:plan_code/entitlements/:code(.:format)                              api/v1/plans/entitlements#destroy {code: /.*/, plan_code: /.*/}
```


### Next PR

* Dispatch `plan.updated` webhooks
* Create and dispatch `feature.*` webhooks
julienbourdeau added a commit that referenced this pull request Jul 22, 2025
)

Allow `config.select_options` to be updated for `select` privilege.

I don't know why the config column is nullable in the DB, this is a
mistake.
Notice that I can simply change the column with "safety_assured" because
**the feature is not released and there was no tagged version [since I
added this model](#3873
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants