Skip to content

Commit

Permalink
Merge branch 'develop' into fe-session-modal-visual-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Santisantt01 committed Nov 6, 2023
2 parents 48dfe51 + e050ae2 commit ada215d
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 55 deletions.
41 changes: 11 additions & 30 deletions api/app/controllers/users/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,19 @@ class PasswordsController < Devise::PasswordsController
def create
user = User.find_by(email: resource_params[:email])

if user
# rate limit
if cooldown_passed?(user.reset_password_sent_at)
self.resource = resource_class.send_reset_password_instructions(resource_params)
# Only attempt to send instructions if the user exists.
if user && cooldown_passed?(user.reset_password_sent_at)
self.resource = resource_class.send_reset_password_instructions(resource_params)
user.update(reset_password_sent_at: Time.current) if successfully_sent?(resource)
end

if successfully_sent?(resource)
user.update(reset_password_sent_at: Time.current)
# Log an attempt to request password reset instructions.
Rails.logger.info "Attempted to send reset password instructions to '#{resource_params[:email]}'."

Rails.logger.info "Reset password instructions sent to '#{resource.email}' successfully."
render json: { message: "Instrucciones enviadas correctamente a #{resource.email}." },
status: :ok
else
Rails.logger.info 'Failed to send instructions to ' \
"'#{resource.email}' due to: #{resource.errors.full_messages}"
render json: {
message: 'No se pudieron enviar las instrucciones para reestablecer la contraseña.',
errors: resource.errors.messages
}, status: :unprocessable_entity
end
else
# si hay una solicitud que achique
render json: {
message: 'La solicitud de reestablecimiento de contraseña ha sido enviada recientemente. ' \
'Por favor, espera un poco antes de intentar de nuevo.'
}, status: :too_many_requests
end
else
render json: {
message: 'No se encontró un usuario con ese correo electrónico.',
errors: { email: ['El correo electrónico no es válido o no existe.'] }
}, status: :unprocessable_entity
end
# Always return a success message.
render json: { message: 'Si tu correo electrónico existe en nuestra base de datos, ' \
'recibirás un correo con instrucciones para reestablecer tu contraseña.' },
status: :ok
end

def update
Expand Down
26 changes: 15 additions & 11 deletions api/spec/requests/users/passwords_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
post user_password_path, params: { user: { email: '[email protected]' } }
end

it 'returns http unprocessable_entity' do
expect(response).to have_http_status(:unprocessable_entity)
it 'returns http success' do
expect(response).to have_http_status(:ok)
end

it 'does not send reset password instructions' do
Expand Down Expand Up @@ -95,8 +95,8 @@
post user_password_path, params: { user: { email: user.email } }
end

it 'returns http too_many_requests' do
expect(response).to have_http_status(:too_many_requests)
it 'returns http success' do
expect(response).to have_http_status(:ok)
end

it 'does not send another reset password instructions' do
Expand Down Expand Up @@ -151,19 +151,23 @@
post user_password_path, params: { user: { email: user.email } }
end

it 'returns http unprocessable_entity' do
expect(response).to have_http_status(:unprocessable_entity)
it 'returns http success' do
expect(response).to have_http_status(:ok)
end

it 'logs the failure' do
expect(Rails.logger).to have_received(:info).with(/Failed to send instructions/)
# Update this test to reflect the new logging behavior
it 'logs the attempt' do
expect(Rails.logger).to have_received(:info).with(/Attempted to send reset password instructions to/)
end

it 'renders the error message in the response' do
# Update this test to expect the new success message
it 'renders a generic success message in the response' do
expect(response.parsed_body['message']).to eq(
'No se pudieron enviar las instrucciones para reestablecer la contraseña.'
'Si tu correo electrónico existe en nuestra base de datos, ' \
'recibirás un correo con instrucciones para reestablecer tu contraseña.'
)
expect(response.parsed_body['errors']).to include('base' => ['Error message'])
# Since you're always returning a success, you should not include errors in the response
expect(response.parsed_body).not_to have_key('errors')
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Session } from '@/types/Session';
import CardSession from './CardSession';
import EmptyInboxImage from '@/assets/images/empty_inbox.png';
import Image from 'next/image';

