mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 10:14:17 +08:00
Reports activities refactoring
This commit is contained in:
parent
d1e38e5bc9
commit
1418abc8d7
4 changed files with 92 additions and 32 deletions
|
@ -68,16 +68,13 @@ class ReportsController < ApplicationController
|
||||||
|
|
||||||
if continue && @report.save_with_contents(report_contents)
|
if continue && @report.save_with_contents(report_contents)
|
||||||
# record an activity
|
# record an activity
|
||||||
Activity.create(
|
Activities::CreateActivityService
|
||||||
type_of: :create_report,
|
.call(activity_type: :create_report,
|
||||||
|
owner: current_user,
|
||||||
|
subject: @report,
|
||||||
|
team: @report.team,
|
||||||
project: @report.project,
|
project: @report.project,
|
||||||
user: current_user,
|
message_items: { report: @report.id })
|
||||||
message: I18n.t(
|
|
||||||
'activities.create_report',
|
|
||||||
user: current_user.full_name,
|
|
||||||
report: @report.name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
render json: { url: reports_path }, status: :ok
|
render json: { url: reports_path }, status: :ok
|
||||||
|
@ -113,16 +110,13 @@ class ReportsController < ApplicationController
|
||||||
|
|
||||||
if continue && @report.save_with_contents(report_contents)
|
if continue && @report.save_with_contents(report_contents)
|
||||||
# record an activity
|
# record an activity
|
||||||
Activity.create(
|
Activities::CreateActivityService
|
||||||
type_of: :edit_report,
|
.call(activity_type: :edit_report,
|
||||||
|
owner: current_user,
|
||||||
|
subject: @report,
|
||||||
|
team: @report.team,
|
||||||
project: @report.project,
|
project: @report.project,
|
||||||
user: current_user,
|
message_items: { report: @report.id })
|
||||||
message: I18n.t(
|
|
||||||
'activities.edit_report',
|
|
||||||
user: current_user.full_name,
|
|
||||||
report: @report.name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
render json: { url: reports_path }, status: :ok
|
render json: { url: reports_path }, status: :ok
|
||||||
|
@ -149,16 +143,13 @@ class ReportsController < ApplicationController
|
||||||
report = Report.find_by_id(report_id)
|
report = Report.find_by_id(report_id)
|
||||||
next unless report.present? && can_manage_reports?(current_team)
|
next unless report.present? && can_manage_reports?(current_team)
|
||||||
# record an activity
|
# record an activity
|
||||||
Activity.create(
|
Activities::CreateActivityService
|
||||||
type_of: :delete_report,
|
.call(activity_type: :delete_report,
|
||||||
|
owner: current_user,
|
||||||
|
subject: report,
|
||||||
|
team: report.team,
|
||||||
project: report.project,
|
project: report.project,
|
||||||
user: current_user,
|
message_items: { report: report.id })
|
||||||
message: I18n.t(
|
|
||||||
'activities.delete_report',
|
|
||||||
user: current_user.full_name,
|
|
||||||
report: report.name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
report.destroy
|
report.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -85,11 +85,11 @@ class Extends
|
||||||
FILE_FA_ICON_MAPPINGS = {}
|
FILE_FA_ICON_MAPPINGS = {}
|
||||||
|
|
||||||
ACTIVITY_SUBJECT_TYPES = %w(
|
ACTIVITY_SUBJECT_TYPES = %w(
|
||||||
Team Repository Project Experiment MyModule Result Protocol Step
|
Team Repository Project Experiment MyModule Result Protocol Step Report
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
SEARCHABLE_ACTIVITY_SUBJECT_TYPES = %w(
|
SEARCHABLE_ACTIVITY_SUBJECT_TYPES = %w(
|
||||||
Repository Project Experiment MyModule Result Protocol Step
|
Repository Project Experiment MyModule Result Protocol Step Report
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
ACTIVITY_MESSAGE_ITEMS_TYPES =
|
ACTIVITY_MESSAGE_ITEMS_TYPES =
|
||||||
|
|
68
spec/controllers/reports_controller_spec.rb
Normal file
68
spec/controllers/reports_controller_spec.rb
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe ReportsController, type: :controller do
|
||||||
|
login_user
|
||||||
|
|
||||||
|
let(:user) { User.first }
|
||||||
|
let!(:team) { create :team, created_by: user }
|
||||||
|
let!(:user_team) { create :user_team, team: team, user: user }
|
||||||
|
let(:user_project) { create :user_project, :owner, user: user }
|
||||||
|
let(:project) do
|
||||||
|
create :project, team: team, user_projects: [user_project]
|
||||||
|
end
|
||||||
|
let(:report) do
|
||||||
|
create :report, user: user, project: project, team: team,
|
||||||
|
name: 'test repot A1', description: 'test description A1'
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#create' do
|
||||||
|
context 'in JSON format' do
|
||||||
|
let(:params) do
|
||||||
|
{ project_id: project.id,
|
||||||
|
report: { name: 'test report created',
|
||||||
|
description: 'test description created' },
|
||||||
|
report_contents: '[{"type_of":"project_header","id":{"project_id":' +
|
||||||
|
project.id.to_s + '},"sort_order":null,"children":[]}]' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'calls create activity service' do
|
||||||
|
expect(Activities::CreateActivityService).to receive(:call)
|
||||||
|
.with(hash_including(activity_type: :create_report))
|
||||||
|
|
||||||
|
post :create, params: params, format: :json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#update' do
|
||||||
|
context 'in JSON format' do
|
||||||
|
let(:params) do
|
||||||
|
{ project_id: project.id,
|
||||||
|
id: report.id,
|
||||||
|
report: { name: 'test report update',
|
||||||
|
description: 'test description update' },
|
||||||
|
report_contents: '[{"type_of":"project_header","id":{"project_id":' +
|
||||||
|
project.id.to_s + '},"sort_order":null,"children":[]}]' }
|
||||||
|
end
|
||||||
|
it 'calls create activity service' do
|
||||||
|
expect(Activities::CreateActivityService).to receive(:call)
|
||||||
|
.with(hash_including(activity_type: :edit_report))
|
||||||
|
|
||||||
|
put :update, params: params, format: :json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#destroy' do
|
||||||
|
let(:params) { { report_ids: "[#{report.id}]" } }
|
||||||
|
|
||||||
|
it 'calls create activity service' do
|
||||||
|
expect(Activities::CreateActivityService).to receive(:call)
|
||||||
|
.with(hash_including(activity_type: :delete_report))
|
||||||
|
|
||||||
|
delete :destroy, params: params
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -6,5 +6,6 @@ FactoryBot.define do
|
||||||
project
|
project
|
||||||
team
|
team
|
||||||
name { Faker::Name.unique.name }
|
name { Faker::Name.unique.name }
|
||||||
|
description { Faker::Lorem.sentence }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue