From 1cbbd712fa2d332c39de88a0a32d440b17b9709e Mon Sep 17 00:00:00 2001 From: Christopher Detlef <> Date: Tue, 14 Nov 2023 23:55:51 -0500 Subject: [PATCH 1/3] APPEALS-34018 Create CDLever Controller and Routing --- app/models/case_distribution_lever.rb | 6 ------ .../controllers/case_distribution_levers_controller_spec.rb | 1 - 2 files changed, 7 deletions(-) diff --git a/app/models/case_distribution_lever.rb b/app/models/case_distribution_lever.rb index 1670f979e30..2497eb98058 100644 --- a/app/models/case_distribution_lever.rb +++ b/app/models/case_distribution_lever.rb @@ -8,10 +8,4 @@ class CaseDistributionLever < ApplicationRecord validates :is_disabled, inclusion: { in: [true, false] } self.table_name = "case_distribution_levers" - - def update_levers(lever_list) - lever_list.each do |updated_lever| - updated_lever.save! - end - end end diff --git a/spec/controllers/case_distribution_levers_controller_spec.rb b/spec/controllers/case_distribution_levers_controller_spec.rb index dc8dbaa6d1c..f7cd789e158 100644 --- a/spec/controllers/case_distribution_levers_controller_spec.rb +++ b/spec/controllers/case_distribution_levers_controller_spec.rb @@ -2,7 +2,6 @@ RSpec.describe CaseDistributionLeversController, :all_dbs, type: :controller do - let!(:admin_user) { User.authenticate!(roles: ["Admin"]) } let!(:lever_user) { create(:lever_user) } # //let!(:group_user) { User.authenticate!(roles: ["LeverGroupUser"]) } From ea9b14191bd80114d67ff908d8ccb9cc94d2e190 Mon Sep 17 00:00:00 2001 From: Christopher Detlef <> Date: Wed, 8 Nov 2023 14:34:53 -0500 Subject: [PATCH 2/3] Second draft --- app/models/case_distribution_lever.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/case_distribution_lever.rb b/app/models/case_distribution_lever.rb index 2497eb98058..1670f979e30 100644 --- a/app/models/case_distribution_lever.rb +++ b/app/models/case_distribution_lever.rb @@ -8,4 +8,10 @@ class CaseDistributionLever < ApplicationRecord validates :is_disabled, inclusion: { in: [true, false] } self.table_name = "case_distribution_levers" + + def update_levers(lever_list) + lever_list.each do |updated_lever| + updated_lever.save! + end + end end From 095fbae35316aa51e166a3a1e0318fccd744f4a3 Mon Sep 17 00:00:00 2001 From: Christopher Detlef <> Date: Thu, 16 Nov 2023 13:14:38 -0500 Subject: [PATCH 3/3] APPEALS-34018 Add alpha of Lever page and update controller spec --- .../case_distribution_levers_controller.rb | 6 +-- .../case_distribution_levers/index.html.erb | 8 ++-- client/app/caseflowDistribution/index.jsx | 28 +++++++++++ .../pages/CaseflowDistributionApp.jsx | 18 ++++--- client/app/index.js | 4 +- ...ase_distribution_levers_controller_spec.rb | 47 ++++++++++++++----- 6 files changed, 86 insertions(+), 25 deletions(-) create mode 100644 client/app/caseflowDistribution/index.jsx diff --git a/app/controllers/case_distribution_levers_controller.rb b/app/controllers/case_distribution_levers_controller.rb index 163477f3233..bdabe714145 100644 --- a/app/controllers/case_distribution_levers_controller.rb +++ b/app/controllers/case_distribution_levers_controller.rb @@ -2,8 +2,8 @@ class CaseDistributionLeversController < ApplicationController before_action :verify_access def acd_lever_index - @acd_levers = CaseDistributionLever.all.to_json - @acd_history = CaseDistributionAuditLeverEntry.past_year.to_json + @acd_levers = CaseDistributionLever.all + @acd_history = CaseDistributionAuditLeverEntry.past_year @user_is_an_acd_admin = current_user.admin? render "index" @@ -17,7 +17,7 @@ def update_levers_and_history end if errors.empty? - render json: { successful: true } + render json: { errors: [], successful: true } else render json: { errors: errors, successful: false } end diff --git a/app/views/case_distribution_levers/index.html.erb b/app/views/case_distribution_levers/index.html.erb index 07f0f311f5f..6b7cfed8079 100644 --- a/app/views/case_distribution_levers/index.html.erb +++ b/app/views/case_distribution_levers/index.html.erb @@ -1,6 +1,8 @@ <% content_for :full_page_content do %> - <%= react_component("CaseflowDistributionContent", props: { - param1: "here" + <%= react_component("CaseflowDistribution", props: { + acd_levers: @acd_levers, + acd_history: @acd_history, + user_is_an_acd_admin: @user_is_an_acd_admin }) %> <% end %> -HELLLOOOOO + diff --git a/client/app/caseflowDistribution/index.jsx b/client/app/caseflowDistribution/index.jsx new file mode 100644 index 00000000000..f6a99e5190b --- /dev/null +++ b/client/app/caseflowDistribution/index.jsx @@ -0,0 +1,28 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +import CaseflowDistributionContent from './pages/CaseflowDistributionApp'; + +class CaseflowDistribution extends React.PureComponent { + render() { + console.log("this.props:", this.props) + const {acd_levers, acd_history} = this.props + return ( +
+

Hello world from CaseflowDistribution index

