Commit 4734c3a7 authored by Marin Jankovski's avatar Marin Jankovski

Create an audit events overview on the project settings page.

parent bcaf86da
......@@ -28,7 +28,24 @@ class Projects::TeamMembersController < Projects::ApplicationController
def update
@user_project_relation = @project.project_members.find_by(user_id: member)
@user_project_relation.update_attributes(member_params)
old_access_level = @user_project_relation.human_access
if @user_project_relation.update_attributes(member_params)
details = {
change: "access_level",
from: old_access_level,
to: @user_project_relation.human_access,
target_id: @user_project_relation.user_id,
target_type: "User",
target_details: @user_project_relation.user.name,
}
SecurityEvent.create(
author_id: current_user.id,
entity_id: @project.id,
entity_type: "Project",
details: details
)
end
unless @user_project_relation.valid?
flash[:alert] = "User should have at least one role"
......
module AuditEventsHelper
def human_text(details)
details.map{ |key, value| select_keys(key, value) }.join(" ").humanize
end
def select_keys(key, value)
if key.match(/^target_.*/)
""
else
"#{key.to_s} <strong>#{value}</strong>"
end
end
end
%h3.page-title Project Audit Events
%p.light Events in #{@project.path_with_namespace}
%table.table
%thead
%tr
%th
%th
%th Author
%th
%th
%th Action
%th
%th Target
%tbody
- @events.each do |event|
%tr
%td
%td
%td #{event.author_name}
%td
%td
%td #{raw human_text(event.details)}
%td
%td #{event.details['target_details']}
......@@ -31,3 +31,7 @@
= link_to project_protected_branches_path(@project) do
%i.fa.fa-lock
Protected branches
= nav_link(controller: :audit_events) do
= link_to project_audit_events_path(@project) do
%i.fa.fa-file-text-o
Audit Events
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment