Skip to content

Commit

Permalink
Merge branch 'main' into feat/admin-rules-report
Browse files Browse the repository at this point in the history
  • Loading branch information
Luckvc committed Feb 13, 2024
2 parents 8719d42 + 2da01f6 commit a417f6c
Show file tree
Hide file tree
Showing 66 changed files with 1,198 additions and 302 deletions.
1 change: 1 addition & 0 deletions app/assets/images/thumbs-up-regular.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/images/thumbs-up-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions app/assets/stylesheets/application.bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ $theme-colors: (
"light": rgba(255, 251, 251, 0.603),
"dark": #1b1b1b
);

$primary: #a130fd;

@import 'bootstrap/scss/bootstrap';
@import 'bootstrap-icons/font/bootstrap-icons';
@import 'actiontext.css';
Expand Down Expand Up @@ -70,4 +73,24 @@ input[type="checkbox"]:checked {

.categories{
width: 35% !important;
}

.highlighted {
transform: scale(1.01s);
background-color: hsla(256, 85%, 82%, 0.2);
box-shadow: 0 0 5px 5px rgba(0, 0, 0, 0.2);
transition:
transform 1.5s ease-in-out,
box-shadow 1.5s ease-in-out,
background-color 1.5s ease-in-out;
}

[id^='comment_'] {
transform: reset;
background-color: reset;
box-shadow: reset;
transition:
transform 1s ease-in-out,
box-shadow 1s ease-in-out,
background-color 1s ease-in-out;
}
12 changes: 12 additions & 0 deletions app/controllers/comments/likes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Comments
class LikesController < LikesController
before_action :set_likeable

private

def set_likeable
@likeable = Comment.find(params[:comment_id])
@post = @likeable.post
end
end
end
19 changes: 19 additions & 0 deletions app/controllers/invitation_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class InvitationRequestsController < ApplicationController
before_action :authenticate_user!, only: %i[index]

def index
invitation_requests = current_user.invitation_requests
@error = false
@invitation_request_infos = []

begin
@invitation_request_infos = InvitationRequestService::InvitationRequest.send(invitation_requests)
rescue StandardError
return @error = true
end

return @invitation_request_infos if params[:filter].blank?

@invitation_request_infos.filter! { |request| request.status == params[:filter] }
end
end
32 changes: 5 additions & 27 deletions app/controllers/likes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,18 @@ class LikesController < ApplicationController
before_action :authenticate_user!

def create
likeable, post_id = find_likeable_and_post_id
return unless likeable

like = current_user.likes.build(likeable:)
like = current_user.likes.build(likeable: @likeable)
if like.save
redirect_to post_path(post_id)
redirect_to post_path(@post)
else
redirect_to post_path(post_id), alert: t('.error')
redirect_to post_path(@post), alert: t('.error')
end
end

def destroy
if params[:post_like_id]
like = Like.find(params[:post_like_id])
post_id = like.likeable
elsif params[:comment_like_id]
like = Like.find(params[:comment_like_id])
post_id = like.likeable.post
end

like = current_user.likes.find(params[:id])
like.destroy

redirect_to post_path(post_id)
end

private

def find_likeable_and_post_id
if params[:post_id]
likeable = Post.find(params[:post_id])
[likeable, likeable.id]
elsif params[:comment_id]
likeable = Comment.find(params[:comment_id])
[likeable, likeable.post_id]
end
redirect_to post_path(@post)
end
end
39 changes: 39 additions & 0 deletions app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,44 @@ class NotificationsController < ApplicationController

def index
@notifications = current_user.profile.notifications.order(created_at: :desc)
@notifications.map { |n| n.seen! if n.unseen? }
end

def update
@notification = Notification.find(params[:id])
@notification.clicked!
redirect_to_notification
end

private

def redirect_to_notification
return redirect_to_invitation if @notification.notifiable.is_a? Invitation
return redirect_to_comment if @notification.notifiable.is_a? Comment
return redirect_to_connection if @notification.notifiable.is_a? Connection
return redirect_to_post if @notification.notifiable.is_a? Post

redirect_to_like if @notification.notifiable.is_a? Like
end

def redirect_to_invitation
redirect_to invitation_path(@notification.notifiable)
end

def redirect_to_comment
redirect_to post_path(@notification.notifiable.post)
end

def redirect_to_connection
redirect_to profile_path(@notification.notifiable.follower)
end

def redirect_to_post
redirect_to post_path(@notification.notifiable)
end

def redirect_to_like
likeable = @notification.notifiable.likeable
redirect_to post_path(likeable.is_a?(Comment) ? likeable.post : likeable)
end
end
12 changes: 12 additions & 0 deletions app/controllers/posts/likes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Posts
class LikesController < LikesController
before_action :set_likeable

private

def set_likeable
@likeable = Post.find(params[:post_id])
@post = @likeable
end
end
end
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
17 changes: 17 additions & 0 deletions app/helpers/invitation_requests_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module InvitationRequestsHelper
def css_color_class(status)
class_hash = { processing: 'text-secondary',
pending: 'text-info',
accepted: 'text-success',
refused: 'text-danger',
error: 'text-warning',
aborted: 'text-danger-emphasis' }
class_hash[status] || ''
end

def invitation_request_filter_options
InvitationRequest.statuses.keys.map do |status|
[InvitationRequest.human_attribute_name("status.#{status}"), status]
end
end
end
2 changes: 0 additions & 2 deletions app/javascript/components/projects_vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export default {
},

async created() {
this.errorMsg = false;

try {
let response = await fetch('/api/v1/projects', { signal });
if (response.ok) {
Expand Down
9 changes: 9 additions & 0 deletions app/jobs/post_interest_notification_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class PostInterestNotificationJob < ApplicationJob
queue_as :default

def perform(comment)
post = comment.post
users = post.comments.map(&:user).uniq.excluding(comment.user, post.user)
users.each { |user| Notification.create!(profile: user.profile, notifiable: comment) }
end
end
7 changes: 6 additions & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ class Comment < ApplicationRecord
belongs_to :user
has_many :likes, as: :likeable, dependent: :destroy
has_many :reports, as: :reportable, dependent: :destroy
has_many :notifications, as: :notifiable, dependent: :destroy

enum status: { published: 0, removed: 20 }
has_one :notification, as: :notifiable, dependent: :destroy

after_create :notify_interested_users
after_create :create_notification

private

def notify_interested_users
PostInterestNotificationJob.perform_later(self)
end

def create_notification
comment_author = user.profile
return if comment_author == post.user.profile
Expand Down
4 changes: 2 additions & 2 deletions app/models/invitation_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ class InvitationRequest < ApplicationRecord

validates :profile, uniqueness: { scope: :project_id }

after_create :queue_request_invitation_job

enum status: { processing: 0, pending: 5, accepted: 10, refused: 15, error: 20, aborted: 25 }

after_create :queue_request_invitation_job

def process_colabora_api_response(response)
response = json_treated_response(response)
if response.keys.first == 'data'
Expand Down
13 changes: 13 additions & 0 deletions app/models/invitation_request_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class InvitationRequestInfo
attr_accessor :id, :status, :created_at, :project_title, :project_description, :project_category, :project_id

def initialize(invitation_request:, project:)
@id = invitation_request.id
@status = invitation_request.status
@created_at = invitation_request.created_at
@project_id = project.id
@project_title = project.title
@project_description = project.description
@project_category = project.category
end
end
2 changes: 2 additions & 0 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Notification < ApplicationRecord
belongs_to :profile
belongs_to :notifiable, polymorphic: true

enum status: { unseen: 0, seen: 5, clicked: 10 }
end
5 changes: 2 additions & 3 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ class Profile < ApplicationRecord
enum privacy: { private_profile: 0, public_profile: 10 }
enum status: { inactive: 0, active: 5 }

delegate :full_name, to: :user
delegate :email, to: :user
delegate :full_name, :email, to: :user

def self.advanced_search(search_query)
left_outer_joins(:job_categories, :personal_info, :user).where(
'job_categories.name LIKE :term OR
personal_infos.city LIKE :term OR
users.full_name LIKE :term',
users.full_name LIKE :term OR users.search_name LIKE :term',
{ term: "%#{sanitize_sql_like(search_query)}%" }
).public_profile.active.uniq
end
Expand Down
10 changes: 10 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Project
attr_accessor :id, :title, :description, :category

def initialize(id:, title:, description:, category:)
@id = id
@title = title
@description = description
@category = category
end
end
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class User < ApplicationRecord

after_create :'create_profile!'
after_create :subscribe_likes_mailer_job
after_create :update_search_name

def description
if admin?
Expand Down Expand Up @@ -105,4 +106,8 @@ def cloned_user
clone.save!
clone
end

def update_search_name
update(search_name: I18n.transliterate(full_name, locale: :en))
end
end
Loading

0 comments on commit a417f6c

Please sign in to comment.