+

Levers

+
{JSON.stringify(acd_levers)}
+
{JSON.stringify(acd_history)}
+
{JSON.stringify(acd_history)}
+
+ ) + } +} + +CaseflowDistribution.propTypes = { + acd_levers: PropTypes.array, + acd_history: PropTypes.array, + user_is_an_acd_admin: PropTypes.bool +} + +export default CaseflowDistribution; diff --git a/client/app/caseflowDistribution/pages/CaseflowDistributionApp.jsx b/client/app/caseflowDistribution/pages/CaseflowDistributionApp.jsx index 95e537ef11e..08e638df1d5 100644 --- a/client/app/caseflowDistribution/pages/CaseflowDistributionApp.jsx +++ b/client/app/caseflowDistribution/pages/CaseflowDistributionApp.jsx @@ -1,18 +1,24 @@ import React from 'react'; import PropTypes from 'prop-types'; -const CaseflowDistributionContent = ({param1}) => { - return ( +class CaseflowDistributionContent extends React.PureComponent { + render() {
{/*Wrapper*/} -

Hello World

+

Hello World From CaseflowDistributionContent

+ {this.props.acd_levers.map((lever) => { +
{lever.item}
+ })}
- ); -}; + + } +} CaseflowDistributionContent.propTypes = { - param1: PropTypes.any, + acd_levers: PropTypes.array, + acd_history: PropTypes.array, + user_is_an_acd_admin: PropTypes.bool }; export default CaseflowDistributionContent; diff --git a/client/app/index.js b/client/app/index.js index 52ce797e2db..04d28e7e18f 100644 --- a/client/app/index.js +++ b/client/app/index.js @@ -54,7 +54,7 @@ import Inbox from 'app/inbox'; import Explain from 'app/explain'; import MPISearch from 'app/mpi/MPISearch'; import Admin from 'app/admin'; -import CaseflowDistributionContent from 'app/caseflowDistribution' +import CaseflowDistribution from 'app/caseflowDistribution'; const COMPONENTS = { // New Version 2.0 Root Component @@ -89,7 +89,7 @@ const COMPONENTS = { Explain, MPISearch, Admin, - CaseflowDistributionContent + CaseflowDistribution }; const componentWrapper = (component) => (props, railsContext, domNodeId) => { diff --git a/spec/controllers/case_distribution_levers_controller_spec.rb b/spec/controllers/case_distribution_levers_controller_spec.rb index f7cd789e158..9d6cdfa0a94 100644 --- a/spec/controllers/case_distribution_levers_controller_spec.rb +++ b/spec/controllers/case_distribution_levers_controller_spec.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true - RSpec.describe CaseDistributionLeversController, :all_dbs, type: :controller do let!(:lever_user) { create(:lever_user) } - # //let!(:group_user) { User.authenticate!(roles: ["LeverGroupUser"]) } let!(:lever1) {create(:case_distribution_lever, item: "lever_1", @@ -40,16 +38,21 @@ update_value: 55, case_distribution_lever: lever2 )} + let!(:old_audit_lever_entry) {create(:case_distribution_audit_lever_entry, + user: lever_user, + user_name: "john smith", + created_at: "2020-07-01 10:11:01", + title: 'Lever 1', + previous_value: 42, + update_value: 55, + case_distribution_lever: lever2 + )} let!(:levers) {[lever1, lever2]} let!(:lever_history) {[audit_lever_entry1, audit_lever_entry2]} - before do - end - describe "GET acd_lever_index", :type => :request do it "redirects the user to the unauthorized page if they are not authorized" do - User.authenticate!(user: create(:user)) get "/acd-controls" @@ -57,20 +60,42 @@ expect(response.body).to match(/unauthorized/) end - it "renders a page with the correct levers when user is allowed to view the page" do + it "renders a page with the correct levers, lever history, and user admin status when user is allowed to view the page" do User.authenticate!(user: lever_user) get "/acd-controls" + request_levers = @controller.view_assigns["acd_levers"] + request_history = @controller.view_assigns["acd_history"] + request_user_is_an_admin = @controller.view_assigns["user_is_an_acd_admin"] + expect(response.status).to eq 200 - expect(response.body).to eq(2) + expect(request_levers.count).to eq(2) + expect(request_levers).to include(lever1) + expect(request_levers).to include(lever2) + expect(request_history.count).to eq(2) + expect(request_history).to include(audit_lever_entry1) + expect(request_history).to include(audit_lever_entry2) + expect(request_history).not_to include(old_audit_lever_entry) + expect(request_user_is_an_admin).to be_falsey end - it "renders a page with the correct levers when user is an admin" do - User.authenticate!(roles: ["Admin"]) + it "renders a page with the correct levers, lever history, and user admin status when user is an admin" do + User.authenticate!(roles: ["System Admin"]) get "/acd-controls" + request_levers = @controller.view_assigns["acd_levers"] + request_history = @controller.view_assigns["acd_history"] + request_user_is_an_admin = @controller.view_assigns["user_is_an_acd_admin"] + expect(response.status).to eq 200 - expect(user.roles).to eq(2) + expect(request_levers.count).to eq(2) + expect(request_levers).to include(lever1) + expect(request_levers).to include(lever2) + expect(request_history.count).to eq(2) + expect(request_history).to include(audit_lever_entry1) + expect(request_history).to include(audit_lever_entry2) + expect(request_history).not_to include(old_audit_lever_entry) + expect(request_user_is_an_admin).to be_truthy end end