From 893313741f9ab324336fd08d7379b7ba72d2c8b6 Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 1 Aug 2014 12:22:47 +0800 Subject: [PATCH] add authorization --- app/controllers/admin/diplomas_controller.rb | 7 +++++-- app/views/admin/diplomas/_diploma.html.erb | 1 + app/views/admin/diplomas/_form.html.erb | 1 + app/views/admin/diplomas/index.html.erb | 7 ++++--- .../plugin/personal_diploma/_profile.html.erb | 17 +++++++++-------- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/controllers/admin/diplomas_controller.rb b/app/controllers/admin/diplomas_controller.rb index 6e4054d..ea9bf7e 100644 --- a/app/controllers/admin/diplomas_controller.rb +++ b/app/controllers/admin/diplomas_controller.rb @@ -4,6 +4,9 @@ class Admin::DiplomasController < OrbitMemberController before_action :set_plugin before_action :get_settings,:only => [:new, :edit, :setting] + before_action :need_access_right + before_action :allow_admin_only, :only => [:index, :setting] + def index @diplomas = Diploma.order_by(:end_date=>'desc',:start_date=>'desc').page(params[:page]).per(10) end @@ -17,7 +20,7 @@ class Admin::DiplomasController < OrbitMemberController @member = MemberProfile.find(diploma_params['member_profile_id']) rescue nil @diploma = Diploma.new(diploma_params) @diploma.save - redirect_to URI.encode('/admin/members/'+@member.to_param+'/Diploma') + redirect_to params['referer_url'] end def edit @@ -30,7 +33,7 @@ class Admin::DiplomasController < OrbitMemberController @diploma = Diploma.find(params[:id]) @diploma.update_attributes(diploma_params) @diploma.save - redirect_to URI.encode('/admin/members/'+@member.to_param+'/Diploma') + redirect_to params['referer_url'] end def destroy diff --git a/app/views/admin/diplomas/_diploma.html.erb b/app/views/admin/diplomas/_diploma.html.erb index 4c11752..14c6019 100644 --- a/app/views/admin/diplomas/_diploma.html.erb +++ b/app/views/admin/diplomas/_diploma.html.erb @@ -1,5 +1,6 @@ <% @diplomas.each do |diploma| %> "> + <%= diploma.member_profile.name %> <%= diploma.duration %> <%= link_to diploma.school_name, OrbitHelper.url_to_plugin_show(diploma.to_param,'personal_diploma'), target: "blank"%> diff --git a/app/views/admin/diplomas/_form.html.erb b/app/views/admin/diplomas/_form.html.erb index 83d2e86..d2baf33 100644 --- a/app/views/admin/diplomas/_form.html.erb +++ b/app/views/admin/diplomas/_form.html.erb @@ -177,6 +177,7 @@
<%= f.hidden_field :user_id, :value => params[:user_id] if !params[:user_id].blank? %> + <%= f.submit t('submit'), class: 'btn btn-primary' %> <%= link_to t('cancel'), get_go_back, :class=>"btn" %>
\ No newline at end of file diff --git a/app/views/admin/diplomas/index.html.erb b/app/views/admin/diplomas/index.html.erb index a365c30..10c7d70 100644 --- a/app/views/admin/diplomas/index.html.erb +++ b/app/views/admin/diplomas/index.html.erb @@ -1,10 +1,11 @@ - + + - - + + diff --git a/app/views/plugin/personal_diploma/_profile.html.erb b/app/views/plugin/personal_diploma/_profile.html.erb index ef14752..6089f6e 100644 --- a/app/views/plugin/personal_diploma/_profile.html.erb +++ b/app/views/plugin/personal_diploma/_profile.html.erb @@ -6,15 +6,14 @@ <% end %> <% - is_autorized_user = (current_user==@member.user || current_user.is_admin?) - if is_autorized_user + if has_access? @diplomas = Diploma.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) else @diplomas = Diploma.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) end %> -<% if is_autorized_user %> +<% if has_access? %>
<%= link_to('Hide', '#', :class => "btn btn-mini list-active-btn disabled", "data-check-action" => "list-be-hide", :rel => toggle_hide_admin_diplomas_path(member_profile_id: params[:id], disable: 'true') ) %> @@ -26,7 +25,7 @@
<%= t('date_') %><%= t('users.name') %><%= t('personal_diploma.duration') %> <%= t('personal_diploma.school_name') %><%= t('personal_diploma.department') %><%= t('personal_diploma.degree') %><%= t('personal_diploma.department') %><%= t('personal_diploma.degree') %>
- <% if is_autorized_user %> + <% if has_access? %> <% end -%> @@ -38,7 +37,7 @@ <% @diplomas.each do |diploma| %> "> - <% if is_autorized_user %> + <% if has_access? %> @@ -48,8 +47,10 @@ <%= link_to diploma.school_name, OrbitHelper.url_to_plugin_show(diploma.to_param,'personal_diploma'), target: "blank"%>
@@ -62,7 +63,7 @@
- <% if is_autorized_user %> + <% if has_access? %>
<%= link_to content_tag(:i, nil, :class => 'icon-edit') +' '+ t('setting'),'/admin/members/'+@member.to_param+'/diplomas/frontend_setting', :class => 'btn btn-primary' %> <%= link_to content_tag(:i, nil, :class => 'icon-plus') +' '+ t('new_'),
<%= t('date_') %>
<%= check_box_tag 'to_change[]', diploma.id.to_s, false, :class => "list-check" %>