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'%> + +