app/helpers/usman/authentication_helper.rb in usman-0.4.4.pre.materialize vs app/helpers/usman/authentication_helper.rb in usman-0.4.5.pre.materialize

- old
+ new

@@ -96,10 +96,29 @@ # Check if the user exists with the auth token present in session @current_user = User.find_by_id(session[:id]) unless @current_user return @current_user end + def current_permissions + return @current_permissions unless @current_permissions.nil? + @current_permissions = @current_user.permissions.includes(:feature).all + end + + def current_feature + return @current_feature unless @current_feature.nil? + return if @resource_options.nil? + feature_name = @resource_options[:feature_name] || @resource_options[:class] + @current_feature = Feature.published.find_by_name(feature_name) + end + + + def current_permission + return @current_permission unless @current_permission.nil? + feature_id = current_feature ? current_feature.id : -1 + @current_permission = @current_user.permissions.where("feature_id = ?", feature_id).first + end + # This method is usually used as a before filter to secure some of the actions which requires the user to be signed in. def require_user current_user unless @current_user text = "#{I18n.t("authentication.login_required.heading")}" @@ -196,16 +215,9 @@ set_params_hsh render(:partial => 'usman/sessions/permission_denied.js.erb', :handlers => [:erb], :formats => [:js]) } end end - end - - def current_permission - feature_name = @resource_options[:feature_name] || @resource_options[:class] - @current_feature = Feature.published.find_by_name(feature_name) - feature_id = @current_feature ? @current_feature.id : -1 - @current_permission = @current_user.permissions.where("feature_id = ?", feature_id).first end # ------------------- # Masquerade Helpers # -------------------