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

Refactor/Ajuste na tela de configurações #180

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,7 @@ def show
@personal_info = personal_info
end

def work_unavailable
@profile = current_user.profile
@profile.unavailable!
redirect_to profile_path(@profile), notice: t('.success')
end

def open_to_work
@profile = current_user.profile
@profile.open_to_work!
redirect_to profile_path(@profile), notice: t('.success')
end

def change_privacy
@profile = current_user.profile
if @profile.public_profile?
@profile.private_profile!
else
@profile.public_profile!
end
redirect_to profile_path(@profile), notice: t('.success')
end
private

def private_profile?
return if @profile.user == current_user
Expand All @@ -59,8 +39,6 @@ def private_profile?
redirect_to root_path, alert: t('.private')
end

private

def profile_params
params.require(:profile).permit(:photo)
end
Expand Down
22 changes: 22 additions & 0 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ def delete_account
redirect_to root_path, notice: t('delete_account')
end

def change_privacy
@profile = current_user.profile
if @profile.public_profile?
@profile.private_profile!
else
@profile.public_profile!
end
redirect_to profile_settings_path(@profile), notice: t('.success')
end

def work_unavailable
@profile = current_user.profile
@profile.unavailable!
redirect_to profile_settings_path(@profile), notice: t('.success')
end

def open_to_work
@profile = current_user.profile
@profile.open_to_work!
redirect_to profile_settings_path(@profile), notice: t('.success')
end

private

def redirect_unauthorized_access
Expand Down
20 changes: 0 additions & 20 deletions app/views/profiles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<div class="ratio ratio-1x1 rounded-circle overflow-hidden w-50">
<%= render 'profile_photo' %>
</div>

<%= link_to 'Alterar foto', edit_profile_path(@profile), class: 'badge bg-secondary' if current_user == @profile.user %>
<h4><%= @user.full_name %></h4>
<div class="d-flex gap-4">
Expand All @@ -44,25 +43,6 @@
<% end %>
</div>
</div>
<div class="mt-2">
<% if @profile.open_to_work? %>
<h6 class="text-success"><%= t Profile.human_attribute_name("work_status.#{@profile.work_status}") %></h6>
<%= button_to 'alterar disponibilidade', work_unavailable_path, method: :patch, class: 'btn btn-outline-primary btn-sm' if current_user.profile == @profile %>
<% else %>
<h6 class="text-danger"><%= t Profile.human_attribute_name("work_status.#{@profile.work_status}") %></h6>
<%= button_to 'alterar disponibilidade', open_to_work_path, method: :patch, class: 'btn btn-outline-primary btn-sm' if current_user.profile == @profile %>
<% end %>
</div>
<div class="mt-3">
<% if current_user.profile == @profile %>
<% if @profile.public_profile? %>
<h6 class="text-success"><%= t Profile.human_attribute_name("privacy.#{@profile.privacy}") %></h6>
<% else %>
<h6 class="text-secondary"><%= t Profile.human_attribute_name("privacy.#{@profile.privacy}") %></h6>
<% end %>
<%= button_to 'alterar privacidade', change_privacy_path, method: :patch, class: 'btn btn-outline-primary btn-sm' %>
<% end %>
</div>
<br>
<div class="w-75">
<% if current_user.profile != @profile %>
Expand Down
62 changes: 43 additions & 19 deletions app/views/settings/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
<h2>Configurações</h2>
<div>
<%= form_with(url: deactivate_profile_path, method: :patch) do |form| %>
<p><strong class="text-danger">Atenção:</strong> Todos os dados relacionados ao seu perfil serão ARQUIVADOS. Você pode reativar sua conta fazendo log-in novamente.</p>
<%= form.submit 'Desativar Perfil',
class: "btn btn-danger",
data: { turbo_confirm: 'Seu perfil será DESATIVADO, deseja prosseguir?' }
%>
<% end %>
</div>
<h2 class="text-center">Configurações</h2>

<div>
<%= form_with(url: delete_account_path, method: :delete) do |form| %>
<p><strong class="text-danger">Atenção:</strong> Todos os dados relacionados a conta serão EXCLUÍDOS e não poderão ser recuperados.</p>
<%= form.submit 'Excluir Conta',
class: "btn btn-danger",
data: { turbo_confirm: 'Sua conta será EXCLUÍDA, deseja prosseguir?' }
%>
<% end %>
</div>
<section class="text-center mt-4">
<h3>Privacidade</h3>
<div class="mt-3">
<% if @profile.public_profile? %>
<p class="text-success fs-4"><%= t Profile.human_attribute_name("privacy.#{@profile.privacy}") %></p>
<% else %>
<p class="text-secondary fs-4"><%= t Profile.human_attribute_name("privacy.#{@profile.privacy}") %></p>
<% end %>
<%= button_to 'Alterar Privacidade', change_privacy_path, method: :patch, class: 'btn btn-outline-primary btn-sm' %>
</div>
<div class="mt-2">
<% if @profile.open_to_work? %>
<p class="text-success fs-4"><%= t Profile.human_attribute_name("work_status.#{@profile.work_status}") %></p>
<%= button_to 'Alterar Disponibilidade', work_unavailable_path, method: :patch, class: 'btn btn-outline-primary btn-sm' if current_user.profile == @profile %>
<% else %>
<p class="text-danger fs-4"><%= t Profile.human_attribute_name("work_status.#{@profile.work_status}") %></p>
<%= button_to 'Alterar Disponibilidade', open_to_work_path, method: :patch, class: 'btn btn-outline-primary btn-sm' if current_user.profile == @profile %>
<% end %>
</div>
</section>
<br>
<h3 class="text-center">Remoção de conta</h3>
<p class="text-center"><strong class="text-danger">Atenção:</strong> Ao desativar o perfil todos os dados relacionados serão <strong>ARQUIVADOS</strong>. Você pode reativar sua conta fazendo login novamente.</p>
<section class="text-center d-flex justify-content-around w-25 mx-auto">
<div>
<%= form_with(url: deactivate_profile_path, method: :patch) do |form| %>
<%= form.submit 'Desativar Perfil',
class: "btn btn-danger",
data: { turbo_confirm: 'Seu perfil será DESATIVADO, deseja prosseguir?' }
%>
<% end %>
</div>

<div>
<%= form_with(url: delete_account_path, method: :delete) do |form| %>
<%= form.submit 'Excluir Conta',
class: "btn btn-danger",
data: { turbo_confirm: 'Sua conta será EXCLUÍDA, deseja prosseguir?' }
%>
<% end %>
</div>
</section>
6 changes: 0 additions & 6 deletions config/locales/profile.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ pt-BR:
results:
one: 'resultado'
other: 'resultados'
work_unavailable:
success: Alteração salva com sucesso
open_to_work:
success: Alteração salva com sucesso
change_privacy:
success: Privacidade alterada com sucesso
show:
private: O perfil que você acessou é privado
profile:
Expand Down
9 changes: 8 additions & 1 deletion config/locales/settings.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
pt-BR:
deactivate_profile: Perfil desativado com sucesso
delete_account: Conta excluída com sucesso
delete_account: Conta excluída com sucesso
settings:
change_privacy:
success: Privacidade alterada com sucesso
work_unavailable:
success: Alteração salva com sucesso
open_to_work:
success: Alteração salva com sucesso
7 changes: 2 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
resources :users, only: [] do
resources :posts, shallow: true, only: %i[show edit update]
resources :profiles, shallow: true, only: %i[edit show update] do
resources 'settings', only: %i[index]
resources :settings, only: %i[index]
patch :remove_photo, on: :member
resources :connections, only: %i[create index] do
patch 'unfollow', 'follow_again'
Expand All @@ -34,10 +34,7 @@
end

delete 'delete_account', controller: :settings
patch 'deactivate_profile', controller: :settings
patch 'work_unavailable', controller: :profiles
patch 'open_to_work', controller: :profiles
patch 'change_privacy', controller: :profiles
patch 'deactivate_profile', 'work_unavailable', 'open_to_work', 'change_privacy', controller: :settings

resources :likes, only: %i[create destroy]
resources :job_categories, only: %i[index create]
Expand Down
55 changes: 0 additions & 55 deletions spec/system/profiles/user_changes_work_status_spec.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@
user = create(:user)

login_as user
visit profile_path(user.profile)
click_on 'alterar privacidade'
visit profile_settings_path(user.profile)
click_on 'Alterar Privacidade'

expect(page).to have_current_path profile_path(user.profile)
expect(page).to have_current_path profile_settings_path(user.profile)
expect(page).to have_content 'Privacidade alterada com sucesso'
expect(page).to have_content 'Perfil Privado'
end

it 'apenas do seu próprio perfil' do
user = create(:user)
another_user = create(:user)

login_as another_user
visit profile_path(user.profile)

expect(page).not_to have_button 'alterar privacidade'
end

it 'e não aparece nas buscas' do
job_category = create(:job_category, name: 'C++')
private_user = create(:user)
Expand Down Expand Up @@ -100,10 +90,10 @@
user.profile.private_profile!

login_as user
visit profile_path(user.profile)
click_on 'alterar privacidade'
visit profile_settings_path(user.profile)
click_on 'Alterar Privacidade'

expect(page).to have_current_path profile_path(user.profile)
expect(page).to have_current_path profile_settings_path(user.profile)
expect(page).to have_content 'Privacidade alterada com sucesso'
expect(page).to have_content 'Perfil Público'
end
Expand Down
32 changes: 32 additions & 0 deletions spec/system/settings/user_changes_work_status_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'rails_helper'

describe 'Usuário altera o status de disponibilidade de trabalho' do
context 'de disponível para indisponível' do
it 'com sucesso' do
user = create(:user)

login_as user
visit profile_settings_path(user.profile)
click_on 'Alterar Disponibilidade'

expect(page).to have_current_path profile_settings_path(user.profile)
expect(page).to have_content 'Alteração salva com sucesso'
expect(page).to have_content 'Indisponível Para Trabalho'
end
end

context 'de indisponível para disponível' do
it 'com sucesso' do
user = create(:user)
user.profile.unavailable!

login_as user
visit profile_settings_path(user.profile)
click_on 'Alterar Disponibilidade'

expect(page).to have_current_path profile_settings_path(user.profile)
expect(page).to have_content 'Alteração salva com sucesso'
expect(page).to have_content 'Disponível Para Trabalho'
end
end
end
4 changes: 2 additions & 2 deletions spec/system/settings/user_views_profile_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
within 'h2' do
expect(page).to have_content 'Configurações'
end
expect(page).to have_content 'Todos os dados relacionados ao seu perfil serão ARQUIVADOS'
expect(page).to have_content 'Atenção: Ao desativar o perfil todos os dados relacionados serão ARQUIVADOS.'
expect(page).to have_content 'Você pode reativar sua conta fazendo login novamente.'
expect(page).to have_button 'Desativar Perfil'
expect(page).to have_content 'Todos os dados relacionados a conta serão EXCLUÍDOS e não poderão ser recuperados'
expect(page).to have_button 'Excluir Conta'
end

Expand Down
Loading