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

View File

@ -410,7 +410,7 @@ class ApplicationController < ActionController::Base
if check_permission(:manager)
object.create_user_id != current_user.id
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
else
false

View File

@ -12,13 +12,13 @@ module OrbitBackendHelper
def show_form_status_field(object)
#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
end
def show_approval_link(object)
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
end
@ -279,6 +279,10 @@ module OrbitBackendHelper
if show_approval_link(object)
content_tag :li, link_to(t(quick[:translation] || :approval_), eval("#{quick[:link]}('#{object.id}')"), class: "preview_trigger #{quick[:class]}")
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'
if authorization || approvable
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">
<% @module_apps.each do |module_app| %>
<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>
<% end %>
</ul>
@ -14,12 +14,14 @@
</div>
<div class="mini-layout-body span10">
<%= link_to t(:module_authorization), admin_authorizations_path(@module_app.key) %>
<%= link_to t(:category_auth), admin_authorizations_path(@module_app.key, type: 'category') %>
<%= link_to t(:approval_), admin_authorizations_path(@module_app.key, type: 'approval') %>
<% @module_app.authorizable_models.each do |authorizable_model| %>
<%= 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 %>
<%= @error %>
<% 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">
<%= render partial: 'user', collection: @users %>
</ul>
@ -30,7 +32,7 @@
<!-- footer -->
<div class="bottomnav clearfix">
<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: "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: "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, @object) %>
</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();

View File

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

View File

@ -53,7 +53,7 @@ namespace :new_ui do
when 'fact_check'
new_object_auth = new_category.get_object_auth_by_title("approval_#{module_app.key}")
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
object_auth.auth_users.each do |user|
new_object_auth.add_user_to_privilege_list(user)
@ -85,4 +85,10 @@ namespace :new_ui do
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