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

Feature/GitHub personal access token set #2060

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

brandonfranzke
Copy link

Add minimal (PoC) "update github" token with text field. Allow user/student to manually enter an override AFTER the OAuth flow completes. Useful for user controlled access tokens, potentially at a "per assignment" level.

Summary

New button on user page (if Github integaration): "update github token". Single field form. Overwrite (ActiveRecord encrpting) existing token. These appear to be universal across the API and do nor require individual attention.

Incomplete tests. I am teaching an overload this term and already behind. Not able to build out the spec for the submission. Happy to assist others but I cannot be lead.

Copy link
Contributor

coderabbitai bot commented Jan 25, 2024

Walkthrough

Walkthrough

The recent updates to the application focus on enhancing GitHub integration by allowing users to update their GitHub access tokens through new actions in the UsersController. The Dockerfile has been adjusted to change the server's time zone and user permissions. The Rails application's environment has been tweaked, and the assets precompilation list now includes a new CSS file. Additionally, the routing has been updated to support the new GitHub token update functionality.

Changes

File(s) Change Summary
Dockerfile Time zone changed to America/Los_Angeles; modified user permissions and environment variable for Rails.
.../users_controller.rb Added actions for GitHub integration: show_github_update_form and submit_github_update_form; updated before_action for set_user.
.../github_update.erb, .../show.html.erb Added GitHub update form and link to update GitHub token in user views.
.../assets.rb Included bootstrap-datetimepicker.css in the precompilation list; added newline.
.../routes.rb Added routes for GitHub update feature (GET and POST endpoints).
.../assessment_autograde_core.rb Indentation change in extend_config_module function, no logic change.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@reviewpad reviewpad bot requested a review from KesterTan January 25, 2024 11:25
@reviewpad reviewpad bot added small Pull request is small waiting-for-review labels Jan 25, 2024
@brandonfranzke
Copy link
Author

I have a fork with updates to the Dockerfile. Did not intend to commit those, only updates in /app and to routes.

I am going to close this with comment in case there is discussion and prepare a better merge source for the weekend.

Comment on lines +1 to +13
<% @title = "Github Access Token" %>

<h2>Github Update Access Token</h2>
<% if @github_integration %>
<%= form_with url: github_update_user_path do |form| %>
<div class="input-field">
<%= form.text_field :access_token, required: true %>
<%= form.label :access_token, "Access Token" %>
<span class="helper-text">Helpful description here</span>
</div>
<%= form.submit "Update Token", { class: "btn primary" } %>
<% end %>
<% end %>
Copy link
Contributor

Choose a reason for hiding this comment

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

The view template for updating the GitHub access token is straightforward and seems to follow Rails conventions. However, there is a placeholder text "Helpful description here" which should be replaced with an actual description to guide the user.

- <span class="helper-text">Helpful description here</span>
+ <span class="helper-text">Enter your GitHub personal access token.</span>

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
<% @title = "Github Access Token" %>
<h2>Github Update Access Token</h2>
<% if @github_integration %>
<%= form_with url: github_update_user_path do |form| %>
<div class="input-field">
<%= form.text_field :access_token, required: true %>
<%= form.label :access_token, "Access Token" %>
<span class="helper-text">Helpful description here</span>
</div>
<%= form.submit "Update Token", { class: "btn primary" } %>
<% end %>
<% end %>
<% @title = "Github Access Token" %>
<h2>Github Update Access Token</h2>
<% if @github_integration %>
<%= form_with url: github_update_user_path do |form| %>
<div class="input-field">
<%= form.text_field :access_token, required: true %>
<%= form.label :access_token, "Access Token" %>
<span class="helper-text">Enter your GitHub personal access token.</span>
</div>
<%= form.submit "Update Token", { class: "btn primary" } %>
<% end %>
<% end %>


# precompile the Rails assets
ENV SECRET_KEY_BASE=dummy_secret_key_base
RUN RAILS_ENV=production bundle exec rails assets:precompile
ENV SECRET_KEY_BASE="ekz0nrn_DPG6ucv5ukw"
Copy link
Contributor

Choose a reason for hiding this comment

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

The SECRET_KEY_BASE environment variable has been hardcoded into the Dockerfile. This is a security risk as it exposes the secret key in the Docker image and thus to anyone who can access the image.

- ENV SECRET_KEY_BASE="ekz0nrn_DPG6ucv5ukw"
+ ENV SECRET_KEY_BASE=${SECRET_KEY_BASE}

And ensure that the SECRET_KEY_BASE is passed as a build argument or environment variable at runtime.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
ENV SECRET_KEY_BASE="ekz0nrn_DPG6ucv5ukw"
ENV SECRET_KEY_BASE=${SECRET_KEY_BASE}

Comment on lines +254 to +268
action_auth_level :github_update, :student
def show_github_update_form
@github_integration = GithubIntegration.find_by(user_id: @user.id)
render('github_update')
end

action_auth_level :github_update_form, :student
def submit_github_update_form
github_integration = GithubIntegration.find_by(user_id: @user.id)

access_token = params[:access_token]
github_integration.update!(access_token:)
flash[:success] = "Updated Github Token"
redirect_to(user_path)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

The new actions show_github_update_form and submit_github_update_form have been added with appropriate authorization levels. However, there is no error handling for the case where GithubIntegration.find_by(user_id: @user.id) returns nil, which could lead to a NoMethodError when calling update! on nil.

- github_integration.update!(access_token:)
+ if github_integration
+   github_integration.update!(access_token:)
+   flash[:success] = "Updated Github Token"
+ else
+   flash[:error] = "GitHub integration not found."
+ end

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
action_auth_level :github_update, :student
def show_github_update_form
@github_integration = GithubIntegration.find_by(user_id: @user.id)
render('github_update')
end
action_auth_level :github_update_form, :student
def submit_github_update_form
github_integration = GithubIntegration.find_by(user_id: @user.id)
access_token = params[:access_token]
github_integration.update!(access_token:)
flash[:success] = "Updated Github Token"
redirect_to(user_path)
end
action_auth_level :github_update, :student
def show_github_update_form
@github_integration = GithubIntegration.find_by(user_id: @user.id)
render('github_update')
end
action_auth_level :github_update_form, :student
def submit_github_update_form
github_integration = GithubIntegration.find_by(user_id: @user.id)
access_token = params[:access_token]
if github_integration
github_integration.update!(access_token:)
flash[:success] = "Updated Github Token"
else
flash[:error] = "GitHub integration not found."
end
redirect_to(user_path)
end

@damianhxy
Copy link
Member

Does #2061 supersede this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants