Merge branch 'master' into master-with-note-section

This commit is contained in:
Anton Ignatov 2019-04-30 12:07:59 +02:00
commit 7c55fcf0cf
13 changed files with 76 additions and 39 deletions

View file

@ -3,3 +3,6 @@ PreCommit:
enabled: true
on_warn: fail
problem_on_unmodified_line: ignore
ScssLint:
enabled: true
problem_on_unmodified_line: ignore

View file

@ -1,8 +1,8 @@
class RepositoriesController < ApplicationController
before_action :load_vars,
except: %i(index create create_modal parse_sheet import_records)
except: %i(index create create_modal parse_sheet)
before_action :load_parent_vars, except:
%i(repository_table_index export_repository parse_sheet import_records)
%i(repository_table_index parse_sheet)
before_action :check_team, only: %i(parse_sheet import_records)
before_action :check_view_all_permissions, only: :index
before_action :check_view_permissions, only: %i(export_repository show)
@ -243,6 +243,9 @@ class RepositoriesController < ApplicationController
status = import_records.import!
if status[:status] == :ok
log_activity(:import_inventory_items,
num_of_items: status[:nr_of_added])
flash[:success] = t('repositories.import_records.success_flash',
number_of_rows: status[:nr_of_added],
total_nr: status[:total_nr])
@ -272,15 +275,7 @@ class RepositoriesController < ApplicationController
def export_repository
if params[:row_ids] && params[:header_ids]
RepositoryZipExport.generate_zip(params, @repository, current_user)
Activities::CreateActivityService
.call(activity_type: :export_inventory_items,
owner: current_user,
subject: current_team,
team: current_team,
message_items: {
repository: @repository.id
})
log_activity(:export_inventory_items)
else
flash[:alert] = t('zip_export.export_error')
end
@ -355,12 +350,14 @@ class RepositoriesController < ApplicationController
end
end
def log_activity(type_of)
def log_activity(type_of, message_items = {})
message_items = { repository: @repository.id }.merge(message_items)
Activities::CreateActivityService
.call(activity_type: type_of,
owner: current_user,
subject: @repository,
team: @team,
message_items: { repository: @repository.id })
message_items: message_items)
end
end

View file

@ -30,4 +30,10 @@ class RepositoryRow < ApplicationRecord
def self.name_like(query)
where('repository_rows.name ILIKE ?', "%#{query}%")
end
def self.change_owner(team, user, new_owner)
joins(:repository)
.where('repositories.team_id = ? and repository_rows.created_by_id = ?', team, user)
.update_all(created_by_id: new_owner.id)
end
end

View file

@ -77,6 +77,10 @@ class UserTeam < ApplicationRecord
protocol.save
end
# Make new owner author of all inventory items that were added
# by departing user and belong to this team.
RepositoryRow.change_owner(team, user, new_owner)
super()
end

View file

@ -60,7 +60,8 @@ class RepositoryDatatableService
search_value)
.pluck(:id)
.uniq
repository_rows = RepositoryRow.where(id: repository_row_ids)
repository_rows = RepositoryRow.left_outer_joins(:created_by)
.where(id: repository_row_ids)
end
repository_rows

View file

@ -108,8 +108,6 @@ module RepositoryImportParser
raise ActiveRecord::Rollback
end
# Disable per row activity logging
# log_activity(record_row)
@new_rows_added += 1
end
end
@ -158,18 +156,5 @@ module RepositoryImportParser
end
current_column
end
def log_activity(repository_row)
Activities::CreateActivityService.call(
activity_type: :create_item_inventory,
owner: @user,
subject: @repository,
team: @repository.team,
message_items: {
repository_row: repository_row.id,
repository: @repository.id
}
)
end
end
end

View file

@ -2,17 +2,17 @@
<%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %>
<%= render partial: "shared/secondary_navigation" %>
<div class="global-activities-container container-flex task_activities">
<div class="global-activities-container container-flex task_activities">
<div class="row">
<div class="ga-top col-md-12 task_activities">
<%= render partial: "my_modules/activities/top_pane" %>
</div>
<div class="ga-side col-lg-3 col-md-12 col-xl-2 task_activities perfect-scrollbar">
<div class="ga-side col-lg-3 col-md-12 col-xl-2 task_activities perfect-scrollbar">
<%= render partial: "my_modules/activities/side_filters" %>
</div>
<div class="ga-main col-lg-9 col-md-12 col-xl-10 task_activities perfect-scrollbar">
<div class="ga-main col-lg-9 col-md-12 col-xl-10 task_activities perfect-scrollbar">
<div class="no-activities-message text-center <%= 'hidden' if @grouped_activities.keys.any? %>">
<p><%= t('activities.index.no_activities_task_message') %></p>
</div>
@ -27,6 +27,7 @@
<%= t'activities.index.more_activities' %>
</a>
</div>
<div id="ga-more-activities-placeholder" class="hidden"></div>
</div>
</div>

View file

@ -15,6 +15,7 @@
<li><%= t("users.settings.user_teams.destroy_uo_alert_line_1") %></li>
<li><%= t("users.settings.user_teams.destroy_uo_alert_line_2").html_safe %></li>
<li><%= t("users.settings.user_teams.destroy_uo_alert_line_3") %></li>
<li><%= t("users.settings.user_teams.destroy_uo_alert_line_4") %></li>
</ul>
</div>
<% end %>

View file

