Skip to content

Commit

Permalink
test de journalisation des modifications des droits des non membres d…
Browse files Browse the repository at this point in the history
…ans l'historique d'un projet
  • Loading branch information
Yalaeddin authored and nanego committed Sep 19, 2023
1 parent 62d13a4 commit b953b6d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/controllers/organizations/memberships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def update_group_non_member_roles
new_roles = Role.find(params[:membership][:role_ids].reject(&:empty?))
group = GroupBuiltin.find(params[:group_id])
membership = Member.where(user_id: group.id, project_id: @project.id).first_or_initialize
previous_role_ids = membership.roles.ids
previous_role_ids = membership.roles.ids
if new_roles.present?
membership.roles = new_roles
membership.save
Expand Down
56 changes: 35 additions & 21 deletions spec/controllers/memberships_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,49 @@

it "should delete all members from an organization except lock one" do

user1 = User.find(8)
user1.organization = Organization.find(1)
user1.save
user2 = User.find(2)
user2.organization = Organization.find(1)
user2.save
user1 = User.find(8)
user1.organization = Organization.find(1)
user1.save
user2 = User.find(2)
user2.organization = Organization.find(1)
user2.save

expect do
delete :destroy_organization, :params => {
:project_id => 5,
:id => 1
}
end.to change { Member.count }.by(-1)
expect do
delete :destroy_organization, :params => {
:project_id => 5,
:id => 1
}
end.to change { Member.count }.by(-1)

if Redmine::Plugin.installed?(:redmine_admin_activity)
journal_detail_count_after_delation = JournalDetail.count
if Redmine::Plugin.installed?(:redmine_admin_activity)
journal_detail_count_after_delation = JournalDetail.count

expect(journal_detail_count_after_delation) .to eq(journal_detail_count_before_delation + 2)
expect(journal_detail_count_after_delation) .to eq(journal_detail_count_before_delation + 2)


last_journal_for_delection_of_member = JournalDetail.last(2)[0]
user_name = JSON.parse(last_journal_for_delection_of_member.old_value)["name"]
last_journal_for_delection_of_member = JournalDetail.last(2)[0]
user_name = JSON.parse(last_journal_for_delection_of_member.old_value)["name"]

pro_key_value = Redmine::Plugin.installed?(:redmine_limited_visibility) ? 'member_roles_and_functions' : 'member_with_roles'
pro_key_value = Redmine::Plugin.installed?(:redmine_limited_visibility) ? 'member_roles_and_functions' : 'member_with_roles'

expect(last_journal_for_delection_of_member).to have_attributes(:prop_key => pro_key_value)
expect(user_name).to eq(user2.name)
end
expect(last_journal_for_delection_of_member).to have_attributes(:prop_key => pro_key_value)
expect(user_name).to eq(user2.name)
end
end

if Redmine::Plugin.installed?(:redmine_admin_activity)
it "add logs on JournalDetail when change non_member roles" do
expect do
patch :update_group_non_member_roles ,:params => {
:project_id => 5,
:membership => {:role_ids => ["2", "3"]},
:group_id => 12
}
end.to change { JournalDetail.count }.by (1)

expect(JournalDetail.last.property).to eq("members")
expect(JournalDetail.last.prop_key).to eq("member_roles_and_functions")
end
end
end
end

0 comments on commit b953b6d

Please sign in to comment.