Skip to content

Commit

Permalink
add current object
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangplus committed Sep 7, 2024
1 parent aea0dde commit b63c866
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
class ApplicationController < ActionController::Base
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern

before_action :set_current

private
def set_current
Current.user_agent = request.user_agent
Current.ip_address = request.ip
Current.session = Profile.find_by_id(cookies.signed[:profile_id])
end
end
4 changes: 4 additions & 0 deletions app/models/current.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Current < ActiveSupport::CurrentAttributes
attribute :session
attribute :user_agent, :ip_address
end
2 changes: 1 addition & 1 deletion app/policies/badge_class_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def manage?
end

def send?
if @badge_class.group_id && @badge_class.permissions.include?("group_member_send")
if @badge_class.group_id && @badge_class.permissions["group_member_send"]
@badge_class.group.is_member(@profile.id)
elsif @badge_class.group_id
@badge_class.group.is_manager(@profile.id)
Expand Down

0 comments on commit b63c866

Please sign in to comment.