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" %> + +

Github Update Access Token

+<% if GithubIntegration.connected %> + <%= form_with url: github_token_user_path do |form| %> +
+ <%= form.text_field :access_token, required: true %> + <%= form.label :access_token, "Access Token" %> + Helpful description here +
+ <%= form.submit "Update Token", { class: "btn primary" } %> + <% end %> +<% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index c9d20bf76..5599e05cd 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -62,6 +62,7 @@ <% end %> <% if GithubIntegration.connected %> +

Github Settings

<% if @user.github_integration && @user.github_integration.is_connected %> <%= link_to github_revoke_user_path(@user), data: { method: "post" } do %> @@ -75,6 +76,12 @@ <% end %> <% end %> + + <%= link_to github_token_user_path(@user) do %> + + Use Personal access Token + + <% end %> <% end %>

API Settings

<%= link_to device_flow_activation_path do %> diff --git a/config/routes.rb b/config/routes.rb index f77d186d3..9d2cc64fe 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -79,6 +79,8 @@ get "lti_launch_initialize", on: :member post "lti_launch_link_course", on: :member post "github_revoke", on: :member + get "github_token", on: :member, to: 'users#show_github_token_form' + post 'github_token', on: :member, to: 'users#submit_github_token_form' get "github_oauth_callback", on: :collection match "update_password_for_user", on: :member, via: [:get, :put] post "change_password_for_user", on: :member