Nicolae Claudius
11 years ago
7 changed files with 186 additions and 3 deletions
@ -0,0 +1,10 @@ |
|||||||
|
class AdminAbility |
||||||
|
include CanCan::Ability |
||||||
|
|
||||||
|
def initialize(admin) |
||||||
|
can :access, :rails_admin |
||||||
|
can :manage, :all |
||||||
|
cannot [:ban, :unban], :all |
||||||
|
can [:ban, :unban], User |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,22 @@ |
|||||||
|
<h4> |
||||||
|
<%= t("admin.form.are_you_sure_you_want_to_ban", |
||||||
|
:model_name => @abstract_model.pretty_name.downcase) %> |
||||||
|
“ |
||||||
|
<strong><%= @model_config.with(:object => @object).object_label %></strong> |
||||||
|
” |
||||||
|
<%= t("admin.form.all_of_the_following_related_items_will_be_deleted") %> |
||||||
|
</h4> |
||||||
|
<ul> |
||||||
|
<%= render :partial => "delete_notice", :object => @object %> |
||||||
|
</ul> |
||||||
|
<%= form_for(@object, :url => ban_path(:model_name => @abstract_model.to_param, :id => @object.id), :html => {:method => "patch"}) do %> |
||||||
|
<input name="return_to" type="<%= :hidden %>" value="<%= (params[:return_to].presence || request.referer) %>"></input> |
||||||
|
<div class="form-actions"> |
||||||
|
<button class="btn btn-danger" data-disable-with="<%= t("admin.form.confirmation") %>" type="submit"> |
||||||
|
<i class="icon-white icon-ok"></i> <%= t("admin.form.confirmation") %> |
||||||
|
</button> |
||||||
|
<button class="btn" data-disable-with="<%= t("admin.form.cancel") %>" name="_continue" type="submit"> |
||||||
|
<i class="icon-remove"></i> <%= t("admin.form.cancel") %> |
||||||
|
</button> |
||||||
|
</div> |
||||||
|
<% end %> |
@ -0,0 +1,15 @@ |
|||||||
|
en: |
||||||
|
admin: |
||||||
|
form: |
||||||
|
are_you_sure_you_want_to_ban: "Are you sure you want to ban this %{model_name}" |
||||||
|
actions: |
||||||
|
ban: |
||||||
|
menu: "Ban" |
||||||
|
title: "Ban" |
||||||
|
breadcrumb: "Ban" |
||||||
|
done: "User successfully banned" |
||||||
|
unban: |
||||||
|
menu: "Unban" |
||||||
|
title: "Unban" |
||||||
|
breadcrumb: "Unban" |
||||||
|
done: "User successfully unbanned" |
@ -0,0 +1,57 @@ |
|||||||
|
require 'rails_admin/config/actions' |
||||||
|
require 'rails_admin/config/actions/base' |
||||||
|
|
||||||
|
module RailsAdmin |
||||||
|
module Config |
||||||
|
module Actions |
||||||
|
|
||||||
|
class Ban < RailsAdmin::Config::Actions::Base |
||||||
|
RailsAdmin::Config::Actions.register(self) |
||||||
|
|
||||||
|
register_instance_option :member do |
||||||
|
true |
||||||
|
end |
||||||
|
|
||||||
|
register_instance_option :http_methods do |
||||||
|
[:get, :patch] |
||||||
|
end |
||||||
|
|
||||||
|
register_instance_option :visible? do |
||||||
|
authorized? && bindings[:object].active? |
||||||
|
end |
||||||
|
|
||||||
|
register_instance_option :controller do |
||||||
|
Proc.new do |
||||||
|
if request.get? # BAN |
||||||
|
|
||||||
|
respond_to do |format| |
||||||
|
format.html { render 'ban' } |
||||||
|
format.js { render 'ban', :layout => false } |
||||||
|
end |
||||||
|
|
||||||
|
elsif request.patch? # PATCH |
||||||
|
|
||||||
|
redirect_path = nil |
||||||
|
@auditing_adapter && @auditing_adapter.delete_object(@object, @abstract_model, _current_user) |
||||||
|
if @object.ban! |
||||||
|
flash[:success] = t("admin.flash.successful", :name => @model_config.label, :action => t("admin.actions.ban.done")) |
||||||
|
redirect_path = index_path |
||||||
|
else |
||||||
|
flash[:error] = t("admin.flash.error", :name => @model_config.label, :action => t("admin.actions.ban.done")) |
||||||
|
redirect_path = back_or_index |
||||||
|
end |
||||||
|
|
||||||
|
redirect_to redirect_path |
||||||
|
|
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
register_instance_option :link_icon do |
||||||
|
'icon- fa-ban' |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,33 @@ |
|||||||
|
require 'rails_admin/config/actions' |
||||||
|
require 'rails_admin/config/actions/base' |
||||||
|
|
||||||
|
module RailsAdmin |
||||||
|
module Config |
||||||
|
module Actions |
||||||
|
|
||||||
|
class Unban < RailsAdmin::Config::Actions::Base |
||||||
|
RailsAdmin::Config::Actions.register(self) |
||||||
|
|
||||||
|
register_instance_option :member do |
||||||
|
true |
||||||
|
end |
||||||
|
|
||||||
|
register_instance_option :visible? do |
||||||
|
authorized? && !bindings[:object].active? |
||||||
|
end |
||||||
|
|
||||||
|
register_instance_option :controller do |
||||||
|
Proc.new do |
||||||
|
@object.unban! |
||||||
|
redirect_to back_or_index |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
register_instance_option :link_icon do |
||||||
|
'icon-ok' |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue