padrino-admin 0.8.5 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +40 -84
- data/VERSION +1 -1
- data/lib/padrino-admin.rb +3 -20
- data/lib/padrino-admin/access_control.rb +78 -326
- data/lib/padrino-admin/generators/actions.rb +6 -26
- data/lib/padrino-admin/generators/admin_app.rb +40 -11
- data/lib/padrino-admin/generators/admin_page.rb +11 -17
- data/lib/padrino-admin/generators/orm.rb +85 -0
- data/lib/padrino-admin/generators/templates/account/activerecord.rb.tt +43 -0
- data/lib/padrino-admin/generators/templates/account/datamapper.rb.tt +54 -0
- data/lib/padrino-admin/generators/templates/{page/db → account}/seeds.rb.tt +5 -6
- data/lib/padrino-admin/generators/{app/app.rb.tt → templates/app/app.rb} +2 -10
- data/lib/padrino-admin/generators/templates/app/controllers/base.rb +7 -0
- data/lib/padrino-admin/generators/{app → templates/app}/controllers/sessions.rb +6 -6
- data/lib/padrino-admin/generators/templates/assets/stylesheets/base.css +370 -0
- data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/amro/style.css +364 -0
- data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/bec-green/style.css +290 -0
- data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/bec/style.css +301 -0
- data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/blue/style.css +287 -0
- data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/default/style.css +373 -0
- data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/djime-cerulean/style.css +305 -0
- data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/kathleene/style.css +279 -0
- data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/olive/style.css +345 -0
- data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/orange/style.css +269 -0
- data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/reidb-greenish/style.css +302 -0
- data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/ruby/style.css +281 -0
- data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/warehouse/style.css +391 -0
- data/lib/padrino-admin/generators/templates/erb/app/base/_sidebar.erb.tt +13 -0
- data/lib/padrino-admin/generators/templates/erb/app/base/index.erb.tt +17 -0
- data/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt +44 -0
- data/lib/padrino-admin/generators/templates/erb/app/sessions/new.erb.tt +46 -0
- data/lib/padrino-admin/generators/templates/erb/page/_form.erb.tt +11 -0
- data/lib/padrino-admin/generators/templates/erb/page/edit.erb.tt +18 -0
- data/lib/padrino-admin/generators/templates/erb/page/index.erb.tt +36 -0
- data/lib/padrino-admin/generators/templates/erb/page/new.erb.tt +17 -0
- data/lib/padrino-admin/generators/templates/page/controller.rb.tt +32 -22
- data/lib/padrino-admin/helpers/authentication_helpers.rb +8 -9
- data/lib/padrino-admin/helpers/view_helpers.rb +20 -338
- data/lib/padrino-admin/locale/admin/de.yml +15 -49
- data/lib/padrino-admin/locale/admin/en.yml +12 -50
- data/lib/padrino-admin/locale/admin/it.yml +15 -50
- data/padrino-admin.gemspec +40 -321
- data/test/fixtures/data_mapper.rb +56 -7
- data/test/generators/test_admin_app_generator.rb +17 -16
- data/test/generators/test_admin_page_generator.rb +12 -16
- data/test/test_admin_application.rb +193 -12
- metadata +33 -314
- data/lib/padrino-admin/column_store.rb +0 -156
- data/lib/padrino-admin/config.rb +0 -36
- data/lib/padrino-admin/generators/admin_uploader.rb +0 -88
- data/lib/padrino-admin/generators/app/controllers/accounts.rb +0 -37
- data/lib/padrino-admin/generators/app/controllers/base.rb +0 -11
- data/lib/padrino-admin/generators/app/controllers/javascripts.rb +0 -10
- data/lib/padrino-admin/generators/app/views/accounts/_form.haml +0 -24
- data/lib/padrino-admin/generators/app/views/accounts/edit.haml +0 -3
- data/lib/padrino-admin/generators/app/views/accounts/grid.js.erb +0 -9
- data/lib/padrino-admin/generators/app/views/accounts/new.haml +0 -3
- data/lib/padrino-admin/generators/app/views/accounts/store.jml +0 -7
- data/lib/padrino-admin/generators/app/views/base/dashboard.haml +0 -3
- data/lib/padrino-admin/generators/app/views/base/index.haml +0 -19
- data/lib/padrino-admin/generators/app/views/javascripts/admin.js.erb +0 -490
- data/lib/padrino-admin/generators/app/views/javascripts/locale.js.erb +0 -135
- data/lib/padrino-admin/generators/app/views/sessions/new.haml +0 -26
- data/lib/padrino-admin/generators/assets/flash/charts.swf +0 -0
- data/lib/padrino-admin/generators/assets/flash/clippy.swf +0 -0
- data/lib/padrino-admin/generators/assets/flash/expressinstall.swf +0 -0
- data/lib/padrino-admin/generators/assets/flash/swfupload.swf +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/back.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/background.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/bg-content.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/bg-hd-slate.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/bg-hd.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/bg-intro.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/bg-login.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/bg-menu-slate.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/bg-menu.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/bg.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/btn-login.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/cancel.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/categories.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/close.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/close.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/delete.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/download.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/duplicate.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/edit.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/export.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/hd-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/image.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/loader.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/logo-loader.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/logo-small.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/new.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/no-image.png +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/preview.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/print.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/save.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/support.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/admin/up.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/box/corners-blue.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/box/corners.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/box/l-blue.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/box/l.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/box/r-blue.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/box/r.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/box/tb-blue.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/box/tb.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/button/arrow.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/button/btn.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/button/group-cs.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/button/group-lr.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/button/group-tb.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/button/s-arrow-b-noline.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/button/s-arrow-b.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/button/s-arrow-bo.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/button/s-arrow-noline.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/button/s-arrow-o.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/button/s-arrow.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/dd/drop-add.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/dd/drop-no.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/dd/drop-yes.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/editor/tb-sprite.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/checkbox.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/clear-trigger.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/clear-trigger.psd +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/date-trigger.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/date-trigger.psd +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/error-tip-corners.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/exclamation.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/radio.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/search-trigger.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/search-trigger.psd +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/text-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/trigger-tpl.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/trigger.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/form/trigger.psd +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/gradient-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/Thumbs.db +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/arrow-left-white.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/arrow-right-white.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/col-move-bottom.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/col-move-top.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/columns.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/dirty.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/done.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/drop-no.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/drop-yes.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/footer-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid-blue-hd.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid-blue-split.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid-hrow.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid-loading.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid-split.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid-vista-hd.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid3-hd-btn.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid3-hrow-over.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid3-hrow.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid3-special-col-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid3-special-col-sel-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/group-by.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/group-expand-sprite.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/hd-pop.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/hmenu-asc.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/hmenu-desc.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/hmenu-lock.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/hmenu-lock.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/hmenu-unlock.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/hmenu-unlock.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/invalid_line.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/loading.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/mso-hd.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/nowait.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-first-disabled.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-first.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-last-disabled.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-last.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-next-disabled.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-next.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-prev-disabled.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-prev.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/pick-button.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/refresh.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/row-check-sprite.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/row-expand-sprite.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/row-over.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/row-sel.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/sort-hd.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/sort_asc.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/sort_desc.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/grid/wait.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/collapse.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/expand.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/gradient-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/mini-bottom.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/mini-left.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/mini-right.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/mini-top.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/ns-collapse.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/ns-expand.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/panel-close.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/panel-title-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/panel-title-light-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/stick.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/stuck.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/tab-close-on.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/layout/tab-close.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/menu/checked.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/menu/group-checked.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/menu/item-over.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/menu/menu-parent.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/menu/menu.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/menu/unchecked.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/panel/corners-sprite.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/panel/left-right.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/panel/light-hd.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/panel/tool-sprite-tpl.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/panel/tool-sprites.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/panel/tools-sprites-trans.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/panel/top-bottom.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/panel/top-bottom.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/panel/white-corners-sprite.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/panel/white-left-right.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/panel/white-top-bottom.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/progress/progress-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/qtip/bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/qtip/close.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/qtip/tip-anchor-sprite.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/qtip/tip-sprite.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/s.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/shadow-c.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/shadow-lr.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/shadow.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/shared/blue-loading.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/shared/calendar.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/shared/glass-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/shared/hd-sprite.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/shared/large-loading.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/shared/left-btn.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/shared/loading-balls.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/shared/right-btn.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/shared/warning.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/e-handle-dark.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/e-handle.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/ne-handle-dark.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/ne-handle.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/nw-handle-dark.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/nw-handle.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/s-handle-dark.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/s-handle.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/se-handle-dark.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/se-handle.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/square.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/sw-handle-dark.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/sizer/sw-handle.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/slider/slider-bg.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/slider/slider-thumb.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/slider/slider-v-bg.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/slider/slider-v-thumb.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tabs/scroll-left.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tabs/scroll-right.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tabs/scroller-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-btm-inactive-left-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-btm-inactive-right-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-btm-left-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-btm-right-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-close.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-strip-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-strip-bg.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-strip-btm-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tabs-sprite.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/btn-arrow-light.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/btn-arrow.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/btn-over-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/gray-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/more.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/tb-bg.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/tb-btn-sprite.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/tb-xl-btn-sprite.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/tb-xl-sep.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/arrows.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/drop-add.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/drop-between.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/drop-no.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/drop-over.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/drop-under.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/drop-yes.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-end-minus-nl.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-end-minus.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-end-plus-nl.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-end-plus.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-end.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-line.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-minus-nl.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-minus.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-plus-nl.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-plus.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/folder-open.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/folder.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/leaf.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/loading.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/tree/s.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/window/icon-error.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/window/icon-info.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/window/icon-question.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/window/icon-warning.gif +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/window/left-corners.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/window/left-corners.psd +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/window/left-right.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/window/left-right.psd +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/window/right-corners.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/window/right-corners.psd +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/window/top-bottom.png +0 -0
- data/lib/padrino-admin/generators/assets/images/ext/default/window/top-bottom.psd +0 -0
- data/lib/padrino-admin/generators/assets/javascripts/controls.js +0 -3
- data/lib/padrino-admin/generators/assets/javascripts/dragdrop.js +0 -3
- data/lib/padrino-admin/generators/assets/javascripts/effects.js +0 -4
- data/lib/padrino-admin/generators/assets/javascripts/ext.js +0 -29
- data/lib/padrino-admin/generators/assets/javascripts/prototype.js +0 -14
- data/lib/padrino-admin/generators/assets/javascripts/swfupload.js +0 -4
- data/lib/padrino-admin/generators/assets/stylesheets/admin.css +0 -60
- data/lib/padrino-admin/generators/assets/stylesheets/ext.css +0 -1543
- data/lib/padrino-admin/generators/assets/stylesheets/login.css +0 -17
- data/lib/padrino-admin/generators/assets/stylesheets/standard.css +0 -62
- data/lib/padrino-admin/generators/templates/page/views/_form.haml.tt +0 -9
- data/lib/padrino-admin/generators/templates/page/views/edit.haml.tt +0 -3
- data/lib/padrino-admin/generators/templates/page/views/grid.js.erb.tt +0 -9
- data/lib/padrino-admin/generators/templates/page/views/new.haml.tt +0 -3
- data/lib/padrino-admin/generators/templates/page/views/store.jml.tt +0 -6
- data/lib/padrino-admin/generators/templates/uploader/controller.rb +0 -24
- data/lib/padrino-admin/generators/templates/uploader/lib/uploader.rb +0 -66
- data/lib/padrino-admin/generators/templates/uploader/views/grid.js.erb +0 -57
- data/lib/padrino-admin/generators/templates/uploader/views/store.jml +0 -10
- data/lib/padrino-admin/locale/extjs/de.yml +0 -147
- data/lib/padrino-admin/locale/extjs/en.yml +0 -147
- data/lib/padrino-admin/locale/extjs/it.yml +0 -147
- data/lib/padrino-admin/orm.rb +0 -48
- data/lib/padrino-admin/orm/abstract.rb +0 -95
- data/lib/padrino-admin/orm/activerecord.rb +0 -144
- data/lib/padrino-admin/orm/datamapper.rb +0 -229
- data/lib/padrino-admin/orm/mongomapper.rb +0 -65
- data/lib/padrino-admin/utils/literal.rb +0 -13
- data/test/fixtures/active_record.rb +0 -29
- data/test/fixtures/mongo_mapper.rb +0 -12
- data/test/fixtures/test_column_store.jml +0 -11
- data/test/generators/test_admin_uploader_generator.rb +0 -56
- data/test/test_access_control.rb +0 -99
- data/test/test_active_record.rb +0 -96
- data/test/test_column_store.rb +0 -87
- data/test/test_config.rb +0 -13
- data/test/test_data_mapper.rb +0 -114
- data/test/test_mongo_mapper.rb +0 -30
data/README.rdoc
CHANGED
@@ -2,12 +2,11 @@
|
|
2
2
|
|
3
3
|
=== Overview
|
4
4
|
|
5
|
-
Padrino has a beautiful
|
5
|
+
Padrino has a beautiful Admin, with these fatures:
|
6
6
|
|
7
7
|
Orm Agnostic:: Adapters for datamapper, activerecord, mongomapper, couchdb (now only: datamapper and activerecord)
|
8
8
|
Authentication:: Support for Account authentication, Account Permission managment
|
9
9
|
Scaffold:: You can simply create a new "admin interface" simply providing a Model
|
10
|
-
Ajax Uploads:: You can upload file, manage them and attach them to any model in a quick and simple way (coming soon)
|
11
10
|
|
12
11
|
=== Admin Usage
|
13
12
|
|
@@ -23,118 +22,75 @@ For create the admin application:
|
|
23
22
|
Now follow admin instructions so:
|
24
23
|
|
25
24
|
* edit your config/database.rb
|
26
|
-
* run padrino rake dm:
|
25
|
+
* run padrino rake dm:migrate # or ar:migrate if you use activerecord
|
27
26
|
* run padrino rake seed
|
28
27
|
|
29
28
|
Your admin now is "complete", you can start your server with <tt>padrino start</tt> and point your browser to /admin!
|
30
29
|
|
31
30
|
For create a new "scaffold" you need to provide only a Model for them like:
|
32
31
|
|
33
|
-
fun-test$ padrino-gen model post --skip-migration
|
32
|
+
fun-test$ padrino-gen model post --skip-migration # edit your post.rb model and add some fields
|
34
33
|
fun-test$ padrino-gen rake dm:auto:migrate
|
35
|
-
fun-test$ padrino-gen admin_page
|
36
|
-
fun-test$ padrino start
|
34
|
+
fun-test$ padrino-gen admin_page post
|
35
|
+
fun-test$ padrino start # and go to http://localhost:3000/admin
|
37
36
|
|
38
37
|
That's all!!
|
39
38
|
|
40
39
|
=== Admin Authentication
|
41
40
|
|
42
|
-
Padrino Admin use a model Account for manage role, membership and permissions
|
41
|
+
Padrino Admin use a model Account for manage role, membership and permissions.
|
43
42
|
|
44
|
-
access_control.roles_for :any do |role|
|
45
|
-
role.allow "/sessions"
|
46
|
-
# role.deny "/deny/this/always"
|
47
|
-
end
|
48
43
|
|
49
|
-
|
50
|
-
role.allow "/"
|
44
|
+
==== Scenario Ecommerce
|
51
45
|
|
52
|
-
|
53
|
-
project.menu :list, "/admin/accounts.js"
|
54
|
-
project.menu :new, "/admin/accounts/new"
|
55
|
-
end
|
56
|
-
end
|
46
|
+
For an ecommerce we usually deny some controllers/actions like
|
57
47
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
48
|
+
class MyEcommerce < Padrino::Application
|
49
|
+
enable :authentication
|
50
|
+
enable :store_location
|
51
|
+
set :login_page, "/login"
|
63
52
|
|
64
|
-
|
65
|
-
|
66
|
-
|
53
|
+
access_control.roles_for :any do |role|
|
54
|
+
role.protect "/customer/orders"
|
55
|
+
role.protect "/cart/checkout"
|
67
56
|
end
|
68
57
|
end
|
69
58
|
|
70
|
-
In this example we
|
71
|
-
|
72
|
-
Account with role <tt>admin</tt> can manage <tt>only</tt> accounts because have access to "/admin/accounts/**" paths
|
73
|
-
Account with role <tt>editor</tt> can manage <tt>only</tt> post/comments because have access to "/admin/posts/**", "/admin/posts/**" paths
|
74
|
-
|
75
|
-
Another good fature of Padrino admin is that when you define a <tt>Project Module</tt> role you also build the Menu Tree of the Admin.
|
76
|
-
Trust us that in future you appreciate so much this feature.
|
77
|
-
|
78
|
-
=== Admin Uploads
|
79
|
-
|
80
|
-
Padrino admin has a builtin upload managment that leave you to be free as possible.
|
81
|
-
|
82
|
-
fun-test$ padrino-gen admin_uploader
|
83
|
-
fun-test$ rake dm:auto:upgrade # or ar:migrate
|
84
|
-
|
85
|
-
Finish! Now you can browse into your admin and you can see a new menu called +upload+ where you can see all your uploads,
|
86
|
-
upload other file, delete ...
|
87
|
-
|
88
|
-
All upload definitions are defined in lib/uploader.rb, here you can preproces your attachments (like resize) or manage versions.
|
89
|
-
|
90
|
-
See http://github.com/jnicklas/carrierwave
|
59
|
+
In this example +if+ we visit urls that start with /+customer+/+orders+ or /+cart/checkout+ we will be redirected
|
60
|
+
to our :+login_page+ "/login". Once we are correctly logged in we can visit these pages.
|
91
61
|
|
92
|
-
====
|
62
|
+
==== Scenario Admin
|
93
63
|
|
94
|
-
|
64
|
+
Suppose that you need to some actions for +admin+ accounts and others for +editors+
|
95
65
|
|
96
|
-
|
97
|
-
has n, :uploads
|
66
|
+
When you generate padrino-admin will be created for you an +Account+ model that have a +role+ attribute. So:
|
98
67
|
|
99
|
-
|
68
|
+
class Admin < Padrino::Application
|
69
|
+
enable :authentication
|
70
|
+
disable :store_location
|
71
|
+
set :login_page, "/admin/sessions/new"
|
100
72
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
# admin/views/accounts/_form.haml
|
107
|
-
%tr
|
108
|
-
%td=f.label :uploads
|
109
|
-
%td=f.open_window_grid :upload_ids, :with => :uploads, :get => :id, :show => :file, :multiple => true, :item => :panel
|
110
|
-
|
111
|
-
*open_window_grid* is a padrino-admin method that open an extjs window contains your +grids+ so in this case:
|
112
|
-
|
113
|
-
open window grid for :+account+ model in method :+upload_ids+ with the help of controller :+uploads+ and
|
114
|
-
get as a value the :+id+ and display :+file+.
|
115
|
-
|
116
|
-
:+multiple+ indicate that we need more than one :+id+.
|
117
|
-
:+item+ tell to the grid who is the container, we need to explicit this because we have two container in our upload.js
|
118
|
-
|
119
|
-
See view helpers[http://github.com/padrino/padrino-framework/blob/master/padrino-admin/lib/padrino-admin/helpers/view.rb#L145] for more docs.
|
120
|
-
|
121
|
-
That's all! Now run mingrations and browse accounts for see our uploader.
|
122
|
-
|
123
|
-
==== Attach One Upload to a Model
|
73
|
+
access_control.roles_for :any do |role|
|
74
|
+
role.protect "/"
|
75
|
+
role.allow "/sessions"
|
76
|
+
end
|
124
77
|
|
125
|
-
|
78
|
+
access_control.roles_for :admin do |role|
|
79
|
+
role.project_module :settings, "/settings"
|
80
|
+
end
|
126
81
|
|
127
|
-
|
128
|
-
|
82
|
+
access_control.roles_for :editor do |role|
|
83
|
+
role.project_module :posts, "/posts"
|
84
|
+
role.project_module :categories, "/categories"
|
85
|
+
end
|
86
|
+
end
|
129
87
|
|
130
|
-
|
88
|
+
In this case we +protect+ the entire admin (all paths that start with "/") except paths that start with /+sessions+ so
|
89
|
+
an +unauthenticated+ user can login.
|
131
90
|
|
132
|
-
|
133
|
-
%tr
|
134
|
-
%td=f.label :upload
|
135
|
-
%td=f.open_window_grid :upload_id, :with => :uploads, :get => :id, :show => :file, :item => :panel
|
91
|
+
If we login as +admin+ (account.role == 'admin') we have access *only* to paths that start with /+settings+.
|
136
92
|
|
137
|
-
|
93
|
+
If we login as +editor+ (account.role == 'editor') we have access *only* to paths that start with /+posts+ and /+categories+
|
138
94
|
|
139
95
|
== Copyright
|
140
96
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
data/lib/padrino-admin.rb
CHANGED
@@ -3,7 +3,7 @@ require 'padrino-gen'
|
|
3
3
|
require 'padrino-helpers'
|
4
4
|
|
5
5
|
Dir[File.dirname(__FILE__) + '/padrino-admin/*.rb'].each {|file| require file }
|
6
|
-
Dir[File.dirname(__FILE__) + '/padrino-admin/{helpers,
|
6
|
+
Dir[File.dirname(__FILE__) + '/padrino-admin/{helpers,middleware,utils}/*.rb'].each {|file| require file }
|
7
7
|
|
8
8
|
module Padrino
|
9
9
|
##
|
@@ -21,35 +21,18 @@ end
|
|
21
21
|
# We need to apply Padrino::Admin::Utils::Extensions
|
22
22
|
#
|
23
23
|
String.send(:include, Padrino::Admin::Utils::Crypt)
|
24
|
-
String.send(:include, Padrino::Admin::Utils::Literal)
|
25
24
|
|
26
25
|
##
|
27
26
|
# We need to add to Padrino::Application a +access_control+ class
|
28
27
|
#
|
29
|
-
Padrino::Application.
|
30
|
-
Padrino::Application.send(:access_control=, Class.new(Padrino::Admin::AccessControl::Base))
|
31
|
-
|
32
|
-
##
|
33
|
-
# If CarrierWave is defined we set the root directory
|
34
|
-
#
|
35
|
-
CarrierWave.root = Padrino.root("public") if defined?(CarrierWave)
|
36
|
-
|
37
|
-
##
|
38
|
-
# Extend Abastract Form builder
|
39
|
-
#
|
40
|
-
Padrino::Helpers::FormBuilder::AbstractFormBuilder.send(:include, Padrino::Admin::Helpers::ViewHelpers::AbstractFormBuilder)
|
28
|
+
Padrino::Application.extend(Padrino::Admin::AccessControl::ClassMethods)
|
41
29
|
|
42
30
|
##
|
43
31
|
# Load our Padrino::Admin locales
|
44
32
|
#
|
45
33
|
I18n.load_path += Dir["#{File.dirname(__FILE__)}/padrino-admin/locale/**/*.yml"]
|
46
34
|
|
47
|
-
##
|
48
|
-
# Load our databases extensions
|
49
|
-
#
|
50
|
-
Padrino::Admin::Orm.register!
|
51
|
-
|
52
35
|
##
|
53
36
|
# Now we need to add admin generators to padrino-gen
|
54
37
|
#
|
55
|
-
Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/padrino-admin/generators/{actions,admin_app,admin_page
|
38
|
+
Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/padrino-admin/generators/{actions,orm,admin_app,admin_page}.rb']
|
@@ -2,396 +2,148 @@ module Padrino
|
|
2
2
|
module Admin
|
3
3
|
class AccessControlError < StandardError #:nodoc:
|
4
4
|
end
|
5
|
-
|
6
5
|
##
|
7
|
-
# This module give to a padrino application an access control functionality
|
8
|
-
#
|
9
|
-
# class EcommerceDemo < Padrino::Application
|
10
|
-
# enable :authentication
|
11
|
-
# set :login_page, "/login" # or your login page
|
12
|
-
# enable :store_location # if you want know what is the page that need authentication
|
13
|
-
#
|
14
|
-
# access_control.roles_for :any do
|
15
|
-
# role.require_login "/cart"
|
16
|
-
# role.require_login "/account"
|
17
|
-
# role.allow "/account/create"
|
18
|
-
# end
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# In the EcommerceDemo, we +only+ require logins for all paths that start with "/cart" like:
|
22
|
-
#
|
23
|
-
# - "/cart/add"
|
24
|
-
# - "/cart/empty"
|
25
|
-
# - "/cart/checkout"
|
26
|
-
#
|
27
|
-
# same thing for "/account" so we require a login for:
|
28
|
-
#
|
29
|
-
# - "/account"
|
30
|
-
# - "/account/edit"
|
31
|
-
# - "/account/update"
|
32
|
-
#
|
33
|
-
# but if we call "/account/create" we don't need to be logged in our site for do that.
|
34
|
-
# In EcommerceDemo example we set +redirect_back_or_default+ so if a +unlogged+
|
35
|
-
# user try to access "/account/edit" will be redirected to "/login" when login is done will be
|
36
|
-
# redirected to "/account/edit".
|
37
|
-
#
|
38
|
-
# If we need something more complex aka roles/permissions we can do that in the same simple way
|
39
|
-
#
|
40
|
-
# class AdminDemo < Padrino::Application
|
41
|
-
# enable :authentication
|
42
|
-
# set :login_page, "/sessions/new" # or your page
|
43
|
-
#
|
44
|
-
# access_control.roles_for :any do |role|
|
45
|
-
# role.allow "/sessions"
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
# access_control.roles_for :admin do |role, account|
|
49
|
-
# role.allow "/"
|
50
|
-
# role.deny "/posts"
|
51
|
-
# end
|
52
|
-
#
|
53
|
-
# access_control.roles_for :editor do |role, account|
|
54
|
-
# role.allow "/posts"
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
#
|
58
|
-
# If a user logged with role admin can:
|
59
|
-
#
|
60
|
-
# - Access to all paths that start with "/session" like "/sessions/{new,create}"
|
61
|
-
# - Access to any page except those that start with "/posts"
|
62
|
-
#
|
63
|
-
# If a user logged with role editor can:
|
64
|
-
#
|
65
|
-
# - Access to all paths that start with "/session" like "/sessions/{new,create}"
|
66
|
-
# - Access +only+ to paths that start with "/posts" like "/post/{new,edit,destroy}"
|
67
|
-
#
|
68
|
-
# Finally we have another good fatures, the possibility in the same time we build role build also +tree+.
|
69
|
-
# Figure this scenario: in my admin every account need their own menu, so an Account with role editor have
|
70
|
-
# a menu different than an Account with role admin.
|
71
|
-
#
|
72
|
-
# So:
|
73
|
-
#
|
74
|
-
# class AdminDemo < Padrino::Application
|
75
|
-
# enable :authentication
|
76
|
-
#
|
77
|
-
# access_control.roles_for :any do |role|
|
78
|
-
# role.allow "/sessions"
|
79
|
-
# end
|
80
|
-
#
|
81
|
-
# access_control.roles_for :admin do |role, current_account|
|
82
|
-
#
|
83
|
-
# role.project_module :settings do |project|
|
84
|
-
# project.menu :accounts, "/accounts" do |accounts|
|
85
|
-
# accounts.add :new, "/accounts/new" do |account|
|
86
|
-
# account.add :administrator, "/account/new/?role=administrator"
|
87
|
-
# account.add :editor, "/account/new/?role=editor"
|
88
|
-
# end
|
89
|
-
# end
|
90
|
-
# project.menu :spam_rules, "/manage_spam"
|
91
|
-
# end
|
92
|
-
#
|
93
|
-
# role.project_module :categories do |project|
|
94
|
-
# current_account.categories.each do |category|
|
95
|
-
# project.menu category.name, "/categories/#{category.id}.js"
|
96
|
-
# end
|
97
|
-
# end
|
98
|
-
# end
|
99
|
-
#
|
100
|
-
# access_control.roles_for :editor do |role, current_account|
|
101
|
-
#
|
102
|
-
# role.project_module :posts do |posts|
|
103
|
-
# post.menu :list, "/posts"
|
104
|
-
# post.menu :new, "/posts/new"
|
105
|
-
# end
|
106
|
-
# end
|
107
|
-
#
|
108
|
-
# In this example when we build our menu tree we are also defining roles so:
|
109
|
-
#
|
110
|
-
# An Admin Account have access to:
|
111
|
-
#
|
112
|
-
# - All paths that start with "/sessions"
|
113
|
-
# - All paths that start with "/accounts"
|
114
|
-
# - All paths that start with "/manage_spam"
|
115
|
-
#
|
116
|
-
# An Editor Account have access to:
|
117
|
-
#
|
118
|
-
# - All paths that start with "/posts"
|
119
|
-
#
|
120
|
-
# Remember that you always deny a specific actions or allow globally others.
|
121
|
-
#
|
122
|
-
# Remember that when you define role_for :a_role, you have also access to the Model Account.
|
6
|
+
# This module give to a padrino application an access control functionality
|
123
7
|
#
|
124
8
|
module AccessControl
|
125
|
-
|
126
9
|
##
|
127
10
|
# Method used by Padrino::Application when we register the extension
|
128
11
|
#
|
129
12
|
def self.registered(app)
|
130
13
|
app.set :session_id, "_padrino_#{File.basename(Padrino.root)}_#{app.app_name}".to_sym
|
131
|
-
app.helpers Padrino::Admin::Helpers::ViewHelpers
|
132
14
|
app.helpers Padrino::Admin::Helpers::AuthenticationHelpers
|
133
|
-
app.
|
15
|
+
app.helpers Padrino::Admin::Helpers::ViewHelpers
|
134
16
|
app.use Padrino::Admin::Middleware::FlashMiddleware, app.session_id # make sure that is the same of session_name in helpers
|
135
|
-
|
17
|
+
app.before { login_required }
|
136
18
|
end
|
137
19
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
base.class_eval("@@cache={}; @authorizations=[]; @roles=[]; @mappers=[]")
|
144
|
-
base.send(:cattr_reader, :cache)
|
145
|
-
super(base)
|
146
|
-
end
|
147
|
-
|
148
|
-
##
|
149
|
-
# We map project modules for a given role or roles
|
150
|
-
#
|
151
|
-
def roles_for(*roles, &block)
|
152
|
-
raise Padrino::Admin::AccessControlError, "Role #{role} must be present and must be a symbol!" if roles.any? { |r| !r.kind_of?(Symbol) } || roles.empty?
|
153
|
-
raise Padrino::Admin::AccessControlError, "You can't merge :any with other roles" if roles.size > 1 && roles.any? { |r| r == :any }
|
154
|
-
|
155
|
-
if roles == [:any]
|
156
|
-
@authorizations << Authorization.new(&block)
|
157
|
-
else
|
158
|
-
raise Padrino::Admin::AccessControlError, "For use custom roles you need to define an Account Class" unless defined?(Account)
|
159
|
-
@roles.concat(roles)
|
160
|
-
@mappers << Proc.new { |account| Mapper.new(account, *roles, &block) }
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
##
|
165
|
-
# Returns (allowed && denied paths).
|
166
|
-
# If an account given we also give allowed & denied paths for their role.
|
167
|
-
#
|
168
|
-
def auths(account=nil)
|
169
|
-
if account
|
170
|
-
cache[account.id] ||= Auths.new(@authorizations, @mappers, account)
|
171
|
-
else
|
172
|
-
cache[:any] ||= Auths.new(@authorizations)
|
173
|
-
end
|
174
|
-
end
|
20
|
+
module ClassMethods #:nodoc:
|
21
|
+
def inherited(base)
|
22
|
+
base.send(:cattr_accessor, :access_control)
|
23
|
+
base.send(:access_control=, Padrino::Admin::AccessControl::Base.new)
|
24
|
+
super(base)
|
175
25
|
end
|
176
|
-
end
|
177
|
-
|
178
|
-
class Auths #:nodoc:
|
179
|
-
attr_reader :account, :allowed, :denied, :project_modules
|
26
|
+
end
|
180
27
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
@allowed = authorizations.collect(&:allowed).flatten
|
185
|
-
@denied = authorizations.collect(&:denied).flatten
|
186
|
-
end
|
187
|
-
if mappers && !mappers.empty?
|
188
|
-
maps = mappers.collect { |m| m.call(account) }.reject { |m| !m.allowed? }
|
189
|
-
@allowed.concat(maps.collect(&:allowed).flatten)
|
190
|
-
@denied.concat(maps.collect(&:denied).flatten)
|
191
|
-
@project_modules = maps.collect(&:project_modules).flatten.uniq
|
192
|
-
else
|
193
|
-
@project_modules = []
|
194
|
-
end
|
195
|
-
@allowed.uniq!
|
196
|
-
@denied.uniq!
|
28
|
+
class Base
|
29
|
+
def initialize #:nodoc:
|
30
|
+
@roles, @authorizations, @project_modules = [], [], []
|
197
31
|
end
|
198
|
-
|
199
32
|
##
|
200
|
-
#
|
33
|
+
# We map project modules for a given role or roles
|
201
34
|
#
|
202
|
-
def
|
203
|
-
|
204
|
-
|
205
|
-
|
35
|
+
def roles_for(*roles, &block)
|
36
|
+
raise Padrino::Admin::AccessControlError, "You must define an Account Model!" unless defined?(Account)
|
37
|
+
raise Padrino::Admin::AccessControlError, "Role #{role} must be present and must be a symbol!" if roles.any? { |r| !r.kind_of?(Symbol) } || roles.empty?
|
38
|
+
raise Padrino::Admin::AccessControlError, "You can't merge :any with other roles" if roles.size > 1 && roles.any? { |r| r == :any }
|
39
|
+
|
40
|
+
@roles += roles
|
41
|
+
@authorizations << Authorization.new(*roles, &block)
|
206
42
|
end
|
207
43
|
|
208
44
|
##
|
209
|
-
# Return
|
210
|
-
# Return true if the requested path (like request.path_info) is +not+ allowed
|
45
|
+
# Return an array of roles
|
211
46
|
#
|
212
|
-
def
|
213
|
-
|
214
|
-
request_path = "/" if request_path.blank?
|
215
|
-
@denied.any? { |path| request_path =~ /^#{path}/ }
|
216
|
-
end
|
217
|
-
end # Auths
|
218
|
-
|
219
|
-
class Authorization
|
220
|
-
attr_reader :allowed, :denied
|
221
|
-
|
222
|
-
def initialize(&block) #:nodoc:
|
223
|
-
@allowed = []
|
224
|
-
@denied = []
|
225
|
-
yield self
|
47
|
+
def roles
|
48
|
+
@roles.uniq.reject { |r| r == :any }
|
226
49
|
end
|
227
50
|
|
228
51
|
##
|
229
|
-
#
|
52
|
+
# Return an array of project_modules
|
230
53
|
#
|
231
|
-
def
|
232
|
-
|
54
|
+
def project_modules(account)
|
55
|
+
role = account ? account.role.to_sym : :any
|
56
|
+
authorizations = @authorizations.find_all { |auth| auth.roles.include?(role) }
|
57
|
+
authorizations.collect(&:project_modules).flatten.uniq
|
233
58
|
end
|
234
59
|
|
235
60
|
##
|
236
|
-
#
|
61
|
+
# Return true if the given account is allowed to see the given path.
|
237
62
|
#
|
238
|
-
def
|
239
|
-
|
63
|
+
def allowed?(account=nil, path=nil)
|
64
|
+
path = "/" if path.blank?
|
65
|
+
authorizations = @authorizations.find_all { |auth| auth.roles.include?(:any) }
|
66
|
+
allowed_paths = authorizations.collect(&:allowed).flatten.uniq
|
67
|
+
denied_paths = authorizations.collect(&:denied).flatten.uniq
|
68
|
+
if account
|
69
|
+
denied_paths.clear
|
70
|
+
authorizations = @authorizations.find_all { |auth| auth.roles.include?(account.role.to_sym) }
|
71
|
+
allowed_paths += authorizations.collect(&:allowed).flatten.uniq
|
72
|
+
authorizations = @authorizations.find_all { |auth| !auth.roles.include?(account.role.to_sym) && !auth.roles.include?(:any) }
|
73
|
+
denied_paths += authorizations.collect(&:allowed).flatten.uniq
|
74
|
+
denied_paths += authorizations.collect(&:denied).flatten.uniq
|
75
|
+
end
|
76
|
+
return true if allowed_paths.any? { |p| path =~ /^#{p}/ }
|
77
|
+
return false if denied_paths.any? { |p| path =~ /^#{p}/ }
|
78
|
+
true
|
240
79
|
end
|
241
|
-
|
242
|
-
end # Authorization
|
80
|
+
end # Base
|
243
81
|
|
244
|
-
class
|
245
|
-
attr_reader :
|
82
|
+
class Authorization
|
83
|
+
attr_reader :allowed, :denied, :project_modules, :roles
|
246
84
|
|
247
|
-
def initialize(
|
248
|
-
@
|
85
|
+
def initialize(*roles, &block) #:nodoc:
|
86
|
+
@roles = roles
|
249
87
|
@allowed = []
|
250
88
|
@denied = []
|
251
|
-
@
|
252
|
-
|
253
|
-
yield(self, @account)
|
254
|
-
end
|
255
|
-
|
256
|
-
##
|
257
|
-
# Create a new project module
|
258
|
-
#
|
259
|
-
def project_module(name, path=nil, &block)
|
260
|
-
@project_modules << ProjectModule.new(name, path, &block)
|
89
|
+
@project_modules = []
|
90
|
+
yield self
|
261
91
|
end
|
262
92
|
|
263
93
|
##
|
264
|
-
#
|
94
|
+
# Allow a specified path
|
265
95
|
#
|
266
96
|
def allow(path)
|
267
97
|
@allowed << path unless @allowed.include?(path)
|
268
98
|
end
|
269
99
|
|
270
100
|
##
|
271
|
-
#
|
272
|
-
#
|
273
|
-
def deny(path)
|
274
|
-
@denied << path unless @allowed.include?(path)
|
275
|
-
end
|
276
|
-
|
277
|
-
##
|
278
|
-
# Return true if role is included in given roles
|
101
|
+
# Protect access from
|
279
102
|
#
|
280
|
-
def
|
281
|
-
@
|
103
|
+
def protect(path)
|
104
|
+
@denied << path unless @denied.include?(path)
|
282
105
|
end
|
283
106
|
|
284
107
|
##
|
285
|
-
#
|
108
|
+
# Create a project module
|
286
109
|
#
|
287
|
-
def
|
288
|
-
|
289
|
-
@
|
110
|
+
def project_module(name, path)
|
111
|
+
allow(path)
|
112
|
+
@project_modules << ProjectModule.new(name, path)
|
290
113
|
end
|
291
|
-
end #
|
114
|
+
end # Authorization
|
292
115
|
|
116
|
+
##
|
117
|
+
# Project Module class
|
118
|
+
#
|
293
119
|
class ProjectModule
|
294
|
-
attr_reader :name
|
295
|
-
|
296
|
-
def initialize(name, path=nil, options={}, &block) #:nodoc:
|
297
|
-
@name = name
|
298
|
-
@options = options
|
299
|
-
@allowed = []
|
300
|
-
@menus = []
|
301
|
-
@path = path
|
302
|
-
@allowed << path if path
|
303
|
-
yield self if block_given?
|
304
|
-
end
|
120
|
+
attr_reader :name
|
305
121
|
|
306
|
-
|
307
|
-
|
308
|
-
#
|
309
|
-
def menu(name, path=nil, options={}, &block)
|
310
|
-
@menus << Menu.new(name, path, options, &block)
|
122
|
+
def initialize(name, path) #:nodoc:
|
123
|
+
@name, @path = name, path
|
311
124
|
end
|
312
125
|
|
313
126
|
##
|
314
|
-
#
|
315
|
-
#
|
316
|
-
def allowed
|
317
|
-
@menus.each { |m| @allowed.concat(m.allowed) }
|
318
|
-
@allowed.uniq
|
319
|
-
end
|
320
|
-
|
321
|
-
##
|
322
|
-
# Return the original name or try to translate or humanize the symbol
|
127
|
+
# Returns the name of the project module. If a symbol it translate/humanize them for you.
|
323
128
|
#
|
324
129
|
def human_name
|
325
|
-
@name.is_a?(Symbol) ? I18n.t("admin.
|
130
|
+
@name.is_a?(Symbol) ? I18n.t("padrino.admin.menu.#{@name}", :default => @name.to_s.humanize) : @name
|
326
131
|
end
|
327
132
|
|
328
133
|
##
|
329
|
-
# Return
|
134
|
+
# Return the path of the project module. If a prefix given will be prepended.
|
330
135
|
#
|
331
|
-
|
332
|
-
@name.to_s.downcase.gsub(/[^a-z0-9]+/, '').gsub(/-+$/, '').gsub(/^-+$/, '').to_sym
|
333
|
-
end
|
334
|
-
|
335
|
-
##
|
336
|
-
# Return ExtJs Config for this project module
|
136
|
+
# ==== Examples
|
337
137
|
#
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
options
|
343
|
-
end
|
344
|
-
end # ProjectModule
|
345
|
-
|
346
|
-
class Menu
|
347
|
-
attr_reader :name, :options, :items, :path
|
348
|
-
|
349
|
-
def initialize(name, path=nil, options={}, &block) #:nodoc:
|
350
|
-
@name = name
|
351
|
-
@path = path
|
352
|
-
@options = options
|
353
|
-
@allowed = []
|
354
|
-
@items = []
|
355
|
-
@allowed << path if path
|
356
|
-
yield self if block_given?
|
357
|
-
end
|
358
|
-
|
359
|
-
##
|
360
|
-
# Add a new submenu to the menu
|
138
|
+
# # => /accounts/new
|
139
|
+
# project_module.path
|
140
|
+
# # => /admin/accounts
|
141
|
+
# project_module.path("/admin")
|
361
142
|
#
|
362
|
-
def
|
363
|
-
|
143
|
+
def path(prefix=nil)
|
144
|
+
prefix ? File.join(prefix, @path) : @path
|
364
145
|
end
|
365
|
-
|
366
|
-
##
|
367
|
-
# Return allowed controllers
|
368
|
-
#
|
369
|
-
def allowed
|
370
|
-
@items.each { |i| @allowed.concat(i.allowed) }
|
371
|
-
@allowed.uniq
|
372
|
-
end
|
373
|
-
|
374
|
-
##
|
375
|
-
# Return the original name or try to translate or humanize the symbol
|
376
|
-
#
|
377
|
-
def human_name
|
378
|
-
@name.is_a?(Symbol) ? I18n.t("admin.menus.#{@name}", :default => @name.to_s.humanize) : @name
|
379
|
-
end
|
380
|
-
|
381
|
-
##
|
382
|
-
# Return ExtJs Config for this menu
|
383
|
-
#
|
384
|
-
def config
|
385
|
-
if @path.blank? && @items.empty?
|
386
|
-
options = human_name
|
387
|
-
else
|
388
|
-
options = @options.merge(:text => human_name)
|
389
|
-
options.merge!(:menu => @items.collect(&:config)) if @items.size > 0
|
390
|
-
options.merge!(:handler => "function(){ Admin.app.load('#{path}') }".to_l) if @path
|
391
|
-
end
|
392
|
-
options
|
393
|
-
end
|
394
|
-
end # Menu
|
146
|
+
end # ProjectModule
|
395
147
|
end # AccessControl
|
396
148
|
end # Admin
|
397
149
|
end # Padrino
|