-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api - api keys + fix dates in scheduler + change organization to bill…
…_organization
- Loading branch information
Showing
55 changed files
with
1,160 additions
and
775 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
3.3.6 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -570,7 +570,7 @@ DEPENDENCIES | |
webauthn | ||
|
||
RUBY VERSION | ||
ruby 3.3.6p108 | ||
ruby 3.4.1p0 | ||
|
||
BUNDLED WITH | ||
2.5.23 | ||
2.6.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class ApiKeysController < ApplicationController | ||
# include ApiKeyAuthenticatable | ||
# Require API key authentication | ||
# prepend_before_action :authenticate_with_api_key!, only: %i[index destroy] | ||
|
||
def index | ||
render_component(Pages::API_KEYS, { | ||
apiKeys: current_user.api_keys | ||
}) | ||
end | ||
|
||
def create | ||
if current_user.api_keys.blank? | ||
api_key = current_user.api_keys.create! token: SecureRandom.hex | ||
flash[:notice] = "API Key Created!" | ||
|
||
render json: { | ||
**api_key.attributes, | ||
token: api_key.token | ||
}, status: :ok | ||
else | ||
flash[:alert] = "You may only have 1 API Key." | ||
route_component(api_keys_path) | ||
end | ||
end | ||
|
||
def update | ||
current_user.api_keys.find_by(id: params[:id])&.update!(update_params) | ||
flash[:notice] = "API Key Name Updated" | ||
route_component(api_keys_path) | ||
end | ||
|
||
def destroy | ||
current_user.api_keys.find_by(id: params[:id])&.destroy | ||
flash[:notice] = "API Key Deleted!" | ||
route_component(api_keys_path) | ||
end | ||
|
||
private | ||
|
||
def update_params | ||
params.require(:api_keys_update_params).permit(:name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# typed: true | ||
|
||
module ApiKeyAuthenticatable | ||
extend ActiveSupport::Concern | ||
extend T::Sig | ||
|
||
include ActionController::HttpAuthentication::Basic::ControllerMethods | ||
include ActionController::HttpAuthentication::Token::ControllerMethods | ||
|
||
attr_reader :current_api_key | ||
attr_reader :current_bearer | ||
|
||
# Use this to raise an error and automatically respond with a 401 HTTP status | ||
# code when API key authentication fails | ||
def authenticate_with_api_key! | ||
@current_bearer = authenticate_or_request_with_http_token(&method(:authenticator)) | ||
end | ||
|
||
# Use this for optional API key authentication | ||
def authenticate_with_api_key | ||
@current_bearer = authenticate_with_http_token(&method(:authenticator)) | ||
end | ||
|
||
private | ||
|
||
attr_writer :current_api_key | ||
attr_writer :current_bearer | ||
|
||
def authenticator(http_token, options) | ||
@current_api_key = ApiKey.find_by(token: http_token) | ||
@current_api_key = ApiKey.authenticate_by_token(http_token) | ||
|
||
@current_api_key.update(last_used_on_utc: Time.zone.now) | ||
|
||
current_api_key&.bearer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
module Pages | ||
HOME = "Home" | ||
LEGISLATORS = "Legislators" | ||
REGISTRATION = "Registration" | ||
API_KEYS = "ApiKeys" | ||
BILL = "Bill" | ||
BILLS = "Bills" | ||
BILL_OF_THE_WEEK = "BillOfTheWeek" | ||
BILL_CREATOR = "BillOfTheWeekCreatorPage" | ||
BILL_OF_THE_WEEK = "BillOfTheWeek" | ||
HOME = "Home" | ||
INFLUENCE = "Influence" | ||
INVITE = "Invite" | ||
LEGISLATORS = "Legislators" | ||
NOTIFICATIONS = "Notifications" | ||
REGISTRATION = "Registration" | ||
end |
Oops, something went wrong.