-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Add consumable invites #5814
Add consumable invites #5814
Conversation
Related to #977? |
72d0a35
to
bb8518e
Compare
app/models/user.rb
Outdated
accepts_nested_attributes_for :account | ||
|
||
has_many :applications, class_name: 'Doorkeeper::Application', as: :owner | ||
|
||
validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale? | ||
validates_with BlacklistedEmailValidator, if: :email_changed? | ||
validates_with InviteCodeValidator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only validate when the record is being created, so records don't start erroring once the invite expires
app/models/invite.rb
Outdated
# expires_at :datetime | ||
# max_uses :integer | ||
# uses :integer default(0), not null | ||
# default_follow_account_ids :integer is an Array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused?
- Default follows not used, probably bad idea - InviteCodeValidator is redundant because RegistrationsController checks invite code validity
3b65663
to
aa62afe
Compare
- Admin UI that lists everyone's invites, always available - Admin setting min_invite_role to control who can invite people - Non-admin invite UI only visible if users are allowed to
4c1f42f
to
f0726b7
Compare
def destroy | ||
@invite = Invite.where(user: current_user).find(params[:id]) | ||
authorize @invite, :destroy? | ||
@invite.destroy! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of destroying the record, this should probably just set expires_at = Time.now or something so that it's still auditable.
otherwise we have the situation where someone makes 100 accounts and deletes the invites so they can't be traced back to them.
'21600': 6 hours | ||
'3600': 1 hour | ||
'43200': 12 hours | ||
'86400': 1 day |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this just be done with some sort of interval helper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we overwrote the rails strings to be super short for relative time. Unless you know a better way
|
||
.fields-group | ||
= f.input :max_uses, wrapper: :with_label, collection: [1, 5, 10, 25, 50, 100], label_method: lambda { |num| I18n.t('invites.max_uses', count: num) }, prompt: I18n.t('invites.max_uses_prompt') | ||
= f.input :expires_in, wrapper: :with_label, collection: [30.minutes, 1.hour, 6.hours, 12.hours, 1.day].map(&:to_i), label_method: lambda { |i| I18n.t("invites.expires_in.#{i}") }, prompt: I18n.t('invites.expires_in_prompt') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7 days is probably useful here. 6 hours is probably not super useful? Or keep 6 hours, but get rid of 1 hour because we already have 30 minutes.
* i18n: (zh-CN) Add missing translations for multiple PRs. Related PRs: #5838 #5762 #5835 #5837 #5832 #5823 #5814 #5757 * i18n: (zh-CN) Fix translation for #5823 / #5835 * i18n: (zh-CN) Improve translations * i18n: (zh-CN) Improve translations * i18n: (zh-CN) Change `发送者` to `作者` * i18n: (zh-CN) Add missing translations for #5862 * i18n: (zh-CN) Add missing translation for #5874 * i18n: (zh-CN) Improve translations for keyboard shortcuts
* Add consumable invites * Add UI for generating invite codes * Add tests * Display max uses and expiration in invites table, delete invite * Remove unused column and redundant validator - Default follows not used, probably bad idea - InviteCodeValidator is redundant because RegistrationsController checks invite code validity * Add admin setting to disable invites * Add admin UI for invites, configurable role for invite creation - Admin UI that lists everyone's invites, always available - Admin setting min_invite_role to control who can invite people - Non-admin invite UI only visible if users are allowed to * Do not remove invites from database, expire them instantly
…on#5849) * i18n: (zh-CN) Add missing translations for multiple PRs. Related PRs: mastodon#5838 mastodon#5762 mastodon#5835 mastodon#5837 mastodon#5832 mastodon#5823 mastodon#5814 mastodon#5757 * i18n: (zh-CN) Fix translation for mastodon#5823 / mastodon#5835 * i18n: (zh-CN) Improve translations * i18n: (zh-CN) Improve translations * i18n: (zh-CN) Change `发送者` to `作者` * i18n: (zh-CN) Add missing translations for mastodon#5862 * i18n: (zh-CN) Add missing translation for mastodon#5874 * i18n: (zh-CN) Improve translations for keyboard shortcuts
Normal user UI:
Admin UI:
Admin settings UI: