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

[681] Adds a comments section to the admin panel #772

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ GEM
PLATFORMS
arm64-darwin-22
arm64-darwin-23
arm64-darwin-24
x86_64-darwin-21
x86_64-darwin-22
x86_64-linux
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ setup:
setup-heroku-arm64:
arch -x86_64 /bin/zsh -c 'curl https://cli-assets.heroku.com/install.sh | sh'

# setup-arm64: setup-heroku-arm64 setup-app
setup-arm64: setup-heroku-arm64 setup-app

setup-app:
cp -n .env.example .env || true
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/web/admin/comments/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Web::Admin::Comments::ApplicationController < Web::Admin::ApplicationController
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

class Web::Admin::Comments::ResumesAnswersCommentsController < Web::Admin::Comments::ApplicationController
before_action :set_answers_comment, only: %i[edit update archive restore]

def edit; end

def update
if @comment.update(comment_params)
f(:success)
redirect_to admin_resumes_answers_path
else
f(:error)
render :edit, status: :unprocessable_entity
end
end

def archive
return unless @comment.may_archive?

@comment.archive!
f(:success)
redirect_to admin_resumes_answers_path
end

def restore
return unless @comment.may_restore?

@comment.restore!
f(:success)
redirect_to admin_resumes_answers_path
end

private

def set_answers_comment
@comment = Resume::Answer::Comment.find(params[:id])
end

def comment_params
params.require(:resume_answer_comment).permit(:content)
end
end
53 changes: 53 additions & 0 deletions app/controllers/web/admin/comments/resumes_answers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

class Web::Admin::Comments::ResumesAnswersController < Web::Admin::Comments::ApplicationController
before_action :set_answer, only: %i[edit update archive restore]

def index
@search = Resume::Answer.web.includes(comments: :user).ransack(params[:q])
@resumes_answers = @search.result(sort: 'created_at desc').page(params[:page])
end

def edit; end

def update
if @answer.update(answer_params)
f(:success)
redirect_to admin_resumes_answers_path
else
f(:error)
render :edit, status: :unprocessable_entity
end
end

def archive
return unless @answer.may_archive?

@answer.archive!
f(:success)
redirect_to admin_resumes_answers_path
end

def restore
return unless @answer.may_restore?

@answer.restore!
f(:success)
redirect_to admin_resumes_answers_path
end

def archived
@search = Resume::Answer.web.includes(comments: :user).where(publishing_state: 'archived').ransack(params[:q])
@resumes_answers = @search.result(sort: 'created_at desc').page(params[:page])
end

private

def set_answer
@answer = Resume::Answer.find(params[:id])
end

def answer_params
params.require(:resume_answer).permit(:content)
end
end
52 changes: 52 additions & 0 deletions app/controllers/web/admin/comments/resumes_comments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

class Web::Admin::Comments::ResumesCommentsController < Web::Admin::Comments::ApplicationController
before_action :set_comment, only: %i[edit update archive restore]
def index
@search = Resume::Comment.web.includes(:user).ransack(params[:q])
@resumes_comments = @search.result(sort: 'created_at desc').page(params[:page])
end

def archive
return unless @comment.may_archive?

@comment.archive!
f(:success)
redirect_to admin_resumes_comments_path
end

def restore
return unless @comment.may_restore?

@comment.restore!
f(:success)
redirect_to admin_resumes_comments_path
end

def archived
@search = Resume::Comment.web.includes(:user).where(publishing_state: 'archived').ransack(params[:q])
@resumes_comments = @search.result(sort: 'created_at desc').page(params[:page])
end

def edit; end

def update
if @comment.update(comment_params)
f(:success)
redirect_to admin_resumes_comments_path
else
f(:error)
render :edit, status: :unprocessable_entity
end
end

private

def set_comment
@comment = Resume::Comment.find(params[:id])
end

def comment_params
params.require(:resume_comment).permit(:content)
end
end
7 changes: 7 additions & 0 deletions app/helpers/model_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ module ModelHelper
def states_for_select(model, state_machine = :state)
model.aasm(state_machine).states.map { |s| [s.human_name, s.name] }
end

def state_for_render(model, state_machine = :state, state_name = :default)
model.aasm(state_machine)
.states
.find { |s| s.name == state_name.to_sym }
.try(:human_name)
end
end
36 changes: 27 additions & 9 deletions app/models/resume/answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#
# Table name: resume_answers
#
# id :integer not null, primary key
# applying_state :string
# content :text
# likes_count :integer
# created_at :datetime not null
# updated_at :datetime not null
# resume_id :integer not null
# user_id :integer not null
# id :integer not null, primary key
# applying_state :string
# content :text
# likes_count :integer
# publishing_state :string default("published")
# created_at :datetime not null
# updated_at :datetime not null
# resume_id :integer not null
# user_id :integer not null
#
# Indexes
#
Expand Down Expand Up @@ -46,6 +47,19 @@ class Resume::Answer < ApplicationRecord
end
end

aasm :publishing, column: :publishing_state do
state :published, initial: true
state :archived

event :archive do
transitions from: :published, to: :archived
end

event :restore do
transitions from: :archived, to: :published
end
end

def to_s
content
end
Expand All @@ -59,6 +73,10 @@ def tota_ai_author?
end

def self.ransackable_attributes(_auth_object = nil)
%w[user_id]
%w[id content user_id publishing_state applying_state created_at]
end

def self.ransackable_associations(_auth_object = nil)
%w[comments likes notifications resume user]
end
end
39 changes: 31 additions & 8 deletions app/models/resume/answer/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#
# Table name: resume_answer_comments
#
# id :integer not null, primary key
# content :string
# created_at :datetime not null
# updated_at :datetime not null
# answer_id :integer not null
# answer_user_id :integer not null
# resume_id :integer not null
# user_id :integer not null
# id :integer not null, primary key
# content :string
# publishing_state :string default("published")
# created_at :datetime not null
# updated_at :datetime not null
# answer_id :integer not null
# answer_user_id :integer not null
# resume_id :integer not null
# user_id :integer not null
#
# Indexes
#
Expand All @@ -28,6 +29,7 @@
# user_id (user_id => users.id)
#
class Resume::Answer::Comment < ApplicationRecord
include AASM
validates :content, presence: true, length: { minimum: 10, maximum: 400 }

belongs_to :resume
Expand All @@ -38,11 +40,32 @@ class Resume::Answer::Comment < ApplicationRecord

include Resume::Answer::CommentRepository

aasm :publishing, column: :publishing_state do
state :published, initial: true
state :archived

event :archive do
transitions from: :published, to: :archived
end

event :restore do
transitions from: :archived, to: :published
end
end

def to_s
content
end

def author?(user)
user_id == user.id
end

def self.ransackable_associations(_auth_object = nil)
%w[answer answer_user notifications resume user]
end

def self.ransackable_attributes(_auth_object = nil)
%w[answer_id answer_user_id content created_at id id_value resume_id updated_at user_id]
end
end
35 changes: 29 additions & 6 deletions app/models/resume/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,54 @@
#
# Table name: resume_comments
#
# id :integer not null, primary key
# content :string
# created_at :datetime not null
# updated_at :datetime not null
# resume_id :integer
# user_id :integer
# id :integer not null, primary key
# content :string
# publishing_state :string default("published")
# created_at :datetime not null
# updated_at :datetime not null
# resume_id :integer
# user_id :integer
#
# Indexes
#
# index_resume_comments_on_resume_id (resume_id)
# index_resume_comments_on_user_id (user_id)
#
class Resume::Comment < ApplicationRecord
include AASM
include Resume::CommentRepository
validates :content, presence: true, length: { minimum: 10, maximum: 400 }

belongs_to :resume
belongs_to :user
has_many :notifications, as: :resource, dependent: :destroy

aasm :publishing, column: :publishing_state do
state :published, initial: true
state :archived

event :archive do
transitions from: :published, to: :archived
end

event :restore do
transitions from: :archived, to: :published
end
end

def to_s
content
end

def author?(user)
user_id == user.id
end

def self.ransackable_attributes(_auth_object = nil)
%w[content created_at id id_value resume_id updated_at user_id]
end

def self.ransackable_associations(_auth_object = nil)
%w[notifications resume user]
end
end
3 changes: 3 additions & 0 deletions app/views/layouts/web/admin/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ html.h-100 lang="#{I18n.locale}"
= sidebar_menu_item t('.admins'), 'bi-person-fill-gear', admin_root_path
= sidebar_menu_item t('.all_users'), 'bi-people', admin_users_path
= sidebar_menu_item t('.all_resumes'), 'bi-card-text', admin_resumes_path
= sidebar_menu_divider t('.comments')
= sidebar_menu_item t('.resume_comments'), 'bi-chat-dots', admin_resumes_comments_path
= sidebar_menu_item t('.resume_answers'), 'bi-chat-dots', admin_resumes_answers_path
= sidebar_menu_divider t('.vacancies')
= sidebar_menu_item t('.on_moderate'), 'bi-briefcase', on_moderate_admin_vacancies_path
= sidebar_menu_item t('.all_vacancies'), 'bi-briefcase-fill', admin_vacancies_path
Expand Down
Loading
Loading