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

Is it possible to render subscript and superscript in ActiveAdmin pages?
How to make a form row's label into a selection input for a different attribute in ActiveAdmin?
How to use Money filter in active admin?
Can a rubocop check be disabled on certain paths only?
Render plain form html from ActiveAdmin instead of full page
Customize ActiveAdmin Page based on Roles
NoMethodError error for search_methods activeadmin
rails concerns - superclass mismatch error with active_admin in gems list
How to filter by “is not” in active admin/ransack
Active Admin image upload with refile
AuthorizationAdapter in ActiveAdmin
ActiveAdmin and Rails Engine. How do you keep the path name the same?
Active admin defining scope for custom page
ActiveAdmin: Can I redirect the user to the index after they create/edit something?
Active admin and Pundit
Sortable for has_many does not sort properly

Categories

HOME
amazon-web-services
knockout.js
apache-nifi
azure-functions
matrix
eclipse-plugin
seedstack
bokeh
antd
operating-system
google-sheets-query
jint
repair
clone
cdi
phpseclib
tfs2010
port
swarm
azure-graph-api
game-maker
spring-amqp
fullcalendar-scheduler
pushdown-automaton
jodatime
jpa-2.0
mahout-recommender
vertica
mixpanel
exec-maven-plugin
infrared
home
gitkraken
conda
channel
chronicle-queue
python-appium
beego
echosign
envoy
matlab-app-designer
publishing
delayed-job
series
nsmutablearray
android-collapsingtoolbar
serversocket
gnu-classpath
bootstrap-sass
pdfnet
klee
moinmoin
doctrine-extensions
jshint
realstudio
deployd
roracle
freshdesk
http-basic-authentication
dblink
kendo-editor
ternary-operator
pjax
s-function
bilinear-interpolation
django-testing
openseadragon
wolfram-language
fiber
static-methods
apache-pig-grunt
rails-engines
urbit
swiffy
teamviewer
trust
wif4.5
phpquery
cryptojs
juniper-network-connect
opencyc
apache-commons-digester
nette
prism-4
text-align
directorysearcher
phonegap-facebook-plugin
uno
window-resize
treeline
rpg
commenting
webaii
wso2bam
meteorite
sensormanager
sql-view
disjoint-union
form-for
microformats
arel
examine
django-filebrowser
xmlwriter
red-system
playorm
clrprofiler
wndproc
struts2-s2hibernate
kobold2d
netstream
dip
suphp
dm
isapi-redirect
community-server
account-management

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App