Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ?teach parameter to see instructor version of homepage regardless of user role (#5812) #5983

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/assets/javascripts/actions/training_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const setSlideCompletedPromise = async (opts) => {
const params = {
module_id: opts.module_id,
user_id: opts.user_id,
slide_id: opts.slide_id
slide_id: opts.slide_id,
library_id: opts.library_id
};
const response = await request(`/training_modules_users.json?${stringify(params)}`, {
method: 'POST'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ const TrainingSlideHandler = () => {
dispatch(setSlideCompleted({
slide_id: slideId,
module_id: moduleId(routeParams),
user_id: userId
user_id: userId,
library_id: routeParams.library_id
}));
};

Expand Down
1 change: 1 addition & 0 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def index
set_admin_courses_if_admin
@pres = DashboardPresenter.new(current_courses, past_courses,
@submitted, @strictly_current, current_user)
@instructor_view = params.key?(:teach) and user_signed_in?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the better way to handle this is inside the DashboardPresenter, by passing the 'teach' parameter to the presenter.

Using a separate instance variable makes it more complicated to get all the correct behaviors (such as showing the link to instructor orientation but not the create course button, if the user has not already completed that training module). With the presenter approach, I think there will be no changes needed in the view templates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will make the required changes. Thank you for the review

end

def my_account
Expand Down
33 changes: 33 additions & 0 deletions app/controllers/training_modules_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def create_or_update
return if @slide.nil?
complete_slide if should_set_slide_completed?
complete_module if last_slide?
make_training_module_user_instructor if instructor_training_complete?
@completed = @training_module_user.completed_at.present?
render_slide
end
Expand All @@ -31,6 +32,38 @@ def mark_exercise_complete

private

def instructor_training_complete?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature should not be in the same PR. I'd prefer to first merge the simplest possible version that will address the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

return false unless params[:library_id] == 'instructors' && last_slide?

library = TrainingLibrary.find_by(slug: params[:library_id])
return false unless library

library.categories.all? do |category|
category_modules_complete?(category)
end
end

def category_modules_complete?(category)
category['modules'].all? do |mod|
module_complete?(mod)
end
end

def module_complete?(mod)
training_module = TrainingModule.find_by(slug: mod['slug'])
return false unless training_module

progress_manager = ::TrainingProgressManager.new(current_user, training_module)
progress_manager.assignment_status == 'Completed'
end

def make_training_module_user_instructor
# Do not downgrade admins' permissions.
return if @training_module_user.user.admin?

@training_module_user.user.update(permissions: User::Permissions::INSTRUCTOR)
end

def set_training_module
@training_module = TrainingModule.find_by(slug: params[:module_id])
end
Expand Down
8 changes: 4 additions & 4 deletions app/views/dashboard/_course_creation.html.haml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
- if @pres.can_create_course?
= link_to course_creator_path, class: 'button dark dashboard-cta' do
- if @pres.can_create_course? || @instructor_view
= link_to course_creator_path, class: 'button dark dashboard-cta', style: 'margin-right: 10px;' do
= t("courses.creator.create_short")
%i.icon.icon-plus
- elsif @pres.show_explore_button?
= link_to explore_path, class: 'button dark dashboard-cta' do
= t("courses.creator.find")
%span.icon.icon-rt_arrow

- if @pres.show_orientation_review?
- if @pres.show_orientation_review? || @instructor_view
= link_to @pres.orientation_path, class: 'button' do
= t("dashboard.review_orientation")
%i.icon.icon-rt_arrow_dark
%i.icon.icon-rt_arrow_dark{ style: 'background-position: 0px 11px'}
2 changes: 1 addition & 1 deletion app/views/dashboard/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

- # Empty courses state
- if @pres.current.empty? && @pres.past.empty?
- if @pres.can_create_course? && !Features.open_course_creation?
- if (@pres.can_create_course? && !Features.open_course_creation?) || @instructor_view
%div.empty-state
%p
= t("dashboard.no_courses_instructor")
Expand Down
Loading