mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-04-02 18:31:30 +08:00
Add creating activities for Team actions
This commit is contained in:
parent
3f18166320
commit
e7b57aa4f7
4 changed files with 149 additions and 0 deletions
app/controllers/users
spec/controllers
|
@ -128,6 +128,17 @@ module Users
|
|||
user_team.team
|
||||
)
|
||||
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: :invite_user_to_team,
|
||||
owner: current_user,
|
||||
subject: current_team,
|
||||
team: current_team,
|
||||
message_items: {
|
||||
team: current_team.id,
|
||||
user_invited: user.id,
|
||||
role: user_team.role_str
|
||||
})
|
||||
|
||||
if result[:status] == :user_exists && !user.confirmed?
|
||||
result[:status] = :user_exists_unconfirmed_invited_to_team
|
||||
elsif result[:status] == :user_exists
|
||||
|
|
|
@ -21,6 +21,18 @@ module Users
|
|||
# he/she should be redirected to teams page
|
||||
new_path = teams_path if @user_t.user == @current_user &&
|
||||
@user_t.role != 'admin'
|
||||
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: :change_users_role_on_team,
|
||||
owner: current_user,
|
||||
subject: @user_t.team,
|
||||
team: @user_t.team,
|
||||
message_items: {
|
||||
team: @user_t.team.id,
|
||||
user_changed: @user_t.user.id,
|
||||
role: @user_t.role.to_s
|
||||
})
|
||||
|
||||
format.json do
|
||||
render json: {
|
||||
status: :ok,
|
||||
|
@ -107,6 +119,17 @@ module Users
|
|||
new_owner = current_user
|
||||
end
|
||||
reset_user_current_team(@user_t)
|
||||
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: :remove_user_from_team,
|
||||
owner: current_user,
|
||||
subject: @user_t.team,
|
||||
team: @user_t.team,
|
||||
message_items: {
|
||||
team: @user_t.team.id,
|
||||
user_removed: @user_t.user.id
|
||||
})
|
||||
|
||||
@user_t.destroy(new_owner)
|
||||
end
|
||||
rescue Exception
|
||||
|
|
44
spec/controllers/invitations_controller_spec.rb
Normal file
44
spec/controllers/invitations_controller_spec.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Users::InvitationsController, type: :controller do
|
||||
login_user
|
||||
|
||||
let(:user) { subject.current_user }
|
||||
let!(:team) { create :team, created_by: user }
|
||||
let!(:user_team) { create :user_team, :admin, user: user, team: team }
|
||||
|
||||
describe 'POST invite_users' do
|
||||
let(:invited_user) { create :user }
|
||||
let(:team) { create :team }
|
||||
let(:params) do
|
||||
{
|
||||
teamId: team.id,
|
||||
emails: [invited_user.email],
|
||||
role: 'guest'
|
||||
}
|
||||
end
|
||||
let(:action) { post :invite_users, params: params, format: :json }
|
||||
|
||||
context 'when inviting existing user not in the team' do
|
||||
it 'calls create activity for inviting user' do
|
||||
expect(Activities::CreateActivityService)
|
||||
.to(receive(:call)
|
||||
.with(hash_including(activity_type: :invite_user_to_team)))
|
||||
|
||||
action
|
||||
end
|
||||
|
||||
it 'adds activity in DB' do
|
||||
expect { action }
|
||||
.to(change { Activity.count })
|
||||
end
|
||||
|
||||
it 'adds user_team record in DB' do
|
||||
expect { action }
|
||||
.to(change { UserTeam.count })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
71
spec/controllers/user_teams_controller_spec.rb
Normal file
71
spec/controllers/user_teams_controller_spec.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Users::Settings::UserTeamsController, type: :controller do
|
||||
login_user
|
||||
|
||||
let(:user) { subject.current_user }
|
||||
let(:team) { create :team, created_by: user }
|
||||
let!(:user_team) { create :user_team, :admin, user: user, team: team }
|
||||
let(:another_user) { create :user }
|
||||
let!(:another_user_team) do
|
||||
create :user_team, :normal_user, user: another_user, team: team
|
||||
end
|
||||
describe 'POST invite_users' do
|
||||
let(:params) do
|
||||
{
|
||||
id: another_user.id
|
||||
}
|
||||
end
|
||||
let(:action) { delete :destroy, params: params, format: :json }
|
||||
|
||||
context 'when inviting existing user not in the team' do
|
||||
it 'calls create activity for inviting user' do
|
||||
expect(Activities::CreateActivityService)
|
||||
.to(receive(:call)
|
||||
.with(hash_including(activity_type: :remove_user_from_team)))
|
||||
|
||||
action
|
||||
end
|
||||
|
||||
it 'adds activity in DB' do
|
||||
expect { action }
|
||||
.to(change { Activity.count })
|
||||
end
|
||||
|
||||
it 'remove user_team record from DB' do
|
||||
expect { action }
|
||||
.to(change { UserTeam.count })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT update' do
|
||||
let(:params) do
|
||||
{
|
||||
id: another_user.id,
|
||||
user_team: {
|
||||
role: 'admin'
|
||||
}
|
||||
}
|
||||
end
|
||||
let(:action) { put :update, params: params, format: :json }
|
||||
|
||||
context 'when updating user role in the team' do
|
||||
it 'calls create activity for updating role' do
|
||||
expect(Activities::CreateActivityService)
|
||||
.to(receive(:call)
|
||||
.with(hash_including(activity_type:
|
||||
:change_users_role_on_team)))
|
||||
|
||||
action
|
||||
end
|
||||
|
||||
it 'adds activity in DB' do
|
||||
expect { action }
|
||||
.to(change { Activity.count })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue