generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fworks): simple register import and audit
- Loading branch information
Showing
91 changed files
with
2,000 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.activity-log-table { | ||
@extend .govuk-\!-font-size-16; | ||
|
||
table { | ||
@extend .govuk-\!-font-size-16; | ||
} | ||
|
||
.activity-log-date { | ||
width: 180px; | ||
} | ||
.activity-log-person { | ||
width: 180px; | ||
} | ||
|
||
.activity-log-change-arrow { | ||
color: #a2a2a2; | ||
margin-left: 5px; | ||
margin-right: 5px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class Frameworks::FrameworksController < Frameworks::ApplicationController | ||
before_action :redirect_to_register_tab, unless: :turbo_frame_request?, only: :index | ||
before_action :set_back_url, only: %i[new show] | ||
|
||
def new; end | ||
|
||
def index | ||
@filtering = Frameworks::Framework.filtering(filter_form_params) | ||
@frameworks = @filtering.results.paginate(page: params[:frameworks_page]) | ||
end | ||
|
||
def show | ||
@framework = Frameworks::Framework.find(params[:id]) | ||
@activity_log_items = @framework.activity_log_items.paginate(page: params[:activities_page]) | ||
end | ||
|
||
private | ||
|
||
def filter_form_params | ||
params.fetch(:frameworks_filter, {}).permit( | ||
:sort_by, :sort_order, | ||
status: [], provider: [], | ||
e_and_o_lead: [], proc_ops_lead: [], | ||
category: [], provider_contact: [] | ||
) | ||
end | ||
|
||
def set_back_url | ||
@back_url = back_link_param | ||
end | ||
|
||
def redirect_to_register_tab | ||
redirect_to frameworks_root_path(anchor: "frameworks-register", **request.params.except(:controller, :action)) | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
app/controllers/frameworks/management/activity_logs_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Frameworks::Management::ActivityLogsController < Frameworks::Management::ApplicationController | ||
before_action { @back_url = frameworks_management_path } | ||
|
||
def show | ||
@activity_log_items = Frameworks::ActivityLogItem.paginate(page: params[:page], per_page: 50) | ||
end | ||
|
||
private | ||
|
||
def authorize_agent_scope = [super, :manage_frameworks_activity_log?] | ||
end |
5 changes: 5 additions & 0 deletions
5
app/controllers/frameworks/management/application_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Frameworks::Management::ApplicationController < Frameworks::ApplicationController | ||
private | ||
|
||
def authorize_agent_scope = [super, :access_admin_settings?] | ||
end |
3 changes: 3 additions & 0 deletions
3
app/controllers/frameworks/management/management_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Frameworks::Management::ManagementController < Frameworks::Management::ApplicationController | ||
def index; end | ||
end |
19 changes: 19 additions & 0 deletions
19
app/controllers/frameworks/management/register_uploads_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Frameworks::Management::RegisterUploadsController < Frameworks::Management::ApplicationController | ||
before_action { @back_url = frameworks_management_path } | ||
|
||
def new; end | ||
|
||
def create | ||
Frameworks::Framework.import_from_spreadsheet(register_upload_params[:spreadsheet]) | ||
|
||
redirect_to frameworks_management_path | ||
end | ||
|
||
private | ||
|
||
def register_upload_params | ||
params.require(:register_upload).permit(:spreadsheet) | ||
end | ||
|
||
def authorize_agent_scope = [super, :manage_frameworks_register_upload?] | ||
end |
45 changes: 45 additions & 0 deletions
45
app/controllers/frameworks/provider_contacts_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class Frameworks::ProviderContactsController < Frameworks::ApplicationController | ||
before_action :redirect_to_register_tab, unless: :turbo_frame_request?, only: :index | ||
before_action :set_back_url, only: %i[show edit] | ||
|
||
def index | ||
@filtering = Frameworks::ProviderContact.filtering(filter_form_params) | ||
@provider_contacts = @filtering.results.paginate(page: params[:provider_contacts_page]) | ||
end | ||
|
||
def show | ||
@provider_contact = Frameworks::ProviderContact.find(params[:id]) | ||
end | ||
|
||
def edit | ||
@provider_contact = Frameworks::ProviderContact.find(params[:id]) | ||
end | ||
|
||
def update | ||
@provider_contact = Frameworks::ProviderContact.find(params[:id]) | ||
|
||
if @provider_contact.update(provider_contact_params) | ||
redirect_to frameworks_provider_contact_path(@provider_contact) | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_back_url | ||
@back_url = back_link_param | ||
end | ||
|
||
def filter_form_params | ||
params.fetch(:provider_contacts_filter, {}).permit(:sort_by, :sort_order, provider: []) | ||
end | ||
|
||
def provider_contact_params | ||
params.require(:frameworks_provider_contact).permit(:name, :email, :phone) | ||
end | ||
|
||
def redirect_to_register_tab | ||
redirect_to frameworks_root_path(anchor: "provider-contacts", **request.params.except(:controller, :action)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
class Current < ActiveSupport::CurrentAttributes | ||
attribute :user, :agent | ||
attribute :user, :agent, :actor, :request_id | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Frameworks::Activity | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
has_one :activity_log_item, as: :activity, touch: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Frameworks::ActivityLogItem < ApplicationRecord | ||
include Presentable | ||
|
||
belongs_to :actor, polymorphic: true, optional: true | ||
belongs_to :subject, polymorphic: true, optional: true | ||
delegated_type :activity, types: %w[Frameworks::ActivityLoggableVersion] | ||
|
||
before_create do | ||
self.guid ||= Current.request_id | ||
self.actor ||= Current.actor | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Frameworks::ActivityLogItem::Presentable | ||
extend ActiveSupport::Concern | ||
|
||
def display_created_at | ||
created_at.strftime("%d/%m/%Y %H:%M:%S") | ||
end | ||
|
||
def display_actor | ||
actor.try(:full_name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Frameworks::ActivityLoggable | ||
extend ActiveSupport::Concern | ||
include ActivityLogPresentable | ||
|
||
included do | ||
has_paper_trail versions: { class_name: "Frameworks::ActivityLoggableVersion" } | ||
|
||
has_many :activity_log_items, as: :subject | ||
|
||
after_create :log_latest_version_in_activity_log | ||
after_update :log_latest_version_in_activity_log | ||
end | ||
|
||
private | ||
|
||
def log_latest_version_in_activity_log | ||
Frameworks::ActivityLogItem.create!(subject: self, activity: versions.last, activity_type: "Frameworks::ActivityLoggableVersion") | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
app/models/frameworks/activity_loggable/activity_log_presentable.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Frameworks::ActivityLoggable::ActivityLogPresentable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
delegate :version_at, to: :paper_trail | ||
end | ||
|
||
def activity_log_display_name | ||
try(:full_name) || try(:short_name) || try(:name) | ||
end | ||
|
||
def activity_log_display_type | ||
self.class.to_s.demodulize.underscore.humanize | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Frameworks::ActivityLoggableVersion < PaperTrail::Version | ||
include Presentable | ||
|
||
def item_association_at_version_or_current(association:, id:, version_at: created_at) | ||
current_version_of_association = item.class.reflections[association].klass.find_by(id:) | ||
current_version_of_association.try(:version_at, version_at).presence || current_version_of_association | ||
end | ||
end |
Oops, something went wrong.