Skip to content

Commit

Permalink
Merge branch 'main' into feat/super-seed
Browse files Browse the repository at this point in the history
  • Loading branch information
GyodaiDDA authored Feb 13, 2024
2 parents 3188790 + 2da01f6 commit 1e804ca
Show file tree
Hide file tree
Showing 110 changed files with 2,521 additions and 377 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;
}
21 changes: 21 additions & 0 deletions app/controllers/api/v1/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ def index
render status: :internal_server_error, json: errors.as_json
end
end

def request_invitation
data = proposal_params.as_json
connection = Faraday.new(url: 'http://localhost:3000', params: data)
response = connection.post('api/v1/proposals')

if response.status == 201
proposal = JSON.parse(response.body)
render status: :ok, json: proposal.as_json
else
errors = response.body
render status: :ok, json: errors.as_json
end
end

private

def proposal_params
proposal_attributes = %i[invitation_request_id email message profile_id project_id]
params.require(:data).permit(proposal: proposal_attributes)
end
end
end
end
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
41 changes: 40 additions & 1 deletion app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@ class NotificationsController < ApplicationController
before_action :authenticate_user!

def index
@notifications = current_user.profile.notifications
@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
35 changes: 2 additions & 33 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class ProfilesController < ApplicationController
before_action :authenticate_user!
before_action :set_profile_and_posts, only: %i[show edit remove_photo update]
before_action :private_profile?, only: %i[show]
before_action :redirect_unauthorized_access, only: %i[edit update remove_photo settings]
before_action :redirect_unauthorized_access, only: %i[edit update remove_photo]

def edit; end

Expand All @@ -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,22 +39,11 @@ def private_profile?
redirect_to root_path, alert: t('.private')
end

def settings; end

def deactivate_profile
current_user.profile.inactive!
sign_out current_user
redirect_to root_path, alert: t('.success')
end

private

def profile_params
params.require(:profile).permit(:photo)
end

def redirect_unauthorized_access
@profile = Profile.find(params[:profile_id]) if params[:profile_id]
return if current_user == @profile.user

redirect_to root_path, alert: t('alerts.unauthorized')
Expand Down
24 changes: 21 additions & 3 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class ReportsController < ApplicationController
before_action :set_reportable_for_new, only: :new
before_action :set_reportable_for_create, only: :create
before_action :redirect_unless_published_post
before_action :authorize!, only: %i[index show]
before_action :redirect_if_self_report, only: :create

def new
Expand All @@ -15,13 +16,24 @@ def create
redirect_to root_path, notice: t('.success')
end

def index
return @reports = Report.granted.all if params[:filter] == 'granted'
return @reports = Report.not_granted.all if params[:filter] == 'not_granted'

@reports = Report.pending.all
end

def show
@report = Report.find(params[:id])
end

private

def set_reportable_for_new
reportable_id = params[:reportable]
@reportable = Post.find_by(reportable_id) if params[:reportable_type] == 'Post'
@reportable = Profile.find_by(reportable_id) if params[:reportable_type] == 'Profile'
@reportable = Comment.find_by(reportable_id) if params[:reportable_type] == 'Comment'
@reportable = Post.find(reportable_id) if params[:reportable_type] == 'Post'
@reportable = Profile.find(reportable_id) if params[:reportable_type] == 'Profile'
@reportable = Comment.find(reportable_id) if params[:reportable_type] == 'Comment'
end

def set_reportable_for_create
Expand Down Expand Up @@ -51,6 +63,12 @@ def post_and_published?
@reportable.published?
end

def authorize!
return if current_user.admin?

redirect_to root_path, alert: t('alerts.unauthorized')
end

def redirect_if_self_report
return if @reportable.is_a?(Profile) && @reportable != current_user.profile
return if @reportable.is_a?(Comment) && @reportable.user != current_user
Expand Down
48 changes: 48 additions & 0 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class SettingsController < ApplicationController
before_action :authenticate_user!
before_action :redirect_unauthorized_access, only: %i[index]

def index; end

def deactivate_profile
current_user.profile.inactive!
sign_out current_user
redirect_to root_path, alert: t('deactivate_profile')
end

def delete_account
current_user.delete_user_data
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
@profile = Profile.find(params[:profile_id])
return if current_user == @profile.user

redirect_to root_path, alert: t('alerts.unauthorized')
end
end
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
Loading

0 comments on commit 1e804ca

Please sign in to comment.