build interface to work with object auth. Go to panel/new_blog/back_end/posts/ ,click New Auth link

This commit is contained in:
Matthew Kaito Juyuan Fu 2012-02-09 19:04:06 +08:00 committed by Christophe Vilayphiou
parent e20739e32b
commit 436f039c1b
6 changed files with 61 additions and 35 deletions

View File

@ -4,14 +4,6 @@ class Admin::ObjectAuthsController < ApplicationController
# before_filter :is_admin? ,:only => :index # before_filter :is_admin? ,:only => :index
def index def index
# @roles = Role.all.entries
# apps = Purchase.where(:type =>"App")
# @app_auth_data = apps.entries.map do |app|
# app_c = eval(app.app_controller)
# obj = app_c.new
# obj_auth = obj.send "auth"
# [:app_obj => app,:auth_field => obj_auth]
# end
# if current_user.admin? # if current_user.admin?
@object_auths = ObjectAuth.all @object_auths = ObjectAuth.all
# else # else
@ -19,25 +11,40 @@ class Admin::ObjectAuthsController < ApplicationController
# end # end
end end
def new
obj = eval(params[:type]).find params[:obj_id]
@object_auth=obj.object_auths.build
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @post }
end
end
def create
obj = eval(params[:object_auth][:type]).find params[:object_auth][:obj_id]
@object_auth=obj.object_auths.create :title=> params[:object_auth][:title]
redirect_to edit_admin_object_auth_path(@object_auth)
end
def create_role def create_role
object_auth = ObjectAuth.find(params[:id]) object_auth = ObjectAuth.find(params[:id])
params[:new].each do |item| params[:new].each do |item|
field = item[0] field = item[0]
field_value = item[1] field_value = item[1]
if field_value!='' if field_value!=''
case field case field
when 'role' when 'role'
object_auth.send("add_#{field}",(Role.find field_value)) rescue nil object_auth.send("add_#{field}",(Role.find field_value)) rescue nil
when 'sub_role' when 'sub_role'
object_auth.send("add_#{field}",(SubRole.find field_value)) rescue nil object_auth.send("add_#{field}",(SubRole.find field_value)) rescue nil
when 'privilege_user' when 'privilege_user'
object_auth.add_user_to_privilege_list (User.find field_value) rescue nil object_auth.add_user_to_privilege_list (User.find field_value) rescue nil
when 'blocked_user' when 'blocked_user'
object_auth.add_user_to_black_list (User.find field_value) rescue nil object_auth.add_user_to_black_list (User.find field_value) rescue nil
end end
end end
end end
redirect_to edit_admin_object_auth_path(object_auth) redirect_to edit_admin_object_auth_path(object_auth)
end end
def remove_role def remove_role

View File

@ -0,0 +1,23 @@
<% content_for :secondary do %>
<ul class="list">
</ul>
<% end -%>
<br/>
<br/>
<br/>
<br/>
<%= flash_messages %>
<h1><%= t('object_auth.new_object_auth') %></h1>
<%= form_for @object_auth, :url => admin_object_auths_path do |f| %>
<%= f.label :title %>
<%= f.text_field :title, :class => 'text' %>
<%= f.hidden_field :obj_id, :value => params[:obj_id] %>
<%= f.hidden_field :type, :value => params[:type] %>
<%= submit_tag 'Add Auth' %><br/>
<% end %>
<%= link_back %>

View File

@ -13,8 +13,11 @@ PrototypeR4::Application.routes.draw do
resources :assets resources :assets
resources :app_auths resources :app_auths
resources :object_auths do resources :object_auths do
collection do
match 'new/:type/:obj_id',:action => 'new',:via => "get",:as => :init
end
member do member do
match ':id/create_role',:action => 'create_role',:iia => "post",:as => :create_role match ':id/create_role',:action => 'create_role',:via => "post",:as => :create_role
match 'remove/:type/:target_id' ,:action=> 'remove_role',:via => "delete",:as =>:remove match 'remove/:type/:target_id' ,:action=> 'remove_role',:via => "delete",:as =>:remove
end end
end end

View File

@ -30,13 +30,5 @@ module OrbitCoreLib
users users
end end
def tell_me_class
self.class.name
end
def search_object_db
ObjectAuth.where(obj_authable_type: self.class.name)
end
end end
end end

View File

@ -21,6 +21,7 @@
<tr> <tr>
<td><%= post.title %></td> <td><%= post.title %></td>
<td><%= truncate(post.body,:length=>15) %></td> <td><%= truncate(post.body,:length=>15) %></td>
<td><%= link_to t('blog.new_auth'), init_admin_object_auths_path("Post",post) %></td>
<td><%= link_to t('blog.show'), panel_new_blog_back_end_post_path(post) %></td> <td><%= link_to t('blog.show'), panel_new_blog_back_end_post_path(post) %></td>
<td><%= link_to t('blog.edit'), edit_panel_new_blog_back_end_post_path(post) %></td> <td><%= link_to t('blog.edit'), edit_panel_new_blog_back_end_post_path(post) %></td>
<td><%= link_to t('blog.delete'), panel_new_blog_back_end_post_path(post), :confirm => t('blog.sure?'), :method => :delete %></td> <td><%= link_to t('blog.delete'), panel_new_blog_back_end_post_path(post), :confirm => t('blog.sure?'), :method => :delete %></td>

View File

@ -7,7 +7,7 @@
<%= flash_messages %> <%= flash_messages %>
<h1><%= t('blog.new_post') %></h1> <h1><%= t('blog.new_post') %></h1>
<%= form_for @post, :url => panel_new_blog_back_end_posts_path do |f| %> <%= form_for @post, :url => panel_new_blog_back_end_posts_path do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %> <%= f.text_field :title, :class => 'text' %>
<% end %> <% end %>
<%= link_back %> <%= link_back %>