Skip to content

Commit 8ec97f6

Browse files
committed
Merge branch 'main' into refactor/melhora-layout-do-perfil
2 parents f7602ff + bd89bea commit 8ec97f6

File tree

191 files changed

+9540
-429
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+9540
-429
lines changed

api_doc.md

+2-6

app/assets/images/avatars/avatar1.png

44.4 KB
34.3 KB
44 KB
34.2 KB
30.9 KB
24.5 KB
30.3 KB
31 KB
28.8 KB
34.6 KB
31.1 KB

app/assets/images/avatars/avatar2.png

39.3 KB
33 KB
26.2 KB
26.7 KB
37 KB
29.1 KB
30.6 KB
24.9 KB
36 KB
31.9 KB
21.4 KB

app/assets/images/avatars/avatar3.png

38.7 KB
29.7 KB
23 KB
36.8 KB
35.5 KB
43.8 KB
46.6 KB
37.4 KB
28.5 KB
26.8 KB
26 KB

app/assets/images/avatars/avatar4.png

33.4 KB
30.4 KB
37.2 KB
33.9 KB
38.1 KB
43.8 KB
32.3 KB
23.7 KB
33.3 KB
38.7 KB
24.7 KB

app/assets/images/avatars/avatar5.png

35.3 KB
38.6 KB
29.3 KB
20.7 KB
43.5 KB
28 KB
36 KB
40.4 KB
47.1 KB
34.1 KB
32.8 KB

app/assets/images/avatars/avatar6.png

39.7 KB
26.3 KB
42.5 KB
37 KB
35 KB
36.2 KB
33.1 KB
38.5 KB
31.1 KB
35.3 KB
33.5 KB

app/assets/images/avatars/avatar7.png

26.5 KB
33.3 KB

app/assets/images/avatars/avatar8.png

35.4 KB

app/assets/images/avatars/avatar9.png

31.6 KB

app/assets/stylesheets/application.bootstrap.scss

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ $theme-colors: (
99
"dark": #1b1b1b
1010
);
1111

12+
$primary: #a130fd;
13+
1214
@import 'bootstrap/scss/bootstrap';
1315
@import 'bootstrap-icons/font/bootstrap-icons';
1416
@import 'actiontext.css';

app/controllers/api/v1/invitations_controller.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ def create
99

1010
def update
1111
status = params.permit(:status)[:status]
12-
return render status: :bad_request, json: { error: 'Status inválido' } unless Invitation.statuses.key? status
12+
unless Invitation.statuses.key? status
13+
return render status: :bad_request,
14+
json: { error: I18n.t('invalid_status') }
15+
end
1316

1417
invitation = Invitation.find(params[:id])
1518
invitation.update!(status:)

app/controllers/api/v1/profiles_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def show
1515
profile = Profile.active.find(params[:id])
1616
render status: :ok, json: json_output(profile)
1717
rescue ActiveRecord::RecordNotFound
18-
render status: :not_found, json: { error: 'Perfil não existe.' }
18+
render status: :not_found, json: { error: I18n.t('profile_not_found') }
1919
end
2020

2121
private

app/controllers/notifications_controller.rb

+39
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,44 @@ class NotificationsController < ApplicationController
33

44
def index
55
@notifications = current_user.profile.notifications.order(created_at: :desc)
6+
@notifications.map { |n| n.seen! if n.unseen? }
7+
end
8+
9+
def update
10+
@notification = Notification.find(params[:id])
11+
@notification.clicked!
12+
redirect_to_notification
13+
end
14+
15+
private
16+
17+
def redirect_to_notification
18+
return redirect_to_invitation if @notification.notifiable.is_a? Invitation
19+
return redirect_to_comment if @notification.notifiable.is_a? Comment
20+
return redirect_to_connection if @notification.notifiable.is_a? Connection
21+
return redirect_to_post if @notification.notifiable.is_a? Post
22+
23+
redirect_to_like if @notification.notifiable.is_a? Like
24+
end
25+
26+
def redirect_to_invitation
27+
redirect_to invitation_path(@notification.notifiable)
28+
end
29+
30+
def redirect_to_comment
31+
redirect_to post_path(@notification.notifiable.post)
32+
end
33+
34+
def redirect_to_connection
35+
redirect_to profile_path(@notification.notifiable.follower)
36+
end
37+
38+
def redirect_to_post
39+
redirect_to post_path(@notification.notifiable)
40+
end
41+
42+
def redirect_to_like
43+
likeable = @notification.notifiable.likeable
44+
redirect_to post_path(likeable.is_a?(Comment) ? likeable.post : likeable)
645
end
746
end

app/controllers/posts_controller.rb

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class PostsController < ApplicationController
33
before_action :set_post, only: %w[show edit update pin]
44
before_action :authorize!, only: %w[edit update pin]
55
before_action :blocks_update, only: %w[update]
6+
before_action :redirect_if_removed_content, only: %w[show edit update pin]
67

78
require 'image_processing/mini_magick'
89

@@ -71,4 +72,10 @@ def authorize!
7172
def blocks_update
7273
redirect_to root_path, alert: t('.error') if @post.published? && @post.published_at && post_params['published_at']
7374
end
75+
76+
def redirect_if_removed_content
77+
return if current_user&.admin?
78+
79+
redirect_to root_path, alert: t('.redirect_alert.invalid_user') if @post.removed?
80+
end
7481
end

app/controllers/reports_controller.rb

+23-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class ReportsController < ApplicationController
55
before_action :redirect_unless_published_post
66
before_action :authorize!, only: %i[index show]
77
before_action :redirect_if_self_report, only: :create
8+
before_action :set_report, only: %i[reject show remove_content]
89

910
def new
1011
set_offences
@@ -18,13 +19,22 @@ def create
1819

1920
def index
2021
return @reports = Report.granted.all if params[:filter] == 'granted'
21-
return @reports = Report.not_granted.all if params[:filter] == 'not_granted'
22+
return @reports = Report.rejected.all if params[:filter] == 'rejected'
2223

2324
@reports = Report.pending.all
2425
end
2526

26-
def show
27-
@report = Report.find(params[:id])
27+
def show; end
28+
29+
def reject
30+
@report.rejected!
31+
redirect_to @report, notice: t('.success')
32+
end
33+
34+
def remove_content
35+
@report.reportable.removed!
36+
@report.granted!
37+
redirect_to @report, notice: t('.success')
2838
end
2939

3040
private
@@ -48,15 +58,19 @@ def redirect_unless_published_post
4858

4959
def set_offences
5060
@offences = [
51-
'Discurso de ódio',
52-
'Pornografia',
53-
'Racismo',
54-
'Spam',
55-
'Conteúdo pertubador',
56-
'Abuso/Perseguição'
61+
t('reports.hate_speech'),
62+
t('reports.pornography'),
63+
t('reports.racism'),
64+
t('reports.spam'),
65+
t('reports.disturbin_content'),
66+
t('reports.harassment')
5767
]
5868
end
5969

70+
def set_report
71+
@report = Report.find(params[:id])
72+
end
73+
6074
def post_and_published?
6175
return true unless @reportable.is_a? Post
6276

app/controllers/settings_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ def index; end
77
def deactivate_profile
88
current_user.profile.inactive!
99
sign_out current_user
10-
redirect_to root_path, alert: t('deactivate_profile')
10+
redirect_to root_path, alert: t('.success')
1111
end
1212

1313
def delete_account
1414
current_user.delete_user_data
15-
redirect_to root_path, notice: t('delete_account')
15+
redirect_to root_path, notice: t('.success')
1616
end
1717

1818
def change_privacy

app/helpers/posts_helper.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module PostsHelper
22
def date_fixer(post)
33
if post.draft?
4-
'Criado em: '
4+
t('posts.helpers.created_at')
55
elsif post.scheduled?
6-
'Agendado para: '
6+
t('posts.helpers.scheduled_for')
77
else
8-
'Publicado em: '
8+
t('posts.helpers.published_at')
99
end
1010
end
1111

app/mailers/invitations_mailer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ def received_invitation
33
profile = Profile.find(params[:profile_id])
44
project_title = params[:project_title]
55
mail(subject: t('.subject'), to: profile.user.email,
6-
body: "Você recebeu um convite para participar do projeto #{project_title}.")
6+
body: t('.body', title: project_title))
77
end
88
end

app/mailers/likes_mailer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def notify_like
88
@most_liked_post = @user.most_liked_post_since(1)
99
@most_liked_comment = @user.most_liked_comment_since(1)
1010

11-
mail(subject: "Você recebeu #{@post_likes.count + @comment_likes.count} curtidas nas últimas 24 horas!",
11+
mail(subject: t('.subject', likes: @post_likes.count + @comment_likes.count),
1212
to: @user.email)
1313
end
1414
end

app/models/comment.rb

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class Comment < ApplicationRecord
66
has_many :reports, as: :reportable, dependent: :destroy
77
has_many :notifications, as: :notifiable, dependent: :destroy
88

9+
enum status: { published: 0, removed: 20 }
10+
911
after_create :notify_interested_users
1012
after_create :create_notification
1113

app/models/connection.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Connection < ApplicationRecord
1515
def cant_follow_yourself
1616
return unless followed_profile == follower
1717

18-
errors.add(:followed_profile, 'não pode ser o mesmo do usuário')
18+
errors.add(:followed_profile, I18n.t('connections.same_user'))
1919
end
2020

2121
def create_notification

app/models/invitation.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def set_status
1919
def expiration_date_cannot_be_in_the_past
2020
return unless expiration_date.present? && expiration_date < Time.zone.today
2121

22-
errors.add(:expiration_date, 'deve ser maior que a data atual')
22+
errors.add(:expiration_date, I18n.t('invitations.date_error'))
2323
end
2424

2525
def truncate_description

app/models/notification.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class Notification < ApplicationRecord
22
belongs_to :profile
33
belongs_to :notifiable, polymorphic: true
4+
5+
enum status: { unseen: 0, seen: 5, clicked: 10 }
46
end

app/models/post.rb

+9-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Post < ApplicationRecord
1010
validate :file_size
1111
validate :validate_published_at
1212

13-
enum status: { published: 0, archived: 5, draft: 10, scheduled: 15 }
13+
enum status: { published: 0, archived: 5, draft: 10, scheduled: 15, removed: 20 }
1414
acts_as_ordered_taggable_on :tags
1515

1616
enum pin: { unpinned: 0, pinned: 10 }
@@ -61,7 +61,7 @@ def correct_file_type
6161
content_types = content.body.to_s.scan(/content-type="(.*?)"/)
6262

6363
content_types.each do |type|
64-
errors.add(:content, 'Tipo de arquivo inválido.') unless options.include? type[0]
64+
errors.add(:content, I18n.t('posts.model.invalid_file')) unless options.include? type[0]
6565
end
6666
end
6767

@@ -73,11 +73,11 @@ def file_size
7373

7474
def test_file_size(attachments)
7575
attachments.each do |attachment|
76-
validate_attachment_size(attachment, 'image/png', 2_000_000, 'Tamanho de imagem permitido é 2mb')
77-
validate_attachment_size(attachment, 'image/jpeg', 2_000_000, 'Tamanho de imagem permitido é 2mb')
78-
validate_attachment_size(attachment, 'video/mp4', 15_000_000, 'Tamanho do vídeo permitido é 15mb')
79-
validate_attachment_size(attachment, 'audio/mpeg', 3_000_000, 'Tamanho do áudio permitido é 3mb')
80-
validate_attachment_size(attachment, 'application/pdf', 900_000, 'Tamanho do PDF permitido é 900kb')
76+
validate_attachment_size(attachment, 'image/png', 2_000_000, I18n.t('posts.model.max_image_size'))
77+
validate_attachment_size(attachment, 'image/jpeg', 2_000_000, I18n.t('posts.model.max_image_size'))
78+
validate_attachment_size(attachment, 'video/mp4', 15_000_000, I18n.t('posts.model.max_video_size'))
79+
validate_attachment_size(attachment, 'audio/mpeg', 3_000_000, I18n.t('posts.model.max_audio_size'))
80+
validate_attachment_size(attachment, 'application/pdf', 900_000, I18n.t('posts.model.max_pdf_size'))
8181
end
8282
end
8383

@@ -89,7 +89,8 @@ def validate_attachment_size(attachment, content_type, size_limit, error_message
8989

9090
def validate_published_at
9191
return if published_at.nil?
92+
return unless scheduled?
9293

93-
errors.add(:published_at, 'não pode estar no passado') if published_at < (Time.zone.now - 1.second)
94+
errors.add(:published_at, I18n.t('posts.model.invalid_date')) if published_at < Time.zone.now
9495
end
9596
end

app/models/profile.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class Profile < ApplicationRecord
3838
enum privacy: { private_profile: 0, public_profile: 10 }
3939
enum status: { inactive: 0, active: 5 }
4040

41-
delegate :full_name, to: :user
42-
delegate :email, to: :user
41+
delegate :full_name, :email, to: :user
4342

4443
def self.advanced_search(search_query)
4544
left_outer_joins(:job_categories, :personal_info, :user).where(
@@ -115,13 +114,13 @@ def active!
115114
def valid_photo_content_type
116115
return if photo.present? && photo.content_type.in?(%w[image/jpg image/jpeg image/png])
117116

118-
errors.add(:photo, message: 'deve ser do formato .jpg, .jpeg ou .png') if photo.present?
117+
errors.add(:photo, message: I18n.t('profiles.model.photo_extention')) if photo.present?
119118
end
120119

121120
def photo_size_lower_than_3mb
122121
return if photo.present? && photo.byte_size <= 3.megabytes
123122

124-
errors.add(:photo, message: 'deve ter no máximo 3MB') if photo.present?
123+
errors.add(:photo, message: I18n.t('profiles.model.photo_size')) if photo.present?
125124
end
126125
end
127126

app/models/report.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Report < ApplicationRecord
22
belongs_to :profile
33
belongs_to :reportable, polymorphic: true
44

5-
enum status: { pending: 0, granted: 5, not_granted: 9 }
5+
enum status: { pending: 0, granted: 5, rejected: 9 }
66

77
def truncated_message
88
message.truncate(50)

app/models/user.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def subscribe_likes_mailer_job
8383
end
8484

8585
def validate_citizen_id_number
86-
errors.add(:citizen_id_number, 'inválido') unless CPF.valid?(citizen_id_number)
86+
errors.add(:citizen_id_number, I18n.t('users.model.invalid_cpf')) unless CPF.valid?(citizen_id_number)
8787
end
8888

8989
def transfer_posts_and_comments_to(clone)

app/views/connections/following.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="container text-center">
22
<div class="d-flex flex-column">
33
<h1 class="text-primary"><%= @profile.full_name %></span></h1>
4-
<h3>Seguindo <%= @followed_profiles.count %> <%= User.model_name.human(count: @followed_profiles.count).downcase %></h3>
4+
<h3><%= t('.following') %> <%= @followed_profiles.count %> <%= User.model_name.human(count: @followed_profiles.count).downcase %></h3>
55
</div>
66
<div class="row row-cols-1 row-cols-md-3 g-4 justify-content-center gap-3 mt-4">
77
<% @followed_profiles.each do |followed| %>

app/views/connections/index.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="container text-center">
22
<div class="d-flex flex-column">
33
<h1 class="text-primary"><%= @profile.full_name %></span></h1>
4-
<h2>Seguido por <%= @follower_profiles.count %> <%= User.model_name.human(count: @follower_profiles.count).downcase %></h2>
4+
<h2><%= t('.followed_by') %> <%= @follower_profiles.count %> <%= User.model_name.human(count: @follower_profiles.count).downcase %></h2>
55
</div>
66
<div class="row row-cols-1 row-cols-md-3 g-4 justify-content-center gap-3 mt-4">
77
<% @follower_profiles.each do |connection| %>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<p><%= I18n.t('notifications.new_follower_mail', follower_name: @notification.notifiable.follower.full_name) %></p>
1+
<p><%= @notification.notifiable.follower.full_name %> <%= t('notifications.started_following_you') %></p>

app/views/education_infos/_error_message.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% if @education_info.errors.any? %>
2-
<p>Verifique o(s) erro(s) abaixo:</p>
2+
<p><%= t('check_errors')%></p>
33
<ul class="alert alert-warning" role="alert">
44
<% @education_info.errors.full_messages.each do |msg| %>
55
<li><%= msg %> </li>

app/views/education_infos/_form.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
<%= education_info.label :visibility, class:"form-check-label" %>
2020
</p>
2121
<p class='mt-3'>
22-
<%= education_info.submit 'Salvar', class:'btn btn-primary' %>
23-
<%= link_to 'Voltar', profile_path(current_user.profile), class: 'btn btn-secondary' %>
22+
<%= education_info.submit t('save_btn'), class:'btn btn-primary' %>
23+
<%= link_to t('return_btn'), profile_path(current_user.profile), class: 'btn btn-secondary' %>
2424
</p>

0 commit comments

Comments
 (0)