mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 19:57:52 +01:00
Make invitations expire after 3 months (#426)
Co-authored-by: riggraz <riccardo.graziosi97@gmail.com>
This commit is contained in:
@@ -84,9 +84,13 @@
|
|||||||
div.invitationInfo {
|
div.invitationInfo {
|
||||||
@extend .d-flex;
|
@extend .d-flex;
|
||||||
|
|
||||||
span.invitationAcceptedAt, span.invitationSentAt {
|
span.invitationAcceptedAt, span.invitationSentAt, span.invitationExpired {
|
||||||
@extend .align-self-center, .mutedText;
|
@extend .align-self-center, .mutedText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span.invitationExpired {
|
||||||
|
@extend .text-danger;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ class InvitationsController < ApplicationController
|
|||||||
render json: {}, status: :ok
|
render json: {}, status: :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def invitation_params
|
def invitation_params
|
||||||
|
|||||||
@@ -14,12 +14,11 @@ class RegistrationsController < Devise::RegistrationsController
|
|||||||
|
|
||||||
# Handle invitations
|
# Handle invitations
|
||||||
is_invitation = sign_up_params[:invitation_token].present?
|
is_invitation = sign_up_params[:invitation_token].present?
|
||||||
is_invitation_valid = true
|
|
||||||
invitation = nil
|
invitation = nil
|
||||||
if is_invitation
|
if is_invitation
|
||||||
invitation = Invitation.find_by(email: email)
|
invitation = Invitation.find_by(email: email)
|
||||||
|
|
||||||
if invitation.nil? || invitation.token_digest != Digest::SHA256.hexdigest(sign_up_params[:invitation_token]) || invitation.accepted_at.present?
|
if invitation.nil? || invitation.expired? || invitation.token_digest != Digest::SHA256.hexdigest(sign_up_params[:invitation_token]) || invitation.accepted_at.present?
|
||||||
flash[:alert] = t('errors.unauthorized')
|
flash[:alert] = t('errors.unauthorized')
|
||||||
redirect_to new_user_registration_path and return
|
redirect_to new_user_registration_path and return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import buildRequestHeaders from '../../../helpers/buildRequestHeaders';
|
|||||||
import HttpStatus from '../../../constants/http_status';
|
import HttpStatus from '../../../constants/http_status';
|
||||||
import { isValidEmail } from '../../../helpers/regex';
|
import { isValidEmail } from '../../../helpers/regex';
|
||||||
import IInvitation from '../../../interfaces/IInvitation';
|
import IInvitation from '../../../interfaces/IInvitation';
|
||||||
import friendlyDate from '../../../helpers/datetime';
|
import friendlyDate, { fromRailsStringToJavascriptDate, nMonthsAgo } from '../../../helpers/datetime';
|
||||||
import ActionLink from '../../common/ActionLink';
|
import ActionLink from '../../common/ActionLink';
|
||||||
import { TestIcon } from '../../common/Icons';
|
import { TestIcon } from '../../common/Icons';
|
||||||
|
|
||||||
@@ -229,9 +229,14 @@ const Invitations = ({ siteName, invitations, currentUserEmail, authenticityToke
|
|||||||
{ I18n.t('site_settings.invitations.accepted_at', { when: friendlyDate(invitation.accepted_at) }) }
|
{ I18n.t('site_settings.invitations.accepted_at', { when: friendlyDate(invitation.accepted_at) }) }
|
||||||
</span>
|
</span>
|
||||||
:
|
:
|
||||||
|
fromRailsStringToJavascriptDate(invitation.updated_at) > nMonthsAgo(3) ?
|
||||||
<span className="invitationSentAt" title={invitation.updated_at}>
|
<span className="invitationSentAt" title={invitation.updated_at}>
|
||||||
{ I18n.t('site_settings.invitations.sent_at', { when: friendlyDate(invitation.updated_at) }) }
|
{ I18n.t('site_settings.invitations.sent_at', { when: friendlyDate(invitation.updated_at) }) }
|
||||||
</span>
|
</span>
|
||||||
|
:
|
||||||
|
<span className="invitationExpired">
|
||||||
|
{ I18n.t('site_settings.invitations.expired') }
|
||||||
|
</span>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -48,3 +48,18 @@ export const fromRailsStringToJavascriptDate = date => {
|
|||||||
export const fromJavascriptDateToRailsString = (date: Date) => {
|
export const fromJavascriptDateToRailsString = (date: Date) => {
|
||||||
return date.toJSON();
|
return date.toJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const nMonthsAgo = (n: number) => {
|
||||||
|
const currentDate = new Date();
|
||||||
|
|
||||||
|
return new Date(
|
||||||
|
Date.UTC(
|
||||||
|
currentDate.getFullYear(),
|
||||||
|
currentDate.getMonth() - n,
|
||||||
|
currentDate.getDate(),
|
||||||
|
currentDate.getHours(),
|
||||||
|
currentDate.getMinutes(),
|
||||||
|
currentDate.getSeconds()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
class Invitation < ApplicationRecord
|
class Invitation < ApplicationRecord
|
||||||
include TenantOwnable
|
include TenantOwnable
|
||||||
|
|
||||||
|
belongs_to :tenant
|
||||||
|
|
||||||
|
def expired?
|
||||||
|
updated_at <= 3.months.ago
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -272,6 +272,7 @@ en:
|
|||||||
accepted: 'Accepted'
|
accepted: 'Accepted'
|
||||||
sent_at: 'Sent %{when}'
|
sent_at: 'Sent %{when}'
|
||||||
accepted_at: 'Accepted %{when}'
|
accepted_at: 'Accepted %{when}'
|
||||||
|
expired: 'Expired'
|
||||||
appearance:
|
appearance:
|
||||||
title: 'Appearance'
|
title: 'Appearance'
|
||||||
learn_more: 'Learn how to customize appearance'
|
learn_more: 'Learn how to customize appearance'
|
||||||
|
|||||||
Reference in New Issue
Block a user