Skip to content

Commit

Permalink
pass generated auth key to features
Browse files Browse the repository at this point in the history
  • Loading branch information
jtomchak committed Dec 4, 2023
1 parent 6132957 commit 5b032c2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/controllers/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ def require_user!
# Mammoth client encoded JWT is required as Authorized Bearer header
def require_mammoth!
header = request.headers['Authorization']
header = header.split.last if header
raise InvalidPayload unless header
@auth_header_key = header.split.last if header
raise InvalidPayload unless @auth_header_key

@decoded = JsonToken.decode(header)
@decoded = JsonToken.decode(@auth_header_key)
end

def render_empty
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v4/timelines/for_you_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Api::V4::Timelines::ForYouController < Api::BaseController
# Return Mammoth User Profile w/ foryou settings
# api/v4/foryou/users/me/:acct
def index
result = PersonalForYou.new.mammoth_user_profile(acct_param)
result = PersonalForYou.new.mammoth_user_profile(acct_param, @auth_header_key)
render json: result
end

Expand Down
8 changes: 4 additions & 4 deletions app/lib/personal_for_you.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ def acct_relay_users
# and check for enrollment.
# for_you_setting type can be 'public' | 'personal' | 'waitlist'
# If Overload is enabled set status to 'overloaded'
def mammoth_user_profile(acct)
def mammoth_user_profile(acct, auth_header_key)
user = user(acct)
# Mammoth Overload Check set if overload is enabled
user[:for_you_settings][:status] = 'overloaded' if MAMMOTH_OVERLOAD_ENABLE
return user unless user[:for_you_settings][:type] == 'public'

# if for_you is public get the waitlist
waitlist = waitlist_status(acct)
waitlist = waitlist_status(acct, auth_header_key)
user[:for_you_settings][:type] = 'waitlist' if waitlist == 'enrolled'
user
end
Expand Down Expand Up @@ -97,8 +97,8 @@ def user(acct)

# Get User Waitlist Status
# :waitlist will be 'none' | 'enrolled'
def waitlist_status(acct)
response = HTTP.headers({ Authorization: ACCOUNT_RELAY_AUTH, 'Content-Type': 'application/json' }).get(
def waitlist_status(acct, auth_header_key)
response = HTTP.headers({ Authorization: "Bearer #{auth_header_key}", 'Content-Type': 'application/json' }).get(
"https://#{FEATURE_HOST}/api/v1/personalize?acct=#{acct}"
)
JSON.parse(response.body, symbolize_names: true)[:waitlist]
Expand Down

0 comments on commit 5b032c2

Please sign in to comment.