From 21275e8b7bd25ab33793a3c990b4cd61b9a8226b Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Thu, 12 Nov 2015 17:52:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=A8=A1=E5=9D=97=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E7=BC=BA=E9=99=B7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org_document_comments_controller.rb | 6 ++- app/controllers/organizations_controller.rb | 19 ++++++-- app/models/principal.rb | 16 +++---- app/models/user.rb | 15 ++++++ app/views/org_document_comments/edit.html.erb | 43 ++++++++++++++++++ .../organizations/_show_org_document.html.erb | 4 +- app/views/organizations/setting.html.erb | 18 ++++---- public/images/org_default.jpg | Bin 0 -> 1897 bytes 8 files changed, 96 insertions(+), 25 deletions(-) create mode 100644 app/views/org_document_comments/edit.html.erb create mode 100644 public/images/org_default.jpg diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index d9ed0f1f5..60522dc3f 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -28,13 +28,15 @@ class OrgDocumentCommentsController < ApplicationController end def update @org_document = OrgDocumentComment.find(params[:id]) + @org_document.update_attributes(:title => params[:org_document_comment][:title], :content => params[:org_document_comment][:content]) respond_to do |format| - # format.html {redirect_to :} + format.html {redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id)} end end def edit - + @org_document = OrgDocumentComment.find(params[:id]) + @organization = Organization.find(params[:organization_id]) end def add_reply diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index fbe3814a4..25d0783fb 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -25,10 +25,14 @@ class OrganizationsController < ApplicationController end def show - @organization = Organization.find(params[:id]) - @activities = OrgActivity.where('(org_act_id = ? and org_act_type = ?) || (container_id =? and org_act_type =? and org_act_id !=?)', - @organization.id, 'CreateOrganization ', @organization.id, 'OrgDocumentComment', @organization.home_id).order('updated_at desc') - @activities = paginateHelper @activities, 10 + if User.current.admin? || User.current.member_of_org?(@organization) + @organization = Organization.find(params[:id]) + @activities = OrgActivity.where('(org_act_id = ? and org_act_type = ?) || (container_id =? and org_act_type =? and org_act_id !=?)', + @organization.id, 'CreateOrganization ', @organization.id, 'OrgDocumentComment', @organization.home_id).order('updated_at desc') + @activities = paginateHelper @activities, 10 + else + render_403 + end end def update @@ -61,7 +65,12 @@ class OrganizationsController < ApplicationController end def setting - @organization = Organization.find(params[:id]) + @organization = Organization.find(params[:id]) + + if User.current.admin? || User.current.admin_of_org?(@organization) + else + render_403 + end end diff --git a/app/models/principal.rb b/app/models/principal.rb index fc9c7cac4..dd376f609 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -88,14 +88,14 @@ class Principal < ActiveRecord::Base } scope :not_member_of_org, lambda {|org| - orgs = [org] unless org.is_a?(Array) - if orgs.empty? - where("1=0") - else - ids = orgs.map(&:id) - where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{OrgMember.table_name} WHERE organization_id IN (?))", ids) - end - } + orgs = [org] unless org.is_a?(Array) + if orgs.empty? + where("1=0") + else + ids = orgs.map(&:id) + where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{OrgMember.table_name} WHERE organization_id IN (?))", ids) + end + } scope :sorted, lambda { order(*Principal.fields_for_order_statement)} diff --git a/app/models/user.rb b/app/models/user.rb index 4c6449863..740523707 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -770,6 +770,21 @@ class User < Principal courses.to_a.include?(course) end + def member_of_org?(org) + OrgMember.where("user_id =? and organization_id =?", self.id, org.id).count > 0 + end + + def admin_of_org?(org) + if OrgMember.where("user_id =? and organization_id =?", self.id, org.id).count == 0 + return false + end + role = OrgMember.where("user_id =? and organization_id =?", self.id, org.id)[0].roles[0] + unless role.nil? + role.name == 'orgManager' ? true : false + else + false + end + end def member_of_course_group?(course_group) course_groups.to_a.include?(course_group) end diff --git a/app/views/org_document_comments/edit.html.erb b/app/views/org_document_comments/edit.html.erb new file mode 100644 index 000000000..ffa05ff61 --- /dev/null +++ b/app/views/org_document_comments/edit.html.erb @@ -0,0 +1,43 @@ +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg'%> + +
+
编辑文章
+
+<%= form_tag url_for(:controller => 'org_document_comments',:action => 'update', :id => @org_document.id),:method => 'put', :id => 'new_org_document_form' do |f| %> +
+
+ +
+
+
+
+ <%= kindeditor_tag 'org_document_comment[content]',@org_document.content, :editor_id => 'org_document_description_editor', :height => "150px" %> +
+
+ + +

+
+ +
+ 确定 + + 取消 +
+
+ +
+
+<% end %> \ No newline at end of file diff --git a/app/views/organizations/_show_org_document.html.erb b/app/views/organizations/_show_org_document.html.erb index e9bd6698b..6641ae23d 100644 --- a/app/views/organizations/_show_org_document.html.erb +++ b/app/views/organizations/_show_org_document.html.erb @@ -25,7 +25,9 @@ 设为首页 <% end %> -
  • 编辑文章
  • +
  • + <%= link_to "编辑文章", edit_org_document_comment_path(:id => document.id, :organization_id => document.organization_id), :class => "postOptionLink" %> +
  • <%= link_to "删除文章", org_document_comment_path(:id => document.id, :organization_id => document.organization_id), :method => 'delete',:remote => true, :class => 'postOptionLink' %>
  • diff --git a/app/views/organizations/setting.html.erb b/app/views/organizations/setting.html.erb index e203b5eed..78cd21504 100644 --- a/app/views/organizations/setting.html.erb +++ b/app/views/organizations/setting.html.erb @@ -38,7 +38,7 @@
    - + <%#= form_for( @organization,{:controller => 'organizations',:action => 'update',:id=>@organization,:html=>{:id=>'update_org_form',:method=>'put'}}) do %> <%= labelled_form_for @organization do |f|%> @@ -55,14 +55,14 @@
    -
    组织URL: -
    https:// - - .trustie.net申请 -

    - -
    -
    + + + + + + + +
    公开 : class="ml3" />
    diff --git a/public/images/org_default.jpg b/public/images/org_default.jpg new file m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