type HistoryProps = {
sessions: Session[];
Expand All @@ -16,6 +18,17 @@ type HistoryProps = {
export default function History({ sessions, viewSession }: HistoryProps) {
return (
<div data-testid='session-history'>
{sessions.length === 0 && (
<div className='flex flex-col items-center justify-center text-gray-500'>
<Image
src={EmptyInboxImage}
alt='empty-session'
width={50}
height={50}
/>
<p>Aún no ocurrieron sesiones.</p>
</div>
)}
{sessions.map((session, index) => {
return (
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Session } from '@/types/Session';
import CardSession from './CardSession';
import EmptyInboxImage from '@/assets/images/empty_inbox.png';
import Image from 'next/image';

type NextSessionsProps = {
sessions: Session[];
Expand All @@ -13,6 +15,18 @@ export default function NextSessions({
}: NextSessionsProps) {
return (
<div data-testid='next-session'>
{sessions.length === 0 && (
<div className='flex flex-col items-center justify-center text-gray-500'>
<Image
src={EmptyInboxImage}
alt='empty-session'
width={50}
height={50}
/>
<p>Aún no hay sesiones programadas.</p>
<p>!Organiza una!</p>
</div>
)}
{sessions.map((session, index) => {
return (
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type ViewSessionProps = {
};

function validateUrl(url: string) {
if (url.startsWith('https://')) return url;
if (url.startsWith('https://') || url.startsWith('http://')) return url;
else return `https://${url}`;
}

Expand Down Expand Up @@ -469,7 +469,8 @@ export default function ViewSession({
value={editData.description ?? ''}
classNameInput='peer h-fit w-[90%] border-b border-gray-300 text-xl focus:border-gray-600 focus:outline-none'
/>,
<p className='font-poppins text-grayText'>

<p className='overflow-auto break-words font-poppins text-grayText'>
{!sessionGroup.description
? strings.viewSession.noDescription
: sessionGroup.description}
Expand Down
4 changes: 3 additions & 1 deletion client/src/app/(protected)/groups/[id]/GroupInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ export default function GroupInfo({ group, subject, user }: GroupInfoProps) {
<p className='mb-3 font-poppins text-xl font-semibold'>
{subject.name}
</p>
<p className='font-regular mb-3'>{description}</p>
<p className='font-regular mb-3 overflow-auto break-words'>
{description}
</p>
<div className='mb-3 flex flex-col items-center justify-center sm:flex-row sm:justify-start'>
<div className='mr-2 flex items-center sm:mb-0'>
<GroupSizeIconSolid className='mr-2 h-5 w-5' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,13 @@ export default function EditGroupPropsSection({

function handleTimePreferencesChange(day: string, value: string) {
const newTimePreferences = { ...groupData.time_preferences };
// @ts-ignore
newTimePreferences[translateSpanishDays[day]] = value;
if (value === '') {
// @ts-ignore
delete newTimePreferences[translateSpanishDays[day]];
} else {
// @ts-ignore
newTimePreferences[translateSpanishDays[day]] = value;
}
setGroupData({ ...groupData, time_preferences: newTimePreferences });
setTouched({ ...touched, time_preferences: true });
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/(protected)/users/[id]/UserBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function UserBio(props: { bio: string }) {
return (
<h1
data-testid={'BioField'}
className='text-center text-xl text-gray-600 lg:mt-2 lg:text-left'
className='overflow-auto break-words text-center text-xl text-gray-600 lg:mt-2 lg:text-left'
>
{props.bio}
</h1>
Expand Down
Binary file added client/src/assets/images/empty_inbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 23 additions & 7 deletions client/src/components/common/EditableTimePreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,30 @@ const preferences: Option[] = [
];

function buildInitialValues(timePreferences?: TimePreference) {
const initalValues = {
Lunes: TimeOfDay.NoPreferences,
Martes: TimeOfDay.NoPreferences,
Miércoles: TimeOfDay.NoPreferences,
Jueves: TimeOfDay.NoPreferences,
Viernes: TimeOfDay.NoPreferences,
Sábado: TimeOfDay.NoPreferences,
Domingo: TimeOfDay.NoPreferences,
};

if (!timePreferences) return initalValues;

function getTimeVal(time: TimeOfDay | undefined) {
return time || TimeOfDay.No;
}

return {
Lunes: timePreferences?.Monday ?? TimeOfDay.NoPreferences,
Martes: timePreferences?.Tuesday ?? TimeOfDay.NoPreferences,
Miércoles: timePreferences?.Wednesday ?? TimeOfDay.NoPreferences,
Jueves: timePreferences?.Thursday ?? TimeOfDay.NoPreferences,
Viernes: timePreferences?.Friday ?? TimeOfDay.NoPreferences,
Sábado: timePreferences?.Saturday ?? TimeOfDay.NoPreferences,
Domingo: timePreferences?.Sunday ?? TimeOfDay.NoPreferences,
Lunes: getTimeVal(timePreferences.Monday),
Martes: getTimeVal(timePreferences.Tuesday),
Miércoles: getTimeVal(timePreferences.Wednesday),
Jueves: getTimeVal(timePreferences.Thursday),
Viernes: getTimeVal(timePreferences.Friday),
Sábado: getTimeVal(timePreferences.Saturday),
Domingo: getTimeVal(timePreferences.Sunday),
};
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/common/GroupCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function GroupCard({ group, className = '' }: GroupCardProps) {
</h1>
<p
data-testid={`groupDescription-${group.description}`}
className='line-clamp-2 text-base font-light text-[#A0A0A0]'
className='line-clamp-2 hyphens-auto break-all text-base font-light text-[#A0A0A0]'
>
{group.description}
</p>
Expand Down

0 comments on commit ada215d

Please sign in to comment.