app/controllers/extensions_controller.rb
# Attempts to authorize the GitHub user who corresponds to the given GitHub token
# as having GitHub collaborator permissions for the given +Extension+ object.
#
# If the authorization succeeds, this method calls the given code block.
#
# Returns an HTTP status code symbol representing the success or failure of the authorization.
#
Attempts to authorize the GitHub user who corresponds to the given GitHub token
as having GitHub collaborator permissions for the given +Extension+ object.

If the authorization succeeds, this method calls the given code block.

Returns an HTTP status code symbol representing the success or failure of the authorization.
Attempts to authorize the GitHub user who corresponds to the given GitHub token as having GitHub collaborator permissions for the given + Extension + object . If the authorization succeeds this method calls the given code block . Returns an HTTP status code symbol representing the success or failure of the authorization .
def with_collaborator_authorization(github_token, extension, &block)
    return :unknown      unless extension
    return :unauthorized unless github_token.present?
    repo_name = extension.github_repo
    return :unknown unless repo_name.present?
    github_client = Octokit::Client.new(access_token: github_token)
    github_login_name = begin
                          github_client.user.login
                        rescue Octokit::Unauthorized
                          return :unauthorized
                        rescue
                          nil
                        end
    return :not_found unless github_login_name.present?
    is_collaborator = github_client.collaborator?(repo_name, github_login_name) rescue false
    return :forbidden unless is_collaborator
    block.call
    return :ok
  end
def with_collaborator_authorization ( github_token , extension , & block ) return :unknown unless extension return :unauthorized unless github_token . present? repo_name = extension . github_repo return :unknown unless repo_name . present? github_client = Octokit :: Client . new ( access_token : github_token ) github_login_name = begin github_client . user . login rescue Octokit :: Unauthorized return :unauthorized rescue nil end return :not_found unless github_login_name . present? is_collaborator = github_client . collaborator? ( repo_name , github_login_name ) rescue false return :forbidden unless is_collaborator block . call return :ok end
Attempts to authorize the GitHub user who corresponds to the given GitHub token
as having GitHub collaborator permissions for the given +Extension+ object.
Attempts to authorize the GitHub user who corresponds to the given GitHub token as having GitHub collaborator permissions for the given + Extension + object .
# The GitHub user corresponding to the auth token must be a collaborator on the GitHub repo. # If this point is reached, we can call the given code block.
github_token
<not_specific>
extension
<not_specific>
block
<not_specific>