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 mode 100644 index 000000000..ad1b4f007 Binary files /dev/null and b/public/images/org_default.jpg differ