From 80d0e1c871f8f65a6f0d3f8afbdcb01b524a5b3c Mon Sep 17 00:00:00 2001 From: Anusha Ranganathan Date: Wed, 15 Jun 2022 00:40:31 +0100 Subject: [PATCH] fix for issue #2 manage users error --- spotlight/app/models/user.rb | 2 +- spotlight/config/initializers/devise.rb | 49 +++++++++++++++++++ .../config/locales/devise_invitable.en.yml | 31 ++++++++++++ ...614231033_devise_invitable_add_to_users.rb | 22 +++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 spotlight/config/locales/devise_invitable.en.yml create mode 100644 spotlight/db/migrate/20220614231033_devise_invitable_add_to_users.rb diff --git a/spotlight/app/models/user.rb b/spotlight/app/models/user.rb index 6e8d560..b915044 100644 --- a/spotlight/app/models/user.rb +++ b/spotlight/app/models/user.rb @@ -6,7 +6,7 @@ class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable - devise :database_authenticatable, :registerable, + devise :database_authenticatable, :registerable, :invitable, :recoverable, :rememberable, :validatable # Method added by Blacklight; Blacklight uses #to_s on your diff --git a/spotlight/config/initializers/devise.rb b/spotlight/config/initializers/devise.rb index 093d714..7b572d1 100644 --- a/spotlight/config/initializers/devise.rb +++ b/spotlight/config/initializers/devise.rb @@ -134,6 +134,55 @@ # Send a notification email when the user's password is changed. # config.send_password_change_notification = false + # ==> Configuration for :invitable + # The period the generated invitation token is valid. + # After this period, the invited resource won't be able to accept the invitation. + # When invite_for is 0 (the default), the invitation won't expire. + # config.invite_for = 2.weeks + + # Number of invitations users can send. + # - If invitation_limit is nil, there is no limit for invitations, users can + # send unlimited invitations, invitation_limit column is not used. + # - If invitation_limit is 0, users can't send invitations by default. + # - If invitation_limit n > 0, users can send n invitations. + # You can change invitation_limit column for some users so they can send more + # or less invitations, even with global invitation_limit = 0 + # Default: nil + # config.invitation_limit = 5 + + # The key to be used to check existing users when sending an invitation + # and the regexp used to test it when validate_on_invite is not set. + # config.invite_key = { email: /\A[^@]+@[^@]+\z/ } + # config.invite_key = { email: /\A[^@]+@[^@]+\z/, username: nil } + + # Ensure that invited record is valid. + # The invitation won't be sent if this check fails. + # Default: false + # config.validate_on_invite = true + + # Resend invitation if user with invited status is invited again + # Default: true + # config.resend_invitation = false + + # The class name of the inviting model. If this is nil, + # the #invited_by association is declared to be polymorphic. + # Default: nil + # config.invited_by_class_name = 'User' + + # The foreign key to the inviting model (if invited_by_class_name is set) + # Default: :invited_by_id + # config.invited_by_foreign_key = :invited_by_id + + # The column name used for counter_cache column. If this is nil, + # the #invited_by association is declared without counter_cache. + # Default: nil + # config.invited_by_counter_cache = :invitations_count + + # Auto-login after the user accepts the invite. If this is false, + # the user will need to manually log in after accepting the invite. + # Default: true + # config.allow_insecure_sign_in_after_accept = false + # ==> Configuration for :confirmable # A period that the user is allowed to access the website even without # confirming their account. For instance, if set to 2.days, the user will be diff --git a/spotlight/config/locales/devise_invitable.en.yml b/spotlight/config/locales/devise_invitable.en.yml new file mode 100644 index 0000000..f6bfee4 --- /dev/null +++ b/spotlight/config/locales/devise_invitable.en.yml @@ -0,0 +1,31 @@ +en: + devise: + failure: + invited: "You have a pending invitation, accept it to finish creating your account." + invitations: + send_instructions: "An invitation email has been sent to %{email}." + invitation_token_invalid: "The invitation token provided is not valid!" + updated: "Your password was set successfully. You are now signed in." + updated_not_active: "Your password was set successfully." + no_invitations_remaining: "No invitations remaining" + invitation_removed: "Your invitation was removed." + new: + header: "Send invitation" + submit_button: "Send an invitation" + edit: + header: "Set your password" + submit_button: "Set my password" + mailer: + invitation_instructions: + subject: "Invitation instructions" + hello: "Hello %{email}" + someone_invited_you: "Someone has invited you to %{url}, you can accept it through the link below." + accept: "Accept invitation" + accept_until: "This invitation will be due in %{due_date}." + ignore: "If you don't want to accept the invitation, please ignore this email. Your account won't be created until you access the link above and set your password." + time: + formats: + devise: + mailer: + invitation_instructions: + accept_until_format: "%B %d, %Y %I:%M %p" diff --git a/spotlight/db/migrate/20220614231033_devise_invitable_add_to_users.rb b/spotlight/db/migrate/20220614231033_devise_invitable_add_to_users.rb new file mode 100644 index 0000000..d1e4d74 --- /dev/null +++ b/spotlight/db/migrate/20220614231033_devise_invitable_add_to_users.rb @@ -0,0 +1,22 @@ +class DeviseInvitableAddToUsers < ActiveRecord::Migration[5.2] + def up + change_table :users do |t| + t.string :invitation_token + t.datetime :invitation_created_at + t.datetime :invitation_sent_at + t.datetime :invitation_accepted_at + t.integer :invitation_limit + t.references :invited_by, polymorphic: true + t.integer :invitations_count, default: 0 + t.index :invitation_token, unique: true # for invitable + t.index :invited_by_id + end + end + + def down + change_table :users do |t| + t.remove_references :invited_by, polymorphic: true + t.remove :invitations_count, :invitation_limit, :invitation_sent_at, :invitation_accepted_at, :invitation_token, :invitation_created_at + end + end +end