From 04178b9b2ec2e62f7cfd0d20e785c08126fedcaf Mon Sep 17 00:00:00 2001 From: Antti Leinonen Date: Tue, 27 Jan 2026 17:40:14 +0200 Subject: [PATCH 1/2] Remove last of unused gdocs functionality --- app/controllers/points_controller.rb | 7 ------- app/models/ability.rb | 3 --- 2 files changed, 10 deletions(-) diff --git a/app/controllers/points_controller.rb b/app/controllers/points_controller.rb index bf98bfbeb..2d973091c 100644 --- a/app/controllers/points_controller.rb +++ b/app/controllers/points_controller.rb @@ -47,13 +47,6 @@ def index end end - def refresh_gdocs - authorize! :refresh, @course - @sheetname = params[:id] - @course = Course.find(params[:course_id]) - @notifications = @course.refresh_gdocs_worksheet @sheetname - end - def show @sheetname = params[:id] @course = Course.find(params[:course_id]) diff --git a/app/models/ability.rb b/app/models/ability.rb index 937a9ee47..fc0b89d28 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -20,9 +20,6 @@ def initialize(user) can :disable, Organization can :rerun, Submission - can :refresh_gdocs_spreadsheet, Course do |c| - c.spreadsheet_key.present? - end can :access, :pghero can :read_vm_log, Submission can :read, :instance_state From a0af56b554379333de5e5a653b9784be7ea66a34 Mon Sep 17 00:00:00 2001 From: Antti Leinonen Date: Wed, 11 Feb 2026 11:47:11 +0200 Subject: [PATCH 2/2] Post new users to courses and move password management --- app/controllers/api/v8/users_controller.rb | 6 +++ app/controllers/users_controller.rb | 6 +++ app/models/user.rb | 48 ++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/app/controllers/api/v8/users_controller.rb b/app/controllers/api/v8/users_controller.rb index 2dfc8f52f..ec5300e34 100644 --- a/app/controllers/api/v8/users_controller.rb +++ b/app/controllers/api/v8/users_controller.rb @@ -157,6 +157,12 @@ def create if @user.errors.empty? && @user.save # TODO: Whitelist origins UserMailer.email_confirmation(@user, params[:origin], params[:language]).deliver_now + + # Post the new user to courses.mooc.fi for password management + if params[:user][:password].present? + @user.post_new_user_to_courses_mooc_fi(params[:user][:password]) + end + render json: build_success_response(params[:include_id]) else errors = @user.errors diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f6490f2e9..e75b78c30 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -45,6 +45,12 @@ def create if @user.errors.empty? && @user.save UserMailer.email_confirmation(@user).deliver_now + + # Post the new user to courses.mooc.fi for password management + if params[:user][:password].present? + @user.post_new_user_to_courses_mooc_fi(params[:user][:password]) + end + if @bare_layout render plain: '
User account created.
', layout: true else diff --git a/app/models/user.rb b/app/models/user.rb index 70f2b05e1..b8dd17044 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -237,6 +237,54 @@ def update_password_via_courses_mooc_fi(old_password, new_password) end end + def post_new_user_to_courses_mooc_fi(password) + create_url = SiteSetting.value('courses_mooc_fi_create_user_url') + + conn = Faraday.new do |f| + f.request :json + f.response :json + end + + begin + response = conn.post(create_url) do |req| + req.headers['Content-Type'] = 'application/json' + req.headers['Accept'] = 'application/json' + req.headers['Authorization'] = Rails.application.secrets.tmc_server_secret_for_communicating_to_secret_project + + req.body = { + upstream_id: id, + password: password, + } + end + + data = response.body + + unless data.is_a?(Hash) && data['user'].present? + Rails.logger.error("Creating user in courses.mooc.fi returned unexpected response for user #{self.id}: #{data}") + raise "Creating user in courses.mooc.fi failed for user #{self.id}" + end + + unless data['password_set'] + Rails.logger.warn("Password was not set for user #{self.id} in courses.mooc.fi") + end + + Rails.logger.info("User #{self.id} successfully created in courses.mooc.fi") + true + + rescue Faraday::ClientError => e + Rails.logger.error( + "Creating user in courses.mooc.fi failed for user #{self.id}: #{e.response}" + ) + false + + rescue => e + Rails.logger.error( + "Unexpected error creating user in courses.mooc.fi for user #{self.id}: #{e.message}" + ) + false + end + end + def password_reset_key action_tokens.find { |t| t.action == 'reset_password' } end