diff --git a/app/assets/javascripts/actions/training_actions.js b/app/assets/javascripts/actions/training_actions.js index d2dcf28991..23290207e9 100644 --- a/app/assets/javascripts/actions/training_actions.js +++ b/app/assets/javascripts/actions/training_actions.js @@ -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' diff --git a/app/assets/javascripts/training/components/training_slide_handler.jsx b/app/assets/javascripts/training/components/training_slide_handler.jsx index e9e3a8e5fe..37ed6a69d0 100644 --- a/app/assets/javascripts/training/components/training_slide_handler.jsx +++ b/app/assets/javascripts/training/components/training_slide_handler.jsx @@ -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 })); }; diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 88faf8b3b8..a22607f547 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -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? end def my_account diff --git a/app/controllers/training_modules_users_controller.rb b/app/controllers/training_modules_users_controller.rb index 333f116082..3f4c5938f2 100644 --- a/app/controllers/training_modules_users_controller.rb +++ b/app/controllers/training_modules_users_controller.rb @@ -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 @@ -31,6 +32,38 @@ def mark_exercise_complete private + def instructor_training_complete? + 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 diff --git a/app/views/dashboard/_course_creation.html.haml b/app/views/dashboard/_course_creation.html.haml index 253e663062..e551ce2d23 100644 --- a/app/views/dashboard/_course_creation.html.haml +++ b/app/views/dashboard/_course_creation.html.haml @@ -1,5 +1,5 @@ -- 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? @@ -7,7 +7,7 @@ = 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'} diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboard/index.html.haml index d1eae126e3..a0efb25885 100644 --- a/app/views/dashboard/index.html.haml +++ b/app/views/dashboard/index.html.haml @@ -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")