Skip to content
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

Limit retention period #2618

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Limit retention period #2618

wants to merge 6 commits into from

Conversation

midigofrank
Copy link
Collaborator

@midigofrank midigofrank commented Oct 30, 2024

Description

This PR adds an extension that allows for limiting retention period.

The extension allows for 3 things:

  1. Only show desired retention periods in the project settings page
  2. Show a message next to the select input if provided
  3. Add custom validation to the project changeset when calling Projects.update_project/2

I also found a refactoring opportunity. I combined ProjectAlertsLimiter and ProjectUsersLimiter into ProjectLimiter to avoid adding extra modules.

Validation steps

This can be validated in the billing app. There are also tests that validate the functionality

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to know!):

  • Code generation (copilot but not intellisense)
  • Learning or fact checking
  • Strategy / design
  • Optimisation / refactoring
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

You can read more details in our Responsible AI Policy

Pre-submission checklist

  • I have performed a self-review of my code.
  • I have implemented and tested all related authorization policies. (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

@midigofrank midigofrank self-assigned this Oct 30, 2024
@midigofrank midigofrank marked this pull request as ready for review October 30, 2024 08:26
Copy link
Member

@stuartc stuartc left a comment

Choose a reason for hiding this comment

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

Very nice, good work! Just one thing about the moving of the validations on the retention periods, could you take a look at my comment?

Comment on lines -70 to -71
|> validate_inclusion(:history_retention_period, @retention_periods)
|> validate_inclusion(:dataclip_retention_period, @retention_periods)
Copy link
Member

Choose a reason for hiding this comment

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

I feel this should still be validated no? We're extending the validation via a hook, but these constraints are still valid here right?

@@ -91,7 +91,7 @@ defmodule LightningWeb.ProjectLive.InviteCollaboratorComponent do

project_users = Ecto.Changeset.get_embed(changeset, :invited_collaborators)

case ProjectUsersLimiter.request_new(
case ProjectLimiter.request_new_user(
Copy link
Member

Choose a reason for hiding this comment

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

👌 nice, I'm liking the renaming and conforming of the ProjectLimiter changes.

Comment on lines 27 to +30
on_mount {LightningWeb.Hooks, :project_scope}
on_mount {LightningWeb.Hooks, :limit_github_sync}
on_mount {LightningWeb.Hooks, :limit_mfa}
on_mount {LightningWeb.Hooks, :limit_retention_periods}
Copy link
Member

Choose a reason for hiding this comment

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

Thinking out loud here, I think these hooks are needing a rename, afaik all the hooks in the file are related to projects.

Also, at least 2/3 of these are only used in this live view, so we might be extending an 'implicit contract' - where this one live view expects a bunch of assigns that are added by another module.

I don't necessarily thing we need to change this now - but the settings module (when using hooks) feels a bit 'stringy' where we quietly plug in a bunch of assigns that are all very specific.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, good point. Feels like we need a central place to extend the settings live view with limiters and extensions

<.input
type="select"
prompt="Select Period"
options={
Enum.map([7, 14, 30, 90, 180, 365], fn days ->
Enum.map(@data_retention_periods, fn days ->
Copy link
Member

Choose a reason for hiding this comment

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

Oh thank goodness 😅

Copy link

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.82%. Comparing base (383c692) to head (3cc66b4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2618      +/-   ##
==========================================
- Coverage   90.84%   90.82%   -0.03%     
==========================================
  Files         320      319       -1     
  Lines       11221    11233      +12     
==========================================
+ Hits        10194    10202       +8     
- Misses       1027     1031       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New Issues
Development

Successfully merging this pull request may close these issues.

2 participants