Skip to content

Commit

Permalink
Merge pull request #2107 from NCCE/revert-2082-2791/ability-to-manage…
Browse files Browse the repository at this point in the history
…-course-enrolments-during-testing

Revert "Add ability to create achievements in non-prod for testing"
  • Loading branch information
msquance-stem authored Jul 31, 2024
2 parents adaf796 + 5ebea18 commit 2e11e4d
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 196 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.1.2"

gem "activestorage-validator"
gem "administrate", "~> 0.20.0"
gem "administrate-field-active_storage"
gem "administrate", "~> 0.18.0"
gem "administrate-field-active_storage", "~> 0.3.4"
gem "administrate-field-jsonb"
gem "administrate-field-nested_has_many"
gem "administrate-field-nested_has_many", "~> 1.3.0"
gem "attr_encrypted"
gem "audited"
gem "aws-sdk-s3", require: false
Expand Down
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ GEM
zeitwerk (~> 2.3)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
administrate (0.20.1)
actionpack (>= 6.0, < 8.0)
actionview (>= 6.0, < 8.0)
activerecord (>= 6.0, < 8.0)
jquery-rails (~> 4.6.0)
kaminari (~> 1.2.2)
administrate (0.18.0)
actionpack (>= 5.0)
actionview (>= 5.0)
activerecord (>= 5.0)
jquery-rails (>= 4.0)
kaminari (>= 1.0)
sassc-rails (~> 2.1)
selectize-rails (~> 0.6)
administrate-field-active_storage (0.3.8)
Expand Down Expand Up @@ -683,10 +683,10 @@ PLATFORMS

DEPENDENCIES
activestorage-validator
administrate (~> 0.20.0)
administrate-field-active_storage
administrate (~> 0.18.0)
administrate-field-active_storage (~> 0.3.4)
administrate-field-jsonb
administrate-field-nested_has_many
administrate-field-nested_has_many (~> 1.3.0)
attr_encrypted
audited
awesome_print
Expand Down
28 changes: 4 additions & 24 deletions app/controllers/admin/achievements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,10 @@ class AchievementsController < Admin::ApplicationController
# Overwrite any of the RESTful controller actions to implement custom behavior
# For example, you may want to send an email after a foo is updated.
#
def create
super do |resource|
update_state(resource)
end
end

def update
achievement = Achievement.find(params[:id])
if achievement.update(resource_params)
update_state(achievement)
end
end

def update_state(achievement)
if params[:achievement][:current_state]
achievement.transition_to(params[:achievement][:current_state])
end
completed_job_processing(achievement) if achievement.in_state?(:complete)
end

def completed_job_processing(achievement)
AssessmentEligibilityJob.perform_later(achievement.user.id)
CertificatePendingTransitionJob.perform_later(achievement.user)
end
# def update
# super
# send_foo_updated_email(requested_resource)
# end

