Change authorization to accept other than category

This commit is contained in:
chris 2013-07-25 17:36:55 +08:00
parent 0c208d0020
commit da1d70efcb
7 changed files with 60 additions and 52 deletions

View File

@ -5,27 +5,26 @@ class Admin::AuthorizationsController < OrbitBackendController
def index def index
@module_apps ||= ModuleApp.where(is_authorizable: true).order_by([:title, :asc]) @module_apps ||= ModuleApp.where(is_authorizable: true).order_by([:title, :asc])
if @module_apps && @module_apps.include?(@module_app) if @module_apps && @module_apps.include?(@module_app)
if @type
case @type case @type
when 'category' when 'category', 'approval'
type = 'submit' if @module_app.has_category
when 'approval' @objects = @module_app.categories
type = 'fact_check' else
@error = t(:no_category)
end
else
@objects = @klass.all
end
unless @objects.blank?
@object ||= @objects.first
@users = @object.get_object_auth_by_title("#{@type}_#{@module_app.key}").auth_users
else
@error = t(:no_data)
end
else else
@users = @module_app.managing_users @users = @module_app.managing_users
end end
if type
if @module_app.has_category
@categories = @module_app.categories
unless @categories.blank?
@category ||= @categories.first
@users = @category.get_object_auth_by_title("#{type}_#{@module_app.key}").auth_users
else
@error = t(:no_category)
end
else
@error = t(:no_category)
end
end
elsif @module_apps elsif @module_apps
@module_app = @module_apps.first @module_app = @module_apps.first
redirect_to admin_authorizations_url(@module_app.key) redirect_to admin_authorizations_url(@module_app.key)
@ -36,21 +35,15 @@ class Admin::AuthorizationsController < OrbitBackendController
def add(users) def add(users)
unless users.blank? unless users.blank?
case @type if @type
when 'category' if @object
type = 'submit' object_auth = @object.get_object_auth_by_title("#{@type}_#{@module_app.key}")
when 'approval'
type = 'fact_check'
else
add_managers(users) unless users.blank?
end
if type
if @category
object_auth = @category.get_object_auth_by_title("#{type}_#{@module_app.key}")
add_users_to_object_auth(object_auth, users) add_users_to_object_auth(object_auth, users)
else else
@error = t(:no_category) @error = t(:no_data)
end end
else
add_managers(users) unless users.blank?
end end
end end
@users = users @users = users
@ -74,9 +67,8 @@ class Admin::AuthorizationsController < OrbitBackendController
def modal_select def modal_select
existing_users = User.find(params[:ids]) rescue [] existing_users = User.find(params[:ids]) rescue []
roles = Role.all roles = Role.all
case @type if @type
when 'category', 'approval' @object_id = @object.id if @object
@category_id = @category.id if @category
@sorted_users = roles.inject({}) do |users, role| @sorted_users = roles.inject({}) do |users, role|
users[role] = role.users.where(admin: false).not_guest_user - existing_users - @module_app.managing_users users[role] = role.users.where(admin: false).not_guest_user - existing_users - @module_app.managing_users
users users
@ -92,18 +84,16 @@ class Admin::AuthorizationsController < OrbitBackendController
def remove_users def remove_users
@users = User.find(params[:ids]) rescue [] @users = User.find(params[:ids]) rescue []
unless @users.blank? unless @users.blank?
case @type if @type
when 'category' if @object
type = 'submit' object_auth = @object.get_object_auth_by_title("#{@type}_#{@module_app.key}")
when 'approval' remove_users_form_object_auth(object_auth, @users)
type = 'fact_check' else
@error = t(:no_data)
end
else else
remove_managers(@users) remove_managers(@users)
end end
if type
object_auth = @category.get_object_auth_by_title("#{type}_#{@module_app.key}")
remove_users_form_object_auth(object_auth, @users)
end
end end
render 'admin/authorizations/remove_users' render 'admin/authorizations/remove_users'
end end
@ -144,8 +134,11 @@ class Admin::AuthorizationsController < OrbitBackendController
def setup_vars def setup_vars
@module_app = ModuleApp.first(conditions: {:key => params[:module]} ) if params[:module] @module_app = ModuleApp.first(conditions: {:key => params[:module]} ) if params[:module]
@category = Category.find(params[:id]) rescue nil @type = params[:type].underscore if params[:type]
@type = params[:type] if @type
@klass = @type.classify.constantize
@object = @klass.find(params[:id]) rescue nil
end
end end
def user_is_manager? def user_is_manager?

View File

@ -410,7 +410,7 @@ class ApplicationController < ActionController::Base
if check_permission(:manager) if check_permission(:manager)
object.create_user_id != current_user.id object.create_user_id != current_user.id
else else
!object.category.authed_users('fact_check').include?(current_user) rescue false !object.category.authed_users("approval_#{@module_app.key}").include?(current_user) rescue false
end end
else else
false false

View File

@ -12,13 +12,13 @@ module OrbitBackendHelper
def show_form_status_field(object) def show_form_status_field(object)
#by_object = (!object.is_expired? and object.is_pending?) #by_object = (!object.is_expired? and object.is_pending?)
by_user = ((object.category.authed_users("fact_check_#{@module_app.key}").include?(current_user) rescue nil) or is_manager? or is_admin?) by_user = ((object.category.authed_users("approval_#{@module_app.key}").include?(current_user) rescue nil) or is_manager? or is_admin?)
by_user by_user
end end
def show_approval_link(object) def show_approval_link(object)
by_object = (!object.is_expired? and object.is_pending?) by_object = (!object.is_expired? and object.is_pending?)
by_user = ((object.category.authed_users("fact_check_#{@module_app.key}").include?(current_user) rescue nil) or is_manager? or is_admin?) by_user = ((object.category.authed_users("approval_#{@module_app.key}").include?(current_user) rescue nil) or is_manager? or is_admin?)
by_object and by_user by_object and by_user
end end
@ -279,6 +279,10 @@ module OrbitBackendHelper
if show_approval_link(object) if show_approval_link(object)
content_tag :li, link_to(t(quick[:translation] || :approval_), eval("#{quick[:link]}('#{object.id}')"), class: "preview_trigger #{quick[:class]}") content_tag :li, link_to(t(quick[:translation] || :approval_), eval("#{quick[:link]}('#{object.id}')"), class: "preview_trigger #{quick[:class]}")
end end
when 'authorization'
if authorization
content_tag :li, link_to(t(quick[:translation] || :authorization_), eval("#{quick[:link]}"), class: "preview_trigger #{quick[:class]}")
end
when 'edit' when 'edit'
if authorization || approvable if authorization || approvable
content_tag :li, link_to(t(quick[:translation] || :edit), eval("#{quick[:link]}('#{object.id}')"), class: quick[:class]) content_tag :li, link_to(t(quick[:translation] || :edit), eval("#{quick[:link]}('#{object.id}')"), class: quick[:class])

View File

@ -5,7 +5,7 @@
<ul class="nav nav-pills nav-stacked"> <ul class="nav nav-pills nav-stacked">
<% @module_apps.each do |module_app| %> <% @module_apps.each do |module_app| %>
<li class="<%= @module_app == module_app ? 'active' : '' %>"> <li class="<%= @module_app == module_app ? 'active' : '' %>">
<%= link_to content_tag(:i, nil, class: (module_app.get_registration.get_icon_class rescue nil)) + ' ' + module_app.title, admin_authorizations_path(module_app.key, @type) %> <%= link_to content_tag(:i, nil, class: (module_app.get_registration.get_icon_class rescue nil)) + ' ' + module_app.title, admin_authorizations_path(module_app.key, (@type if module_app.authorizable_models.include?(@type.camelize))) %>
</li> </li>
<% end %> <% end %>
</ul> </ul>
@ -14,12 +14,14 @@
</div> </div>
<div class="mini-layout-body span10"> <div class="mini-layout-body span10">
<%= link_to t(:module_authorization), admin_authorizations_path(@module_app.key) %> <%= link_to t(:module_authorization), admin_authorizations_path(@module_app.key) %>
<%= link_to t(:category_auth), admin_authorizations_path(@module_app.key, type: 'category') %> <% @module_app.authorizable_models.each do |authorizable_model| %>
<%= link_to t(:approval_), admin_authorizations_path(@module_app.key, type: 'approval') %> <%= link_to (authorizable_model.eql?('Category') ? t(:category_auth) : "#{authorizable_model.underscore.humanize} #{t(:authorization_)}"), admin_authorizations_path(@module_app.key, type: authorizable_model) %>
<% end %>
<%= link_to t(:approval_), admin_authorizations_path(@module_app.key, type: 'approval') if @module_app.is_approvable %>
<% if @error %> <% if @error %>
<%= @error %> <%= @error %>
<% else %> <% else %>
<%= select_tag :category, options_from_collection_for_select(@categories, "id", "title", @category.id), :onchange => "window.location.href = '/admin/authorizations/'+'#{@module_app.key}/#{@type}/'+$(this).val();" if @categories %> <%= select_tag @type.underscore.humanize, options_from_collection_for_select(@objects, "id", "title", @object.id), :onchange => "window.location.href = '/admin/authorizations/'+'#{@module_app.key}/#{@type}/'+$(this).val();" if @objects %>
<ul id="card-list" class="checkbox-card clearfix"> <ul id="card-list" class="checkbox-card clearfix">
<%= render partial: 'user', collection: @users %> <%= render partial: 'user', collection: @users %>
</ul> </ul>
@ -30,7 +32,7 @@
<!-- footer --> <!-- footer -->
<div class="bottomnav clearfix"> <div class="bottomnav clearfix">
<div class="action pull-right"> <div class="action pull-right">
<%= link_to content_tag(:i, nil, class: "icons-plus") + ' ' + t(:add), '#', class: 'btn btn-primary select_user_modal', rel: admin_modal_select_authorizations_path(@module_app.key, @type, @category) %> <%= link_to content_tag(:i, nil, class: "icons-plus") + ' ' + t(:add), '#', class: 'btn btn-primary select_user_modal', rel: admin_modal_select_authorizations_path(@module_app.key, @type, @object) %>
<%= link_to content_tag(:i, nil, class: "icon-trash") + ' ' + t(:delete), '#', id: 'remove_users', class: 'btn btn-danger', rel: admin_remove_users_authorizations_path(@module_app.key, @type, @category) %> <%= link_to content_tag(:i, nil, class: "icon-trash") + ' ' + t(:delete), '#', id: 'remove_users', class: 'btn btn-danger', rel: admin_remove_users_authorizations_path(@module_app.key, @type, @object) %>
</div> </div>
</div> </div>

View File

@ -1,2 +1,2 @@
$("#select_user").html("<%= j render partial: 'admin/member_selects/modal_select', locals: {role_form_url: admin_add_roles_authorizations_path(@module_app.key, @type, @category_id), user_form_url: admin_add_users_authorizations_path(@module_app.key, @type, @category_id)} %>"); $("#select_user").html("<%= j render partial: 'admin/member_selects/modal_select', locals: {role_form_url: admin_add_roles_authorizations_path(@module_app.key, @type, @object_id), user_form_url: admin_add_users_authorizations_path(@module_app.key, @type, @cobject_id)} %>");
$("#member-filter").modal(); $("#member-filter").modal();

View File

@ -5,6 +5,7 @@ en:
add_to_default: Add to default add_to_default: Add to default
alternative: Alternative alternative: Alternative
approval_setting: Approval Setting approval_setting: Approval Setting
authorization_: Authorization
change: Change change: Change
change_file: Change file change_file: Change file
create: create:
@ -31,8 +32,10 @@ en:
next: Next next: Next
no_app: No module no_app: No module
no_category: No Available Category no_category: No Available Category
no_data: No data
no_date: No date no_date: No date
no_file: No file no_file: No file
path: Path
previous: Previous previous: Previous
remove: Remove remove: Remove
remove_default: Remove default remove_default: Remove default

View File

@ -53,7 +53,7 @@ namespace :new_ui do
when 'fact_check' when 'fact_check'
new_object_auth = new_category.get_object_auth_by_title("approval_#{module_app.key}") new_object_auth = new_category.get_object_auth_by_title("approval_#{module_app.key}")
else else
new_object_auth = new_category.get_object_auth_by_title("submit_#{module_app.key}") new_object_auth = new_category.get_object_auth_by_title("category_#{module_app.key}")
end end
object_auth.auth_users.each do |user| object_auth.auth_users.each do |user|
new_object_auth.add_user_to_privilege_list(user) new_object_auth.add_user_to_privilege_list(user)
@ -85,4 +85,10 @@ namespace :new_ui do
end end
end end
task :change_auth_naming => :environment do
ObjectAuth.where(title: /submit_/).each do |auth|
auth.update_attribute(:title, auth.title.gsub('submit_', 'category_'))
end
end
end end