cancan

ActiveAdmin with CanCanAdapter causing infinite redirect on dashboard

試著忘記壹切 提交于 2019-12-03 14:29:56
When using the CanCan adapter in ActiveAdmin 0.6.0. I have a resource working and authorization is working. However, when I go to /admin , the root ActiveAdmin page, it redirects to /admin and continues this forever. If the user does not have access to a page, ActiveAdmin redirects to the Dashboard. If the user doesn't have access to the dashboard, this results in an infinite redirect. Solution is to give the user the ability to read the dashboard page. Place this in the ability model object: can :read, ActiveAdmin::Page, :name => "Dashboard" This is mentioned in the authorization adapter

Allow anonymous/guest user to “try out” functionality without registering in Rails/Devise/CanCan app

扶醉桌前 提交于 2019-12-03 13:40:58
问题 I'm developing a Rails 3 app using Devise and CanCan. The app allows anonymous (not registered) users to access some of the app, and registered users to access other parts. One aspect of the app (a yoga workout app) is that users can create Yoga sequences by stringing together yoga poses, then they can play them back in a video player. I currently have all the functioning for registered users, but now want to allow anonymous users to be able to create a sequence, and play it back, but to

What is the best way to bypass devise authorization for a specific record marked public

爱⌒轻易说出口 提交于 2019-12-03 11:22:37
I'm using devise and cancan in a Rails 3.2 project. I have an event model with a boolean flag public . If the event is marked as public => true then I want anybody, signed in or not to be able to access the record with GET /events/:id If it is marked as public => false then a series of cancan abilities will decide authorization and access to the above resource. What is the best pattern for achieving this? shingara You can do that by skip the authenticate_user! in case of you have this args skip_before_filter :authenticate_user!, :only => :show, :if => lambda { if params[:id] @event = Event

CanCan load_and_authorize_resource triggers Forbidden Attributes

你离开我真会死。 提交于 2019-12-03 10:02:46
I have a standard RESTful controller that uses strong parameters. class UsersController < ApplicationController respond_to :html, :js def index @users = User.all end def show @user = User.find(params[:id]) end def new @user = User.new end def edit @user = User.find(params[:id]) end def create @user = User.new(safe_params) if @user.save redirect_to @user, notice: t('users.controller.create.success') else render :new end end def update @user = User.find(params[:id]) if @user.update_attributes(safe_params) redirect_to @user, notice: t('users.controller.update.success') else render :edit end end

Spree Custom Roles Permissions

為{幸葍}努か 提交于 2019-12-03 09:54:35
I am trying to give some custom roles within spree specific permissions. Cant find this answer anywhere role_ability.rb class RoleAbility include CanCan::Ability def initialize(user) user || User.new # for guest if user.has_role? "admin" can :manage, :all elsif user.has_role? "retailer" can :manage, Product else can :read, :all end end end I thought this might be a popular idea, of letting a user with role 'manager' manage only products and other certain Models... if I change elsif user.has_role? "retailer" can :manage, Product to elsif user.has_role? "retailer" can :manage, :all It works as

Why is Pundit not coupled with Rolify like CanCanCan is?

泄露秘密 提交于 2019-12-03 09:36:55
问题 I am using Devise and interested in using Pundit but cannot find much on if it should be integrating with Rolify or if it is stand alone. CanCanCan works nicely with Rolify and I like the roles model. Am I missing a major reason why Pundit and Rolify do not seem to be used together a lot? 回答1: Why don't use them together? They can be easily used in a fashion like this class OrganisationPolicy def initialize(user, organisation) @user = user @organisation = organisation end def index? @user.has

Devise + CanCan just prevent other users from editing objects

↘锁芯ラ 提交于 2019-12-03 08:37:18
How would you prevent other users from editing a object, say a profile object that does - not - belong to themselves? Most online examples are complexes with multiple user roles, i haven't been able to get this working, must be simple though: def initialize(user) can :update, Profile do |profile| profile.try(:user) == current_user end end And inside my ProfilesController#edit authorize! :update, @profile LearningRoR First question is, have you made your roles for the User ? app/models/user.rb class User < ActiveRecord::Base attr_accessible :email, :password, :remember_me devise :database

Context aware authorization using CanCan

元气小坏坏 提交于 2019-12-03 07:46:21
问题 I want to use CanCan to handle my permissions. My site has many different permissions levels, and most of them are context aware. For instance, Here are the relations in my 3 main models: class User < ActiveRecord::Base has_many :league_relations has_many :leagues, :through => :league_relations end class League < ActiveRecord::Base has_many :league_relations has_many :users, :through => :league_relations end class LeagueRelation < ActiveRecord::Base belongs_to :user belongs_to :league end

How to access 'can?' method from within cell?

ぃ、小莉子 提交于 2019-12-03 07:13:50
I'm using cancan and cells gems in my ruby-on-rails project. How to access can? method from within cell? Thanks. I've had to do exactly this. Try class MyCell < Cell::Rails include CanCan::ControllerAdditions end If you're also using Devise, I had to do this: class MyCell < Cell::Rails include CanCan::ControllerAdditions include Devise::Controllers::Helpers Devise::Controllers::Helpers.define_helpers(Devise::Mapping.new(:user, {})) end #define_helpers will add helper methods such as current_user and user_signed_in? to the cell. For those who happen to have a custom current_ability() method (in

Get a string that represents a user's CanCan abilities

五迷三道 提交于 2019-12-03 05:19:28
问题 I want to cache a Post view, but the view depends on the permissions of the current user (e.g., I only show the "edit" link if current_user.can?(:edit, @post) ) So I'd like my cache key to include a representation of the current user's CanCan abilities, so that I can invalidate the cache when the user's abilities change SO: how can I get a string that represents the current user's abilities such that 2 different users with the same abilities will generate the same "ability string"? I've tried