From 784379d8887549df170651c81a10c6e9bd361195 Mon Sep 17 00:00:00 2001 From: Brandon Franzke <25210059+b-grablabs@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:03:18 -0800 Subject: [PATCH] Add button to set Github token (for instance, to Fine-Grained personal access token) --- app/controllers/users_controller.rb | 26 ++++++++++++++++++++++++-- app/views/users/github_token.erb | 13 +++++++++++++ app/views/users/show.html.erb | 7 +++++++ config/routes.rb | 2 ++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100755 app/views/users/github_token.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e187c5409..af3538113 100755 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,8 +5,9 @@ class UsersController < ApplicationController skip_before_action :update_persistent_announcements before_action :set_gh_oauth_client, only: [:github_oauth, :github_oauth_callback] before_action :set_user, - only: [:github_oauth, :github_revoke, :lti_launch_initialize, - :lti_launch_link_course] + only: [:github_oauth, :github_revoke, + :show_github_token_form, :submit_github_token_form, + :lti_launch_initialize, :lti_launch_link_course] # GET /users action_auth_level :index, :student @@ -250,6 +251,27 @@ def lti_launch_link_course redirect_to(course) end + action_auth_level :github_token, :student + def show_github_token_form + @github_integration = GithubIntegration.find_by(user_id: @user.id) + render('github_token') + end + + action_auth_level :github_token_form, :student + def submit_github_token_form + github_integration = GithubIntegration.find_by(user_id: @user.id) + access_token = params[:access_token] + + if github_integration.nil? + github_integration = GithubIntegration.create!(access_token:, user: @user) + else + github_integration.update!(access_token:) + end + + flash[:success] = "Updated Github Token" + redirect_to(user_path) + end + action_auth_level :github_oauth, :student def github_oauth github_integration = GithubIntegration.find_by(user_id: @user.id) diff --git a/app/views/users/github_token.erb b/app/views/users/github_token.erb new file mode 100755 index 000000000..3864b6b4c --- /dev/null +++ b/app/views/users/github_token.erb @@ -0,0 +1,13 @@ +<% @title = "Github Access Token" %> + +