activeadmin


How to restrict manageable entities in Active Admin?


I would like to restrict the list of manageable model entities in Active Admin based on an attribute of the current_user and the model entity.
e.g: A User (with admin rights) have a team_id == 2 and should only be able to manage
Tasks with a team_id == 2
Edit: I'm trying to use scopes but I don't know how to scope using this condition:
user.team_id == task.team_id
Is that possible with Active Admin?
Thanks for your time.(This is my first post, tell me if I can improve my question)
You're most probably trying to define different levels of access and authorization. You should look into the CanCan gem: https://github.com/ryanb/cancan
ActiveAdmin explains how to implement it here: http://www.activeadmin.info/docs/13-authorization-adapter.html#using_the_cancan_adapter
Then in your case you could define an ability.rb like:
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
case user.team_id
when 1
can :manage, Post
when 2
can :manage, Post
can :manage, Task
when 3
can :manage, :all
end
can :read, ActiveAdmin::Page, :name => "Dashboard"
end
end
I would suggest defining a role attribute instead of using team_id, but that's just being picky with semantic :)
Hope it helps!
I finally found how to use scopes:
scope_to :current_user
And add to User model:
has_many :tasks, through: :team

Related Links

How to add an HTML-class to an ActiveAdmin index table
How to use modules to split very long code in active admin?
Downloading all records of a paginated resource in ActiveAdmin
Can you use the Form() command in ActiveAdmin in the content of a custom page?
CollectionAction route being skipped, action treated as ID
Possible to “split” an ActiveAdmin resource between multiple menu items?
Rails: activeadmin, undefined method `per' for #<ActiveRecord::Relation:0x4d15ee0>
Active Admin create form in register_page
ActiveAdmin - how to customize edit action?
ActiveAdmin - Filter with default value
Make semantic_errors render the exact error-message
ActiveAdmin - Custom action with reusing the show form
make checkboxes for a has_many :through association using Formtastic
CopyCopter with ActiveAdmin gets loads of Timeout Errors.
Rails ActiveAdmin - after creating a post I wish to render an action
Translation models name in active admin

Categories

HOME
openshift
ionic2
mod-rewrite
tomcat
gaming
vagrant
workflow
redmine
concurrency
ant
openlayers-3
tabs
header
moodle-api
ipv6
sentry
migrate
orc
powermock
jodatime
dhcp
phonegap-build
playframework-2.0
nose
codefluent
android-custom-view
backendless
password-generator
ruby-daemons
math.js
bitbake
monitor
es6-modules
source-insight
reporting
delayed-job
appcode
advanced-filter
custom-keyboard
android-canvas
buildforge
wdk
extbase
widestring
imgur
rm
sonicmq
visual-format-language
punctuation
subforms
ptvs
sesame
degrees
ogg
haraka
pjax
callouts
jenkins-workflow
declarative
piping
node-glob
vaadin4spring
distributed-cache
openmrs
seadragon
largenumber
mixins
roxygen2
console.log
innerhtml
mod-auth-openidc
sql-processor
zend-mail
xml-signature
inequality
siena
treeline
maven-central
incognito-mode
illuminate-container
revmob
iirf
mp4parser
jquery-lazyload
android-authenticator
simplecov
nsmutablestring
websphere-6.1
server-name
kaazing
jdom
algol68
filelock
css-friendly
dip
urchin
asdoc

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App