def after_resource_destroyed_path(achievement)
{action: :show, controller: :users, id: achievement.user.id}
Expand Down
12 changes: 9 additions & 3 deletions app/dashboards/achievement_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ class AchievementDashboard < BaseDashboard
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
activity: GroupedActivityListField,
activity: Field::BelongsTo,
user: Field::BelongsTo,
supporting_evidence_attachment: Field::HasOne,
supporting_evidence_blob: Field::HasOne,
self_verification_info: Field::String,
current_state: ValidStatePickerField,
current_state: Field::String.with_options(searchable: false),
id: Field::String,
created_at: FORMATTED_DATE_TIME,
updated_at: FORMATTED_DATE_TIME,
Expand All @@ -33,6 +35,8 @@ class AchievementDashboard < BaseDashboard
SHOW_PAGE_ATTRIBUTES = %i[
user
activity
supporting_evidence_attachment
supporting_evidence_blob
self_verification_info
id
created_at
Expand All @@ -47,7 +51,9 @@ class AchievementDashboard < BaseDashboard
FORM_ATTRIBUTES = %i[
activity
user
current_state
supporting_evidence_attachment
supporting_evidence_blob
progress
].freeze

# COLLECTION_FILTERS
Expand Down
13 changes: 0 additions & 13 deletions app/fields/grouped_activity_list_field.rb

This file was deleted.

19 changes: 0 additions & 19 deletions app/fields/valid_state_picker_field.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/achievement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def self.transition_class

private_class_method :initial_state, :transition_class

delegate :allowed_transitions, :can_transition_to?, :current_state, :transition_to, :last_transition, :in_state?, to: :state_machine
delegate :can_transition_to?, :current_state, :transition_to, :last_transition, :in_state?, to: :state_machine
delegate :provider, :title, :stem_activity_code, :slug, :active_course?, to: :activity

def belonging_to_programme?(programme)
Expand Down
30 changes: 11 additions & 19 deletions app/views/admin/user_programme_enrolments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,16 @@ as well as a link to its edit page.

<section class="main-content__body">
<dl>
<% page.attributes.each do |title, attributes| %>
<fieldset class="<%= "field-unit--nested" if title.present? %>">
<% if title.present? %>
<legend><%= t "helpers.label.#{page.resource_name}.#{title}", default: title %></legend>
<% end %>
<% attributes.each do |attribute| %>
<dt class="attribute-label" id="<%= attribute.name %>">
<%= t(
"helpers.label.#{resource_name}.#{attribute.name}",
default: page.resource.class.human_attribute_name(attribute.name),
) %>
</dt>

<dd class="attribute-data attribute-data--<%=attribute.html_class%>"
><%= render_field attribute, page: page %></dd>
<% end %>
</fieldset>
<% page.attributes.each do |attribute| %>
<dt class="attribute-label" id="<%= attribute.name %>">
<%= t(
"helpers.label.#{resource_name}.#{attribute.name}",
default: page.resource.class.human_attribute_name(attribute.name),
) %>
</dt>

<dd class="attribute-data attribute-data--<%=attribute.html_class%>"
><%= render_field attribute, page: page %></dd>
<% end %>
</dl>
</section>
</section>
30 changes: 14 additions & 16 deletions app/views/admin/users/_actions.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<fieldset>
<dt class="attribute-label actions" id="actions"><%= t(".title") %></dt>
<dd class="attribute-data attribute-data--sync actions">
<%= link_to(
t(".sync.label"),
admin_user_perform_sync_path(user_id: resource.id),
class: "button"
) if accessible_action?(resource, :perform_sync) %>
<br/><br/>
<%= link_to(
t(".reset.label"),
admin_user_perform_reset_path(user_id: resource.id),
class: "button"
) if accessible_action?(resource, :perform_reset_tests) %>
</dd>
</fieldset>
<dt class="attribute-label actions" id="actions"><%= t(".title") %></dt>
<dd class="attribute-data attribute-data--sync actions">
<%= link_to(
t(".sync.label"),
admin_user_perform_sync_path(user_id: resource.id),
class: "button"
) if accessible_action?(resource, :perform_sync) %>
<br/><br/>
<%= link_to(
t(".reset.label"),
admin_user_perform_reset_path(user_id: resource.id),
class: "button"
) if accessible_action?(resource, :perform_reset_tests) %>
</dd>
28 changes: 10 additions & 18 deletions app/views/admin/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,16 @@ as well as a link to its edit page.
<section class="main-content__body">
<dl>
<%= render partial: 'actions', locals: { resource: page.resource } %>
<% page.attributes.each do |title, attributes| %>
<fieldset class="<%= "field-unit--nested" if title.present? %>">
<% if title.present? %>
<legend><%= t "helpers.label.#{page.resource_name}.#{title}", default: title %></legend>
<% end %>
<% attributes.each do |attribute| %>
<dt class="attribute-label" id="<%= attribute.name %>">
<%= t(
"helpers.label.#{resource_name}.#{attribute.name}",
default: page.resource.class.human_attribute_name(attribute.name),
) %>
</dt>

<dd class="attribute-data attribute-data--<%=attribute.html_class%>"
><%= render_field attribute, page: page %></dd>
<% end %>
</fieldset>
<% page.attributes.each do |attribute| %>
<dt class="attribute-label" id="<%= attribute.name %>">
<%= t(
"helpers.label.#{resource_name}.#{attribute.name}",
default: page.resource.class.human_attribute_name(attribute.name),
) %>
</dt>

<dd class="attribute-data attribute-data--<%=attribute.html_class%>"
><%= render_field attribute, page: page %></dd>
<% end %>
</dl>
</section>
6 changes: 0 additions & 6 deletions app/views/fields/grouped_activity_list_field/_form.html.erb

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions app/views/fields/valid_state_picker_field/_form.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/fields/valid_state_picker_field/_index.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/fields/valid_state_picker_field/_show.html.erb

This file was deleted.

3 changes: 1 addition & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
get :generate_certificate
end
end
achievement_actions = Rails.env.production? ? %i[index show] : %i[index show create new destroy update]
resources :achievements, only: achievement_actions do
resources :achievements, only: %i[index show] do
member do
post :reject_evidence
end
Expand Down
4 changes: 1 addition & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_06_26_160358) do
ActiveRecord::Schema.define(version: 2024_03_07_111123) do

# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
Expand Down Expand Up @@ -184,8 +184,6 @@
t.uuid "credly_badge_template_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.date "activation_date"
t.integer "trigger_type", default: 0
t.index ["programme_id"], name: "index_badges_on_programme_id"
end

Expand Down
50 changes: 0 additions & 50 deletions spec/requests/admin/achievements_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
RSpec.describe "Admin::AchievementsController" do
let(:user) { create(:user) }
let(:programme) { create(:programme) }
let!(:cs_accelerator) { create(:cs_accelerator) }
let(:other_programme) { create(:programme) }
let(:activity) { create(:activity, programmes: [programme, other_programme]) }
let(:other_activity) { create(:activity, programmes: [other_programme]) }
Expand Down Expand Up @@ -36,55 +35,6 @@
end
end

describe "POST #create" do
it "should create achievement" do
expect {
post admin_achievements_url(params: {
achievement: {
user_id: user.id,
activity_id: activity.id
}
})
}.to change(Achievement, :count).by(1)
end

it "should call jobs when set to complete" do
post admin_achievements_url(params: {
achievement: {
user_id: user.id,
activity_id: activity.id,
current_state: :complete
}
})
expect(AssessmentEligibilityJob).to have_been_enqueued
expect(CertificatePendingTransitionJob).to have_been_enqueued
end
end

describe "PATCH #update" do
it "should call jobs when updated to complete" do
patch admin_achievement_url(other_achievement, params: {
achievement: {
current_state: :complete
}
})
expect(AssessmentEligibilityJob).to have_been_enqueued
expect(CertificatePendingTransitionJob).to have_been_enqueued
end
end

describe "DELETE #achievement" do
before do
achievement
end

it "should delete achievement" do
expect {
delete admin_achievement_url(achievement)
}.to change(Achievement, :count).by(-1)
end
end

describe "POST #reject_evidence" do
before do
user_programme_enrolment
Expand Down

0 comments on commit 2e11e4d

Please sign in to comment.