@ -13,6 +13,7 @@
<li><%= t("users.settings.user_teams.leave_uo_alert_line_1") %></li>
<li><%= t("users.settings.user_teams.leave_uo_alert_line_2").html_safe %></li>
<li><%= t("users.settings.user_teams.leave_uo_alert_line_3")%></li>
<li><%= t("users.settings.user_teams.leave_uo_alert_line_4")%></li>
</ul>
</div>
<% end %>

View file

@ -215,6 +215,7 @@ class Extends
user_leave_team: 104,
copy_inventory: 105,
export_protocol_from_task: 106,
import_inventory_items: 107,
create_tag: 108,
delete_tag: 109
}
@ -227,7 +228,7 @@ class Extends
task_inventory: [55, 56],
experiment: [*27..31, 57],
reports: [48, 50, 49],
inventories: [70, 71, 105, 72, 73, 74, 102, 75, 76, 77, 78, 96],
inventories: [70, 71, 105, 72, 73, 74, 102, 75, 76, 77, 78, 96, 107],
protocol_repository: [80, 103, 89, 87, 79, 90, 91, 88, 85, 86, 84, 81, 82, 83, 101],
team: [92, 94, 93, 97, 104]
}.freeze

View file

@ -1504,14 +1504,16 @@ en:
leave_uo_alert_heading: "Leaving team has following consequences:"
leave_uo_alert_line_1: "you will lose access to all content belonging to the team (including projects, tasks, protocols and activities);"
leave_uo_alert_line_2: "all projects in the team where you were the sole <b>Owner</b> will receive a new owner from the team administrators;"
leave_uo_alert_line_3: "all repository protocols in the team belonging to you will be reassigned onto a new owner from team administrators."
leave_uo_alert_line_3: "all repository protocols in the team belonging to you will be reassigned onto a new owner from team administrators;"
leave_uo_alert_line_4: "all inventory items in the team added by you will be reassigned onto a new owner from team administrators."
leave_uo_confirm: "Leave"
destroy_uo_heading: "Remove user %{user} from team %{team}"
destroy_uo_message: "Are you sure you wish to remove user %{user} from team %{team}?"
destroy_uo_alert_heading: "Removing user from team has following consequences:"
destroy_uo_alert_line_1: "user will lose access to all content belonging to the team (including projects, tasks, protocols and activities);"
destroy_uo_alert_line_2: "all projects in the team where user was the sole <b>Owner</b> will be reassigned onto you as a new owner;"
destroy_uo_alert_line_3: "all repository protocols in the team belonging to user will be reassigned onto you."
destroy_uo_alert_line_3: "all repository protocols in the team belonging to user will be reassigned onto you;"
destroy_uo_alert_line_4: "all inventory items in the team added by user will be reassigned onto you."
destroy_uo_confirm: "Remove"
leave_flash: "Successfuly left team %{team}."

View file

@ -130,6 +130,7 @@ en:
create_tag_html: "%{user} created tag <strong>%{tag}</strong> in project %{project}."
edit_tag_html: "%{user} edited tag <strong>%{tag}</strong> in project %{project}."
delete_tag_html: "%{user} deleted tag <strong>%{tag}</strong> in project %{project}."
import_inventory_items_html: "%{user} imported %{num_of_items} inventory item(s) to %{repository}."
activity_name:
create_project: "Project created"
@ -231,6 +232,7 @@ en:
create_tag: "Tag created"
edit_tag: "Tag edited"
delete_tag: "Tag deleted"
import_inventory_items: "Inventory items imported"
activity_group:
projects: "Projects"

View file

@ -13,7 +13,7 @@ describe RepositoriesController, type: :controller do
describe 'POST create' do
let(:params) { { repository: { name: 'My Repository' } } }
it 'calls create activity for unarchiving experiment' do
it 'calls create activity for creating inventory' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :create_inventory)))
@ -32,7 +32,7 @@ describe RepositoriesController, type: :controller do
let(:params) { { id: repository.id, team_id: team.id } }
let(:action) { delete :destroy, params: params }
it 'calls create activity for unarchiving experiment' do
it 'calls create activity for deleting inventory' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :delete_inventory)))
@ -53,7 +53,7 @@ describe RepositoriesController, type: :controller do
end
let(:action) { put :update, params: params, format: :json }
it 'calls create activity for unarchiving experiment' do
it 'calls create activity for renaming inventory' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :rename_inventory)))
@ -87,7 +87,7 @@ describe RepositoriesController, type: :controller do
end
let(:action) { post :export_repository, params: params, format: :json }
it 'calls create activity for unarchiving experiment' do
it 'calls create activity for exporting inventory items' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :export_inventory_items)))
@ -100,4 +100,37 @@ describe RepositoriesController, type: :controller do
.to(change { Activity.count })
end
end
describe 'POST import_records' do
let(:repository) { create :repository, team: team }
let(:mappings) do
{ '0': '-1', '1': '', '2': '', '3': '', '4': '', '5': '' }
end
let(:params) do
{ id: repository.id,
team_id: team.id,
file_id: 'file_id',
mappings: mappings }
end
let(:action) { post :import_records, params: params, format: :json }
it 'calls create activity for importing inventory items' do
allow_any_instance_of(ImportRepository::ImportRecords)
.to receive(:import!).and_return(status: :ok)
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :import_inventory_items)))
action
end
it 'adds activity in DB' do
ImportRepository::ImportRecords.any_instance.stub(:import!)
.and_return(status: :ok)
expect { action }
.to(change { Activity.count })
end
end
end