cancan

ActiveAdmin with CanCanAdapter causing infinite redirect on dashboard

人走茶凉 提交于 2020-01-01 05:18:50
问题 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. 回答1: 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

Best way to handle multitenancy in Rails 3

折月煮酒 提交于 2019-12-30 05:04:31
问题 I'm building multi-tenant application. All data isolation is done by TenantID column in each table. What is the best way to automatically handle multi-tenancy for all tenant models. Example: Contacts.new({.....}) should automatically add :tenant => curret_user.tenant Contacts.where({....}) should also add :tenant => curret_user.tenant Currently I see something like this in CanCan gem which that can fetch records for specific user parameters. But it is not providing anything for insert and

Show and hide based on user role in rails

大城市里の小女人 提交于 2019-12-25 08:48:15
问题 I have the following code in my home.html.erb file; <!-- if seeker is logged in show button "Grab it" --> <% if user_signed_in? %> <div class="grabit alignright"> <small>want to work on this?</small> <!-- if seeker is not logged in, show him the output text of "Sign in to work on this job" --> <% else %> <small>are you a guru? want to work on this? Sign up.</small> <% end %> </div> Now as you can see I'm trying to have Seeker as a user role. Depending if that type of user with that type of

Rails, Devise, Role Model and CanCanCan - defining abilities

我们两清 提交于 2019-12-25 06:36:31
问题 I am using Rails 4 to make a web app. I am trying to use CanCanCan to define abilities for the various roles. I have a User model and a Profile model. Each user can have many profiles. Each profile can have a different role. In my Profile.rb, I have defined my roles (using Role Model gem) as: include RoleModel roles :admin, :manager, # coalfacer :student, :educator, :researcher, :ktp, :faculty_manager, :ip_asset_manager, # for universities :sponsor, # for industry :project_manager,

Testing cancan abilities and getting MassAssignmentSecurity::Error

纵然是瞬间 提交于 2019-12-25 05:18:31
问题 I have implemented cancan and would like to test abilities as recommended on the cancan wiki. I trying to replicate "user can only destroy projects which he owns." spec/models/ability_spec.rb: require "cancan/matchers" require 'spec_helper' describe Ability do context "user is investigator" do it "user can only destroy projects which he owns" do user = FactoryGirl.create(:user) ability = Ability.new(user) ability.should be_able_to(:destroy, Project.new(:user => user)) end end end However I

Rails 4: CanCanCan abilities with has_many :through association

南楼画角 提交于 2019-12-24 05:03:13
问题 I have a Rails app with the following models: class User < ActiveRecord::Base has_many :administrations has_many :calendars, through: :administrations end class Calendar < ActiveRecord::Base has_many :administrations has_many :users, through: :administrations end class Administration < ActiveRecord::Base belongs_to :user belongs_to :calendar end For a given calendar , a user has a role , which is define in the administration join model. For each calendar, a user can have only one of the

How do I show an error for unauthorized can can access

耗尽温柔 提交于 2019-12-24 02:33:10
问题 I am using Bootstrap, which has div class="alert notice" that has a bunch of classes for various notice messages. I also have an AJAX destroy action for a comment, that I have added cancan authorization on. When I try to delete a comment that the current_user doesn't have access to it doesn't work - which is correct. But what I want to happen is for an error message to pop-up, in a Bootstrap style'd div for 5 - 10 seconds and then disappear. This is the destroy action on my CommentsController

Rspec tests failing with user being redirected when he should be given access to a Deal he owns

耗尽温柔 提交于 2019-12-23 20:08:52
问题 In my app, I give access to a customer to HIS own deals thanks to Cancan. It works when I try it "manually" with the browser but I fail at implementing the rspec tests . A customer can't access other customer's deals but only his own (the administrator give him access through Active Admin interface). It's like I am not managing to make rspec understand that the customer(through FactoryGirl) I create for tests should be allowed/associated with the deals I create for the tests (again through

Devise/cancan redirect admin issue

旧巷老猫 提交于 2019-12-23 04:55:20
问题 I have a User model with a boolean switch to designate admin t/f. My current application controller: class ApplicationController < ActionController::Base protect_from_forgery def after_sign_in_path_for(user) if current_user.admin? admin_index_path else dashboard_index_path end end end My current admin controller: class AdminController < ApplicationController def index if current_user.admin? admin_index_path else home_index_path end end end The goal is of course to only allow access to the

Cancan + Devise rescue_from not catching exception

左心房为你撑大大i 提交于 2019-12-23 02:44:06
问题 I am implementing Devise and Cancan for user authentication and permissions. Everything works great so far except I am not able to redirect users to the login page when they are not allowed to access a specific feature. My test is: feature 'A signed in user' do before(:each) do user = FactoryGirl.create(:user) visit "/login" fill_in "user_email", :with => user.email fill_in "user_password", :with => "ilovebananas" click_button "Sign in" end scenario 'should not have access to admin dashboard'