diff --git a/app/assets/javascripts/org_document_comment.js.coffee b/app/assets/javascripts/org_document_comment.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/org_document_comment.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/org_member.js.coffee b/app/assets/javascripts/org_member.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/org_member.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/org_projects.js.coffee b/app/assets/javascripts/org_projects.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/org_projects.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/organizations.js.coffee b/app/assets/javascripts/organizations.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/organizations.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/org_document_comment.css.scss b/app/assets/stylesheets/org_document_comment.css.scss new file mode 100644 index 000000000..9359415ae --- /dev/null +++ b/app/assets/stylesheets/org_document_comment.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the org_document_comment controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/org_member.css.scss b/app/assets/stylesheets/org_member.css.scss new file mode 100644 index 000000000..4bab7e008 --- /dev/null +++ b/app/assets/stylesheets/org_member.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the OrgMember controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/org_projects.css.scss b/app/assets/stylesheets/org_projects.css.scss new file mode 100644 index 000000000..12f4fef6a --- /dev/null +++ b/app/assets/stylesheets/org_projects.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the org_projects controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/organizations.css.scss b/app/assets/stylesheets/organizations.css.scss new file mode 100644 index 000000000..39819880e --- /dev/null +++ b/app/assets/stylesheets/organizations.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the organizations controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index dd8dc84c4..cbbf36ea8 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -374,30 +374,29 @@ class FilesController < ApplicationController if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') Mailer.run.attachments_added(attachments[:files]) end - - if params[:course_attachment_type] && params[:course_attachment_type] != "5" - case params[:course_attachment_type] - when "1" - tag_name = l(:label_courseware) - when "2" - tag_name = l(:label_software) - when "3" - tag_name = l(:label_media) - when "4" - tag_name = l(:label_code) - when "6" - tag_name = "论文" - else - tag_name = "" + if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) + params[:course_attachment_type].each do |type| + tag_name = get_tag_name_by_type_number type + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end + end end - if !attachments.empty? && attachments[:files] && tag_name != "" - attachments[:files].each do |attachment| - attachment.tag_list.add(tag_name) - attachment.save + else + if params[:course_attachment_type] && params[:course_attachment_type] != "5" + tag_name = get_tag_name_by_type_number params[:course_attachment_type] + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end end end end + # TODO: 临时用 nyan sort_init 'created_on', 'desc' sort_update 'created_on' => "#{Attachment.table_name}.created_on", @@ -424,6 +423,23 @@ class FilesController < ApplicationController end end + def get_tag_name_by_type_number type + case type + when "1" + tag_name = l(:label_courseware) + when "2" + tag_name = l(:label_software) + when "3" + tag_name = l(:label_media) + when "4" + tag_name = l(:label_code) + when "6" + tag_name = "论文" + else + tag_name = "" + end + end + def tag_saveEx @tags = params[:tag_name][:name] @obj_id = params[:object_id] diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 5d83c1320..be2b44c06 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -74,10 +74,10 @@ class NewsController < ApplicationController @q = params[:subject] if params[:subject].nil? || params[:subject].blank? scope_order = scope.all(:include => [:author, :course], - :order => "#{News.table_name}.created_on DESC") + :order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC") else scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").all(:include => [:author, :course], - :order => "#{News.table_name}.created_on DESC") + :order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC") end # :offset => @offset, diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb new file mode 100644 index 000000000..60522dc3f --- /dev/null +++ b/app/controllers/org_document_comments_controller.rb @@ -0,0 +1,63 @@ +class OrgDocumentCommentsController < ApplicationController + before_filter :find_organization, :only => [:new, :create, :show, :index] + + layout 'base_org' + + def new + @org_document_comment = OrgDocumentComment.new + end + + def create + @org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id) + @org_document_comment.title = params[:org_document_comment][:title] + @org_document_comment.content = params[:org_document_comment][:content] + if @org_document_comment.save + #flash[:notice] = 'success' + OrgActivity + redirect_to organization_org_document_comments_path(@organization) + else + redirect_to new_org_document_comment_path(:organization_id => @organization.id) + end + end + def show + + end + + def index + @documents = @organization.org_document_comments.where("parent_id is null").order("created_at desc") + 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 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 + @document = OrgDocumentComment.find(params[:id]).root + @comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id]) + @comment.content = params[:org_content] + @document.children << @comment + @document.save + end + + def find_organization + @organization = Organization.find(params[:organization_id]) + end + + def destroy + @org_document_comment = OrgDocumentComment.find(params[:id]) + org = @org_document_comment.organization + if @org_document_comment.destroy + if @org_document_comment.id == org.id + org.home_id == nil + end + end + end +end diff --git a/app/controllers/org_member_controller.rb b/app/controllers/org_member_controller.rb new file mode 100644 index 000000000..4b842f9dc --- /dev/null +++ b/app/controllers/org_member_controller.rb @@ -0,0 +1,57 @@ +class OrgMemberController < ApplicationController + + def org_member_autocomplete + @org = Organization.find(params[:org]) + @flag = params[:flag] || false + respond_to do |format| + format.js + end + end + + def create + @org = Organization.find(params[:org]) + if params[:membership].nil? + @fail_hint = l(:label_blank_user_lists_for_org) + else + member_ids = params[:membership][:user_ids] + role_id = params[:orgRole] + member_ids.each do |user_id| + member = OrgMember.create(:user_id=>user_id) + @org.org_members << member + OrgMemberRole.create(:org_member_id => member.id, :role_id => role_id) + end + end + respond_to do |format| + format.js + end + end + + def update + @member = OrgMember.find(params[:id]) + #@member.change_role params[:org_member][:role_ids] + @member_role = @member.org_member_roles[0] + @member_role.role_id = params[:org_member][:role_ids][0] + @member_role.save + @org = @member.organization + respond_to do |format| + format.js + end + end + + def new + + end + + def destroy + member = OrgMember.find(params[:id]) + @org = member.organization + member.destroy + respond_to do |format| + format.js + end + end + + def index + + end +end diff --git a/app/controllers/org_projects_controller.rb b/app/controllers/org_projects_controller.rb new file mode 100644 index 000000000..733df95b7 --- /dev/null +++ b/app/controllers/org_projects_controller.rb @@ -0,0 +1,31 @@ +class OrgProjectsController < ApplicationController + def create + org_ids = params[:orgNames] + @project = Project.find(params[:project_id]) + org_ids.each do |org_id| + OrgProject.create(:organization_id => org_id.to_i, :project_id => params[:project_id].to_i, :created_at => Time.now) + p 1 + end + respond_to do |format| + format.js + end + end + def destroy + @project = Project.find(params[:project_id]) + @org_project = OrgProject.find(params[:id]) + @org_project.destroy + + condition = '%%' + project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:project_id]}").map(&:organization_id) + if project_org_ids.empty? + @orgs_not_in_project = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page( 1).per(10) + @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count + else + project_org_ids = "(" + project_org_ids.join(',') + ")" + @orgs_not_in_project = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page( 1).per(10) + @org_count = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count + end + # @project_count = Project.project_entities.visible.like(params[:name]).page(params[:page]).count + @orgs_page = Paginator.new @org_count, 10,1 + end +end diff --git a/app/controllers/organization_controller.rb b/app/controllers/organization_controller.rb deleted file mode 100644 index 748fc1732..000000000 --- a/app/controllers/organization_controller.rb +++ /dev/null @@ -1,55 +0,0 @@ -class OrganizationController < ApplicationController - # layout 'base_projects' - before_filter :require_admin, :except => [:index] - - def index - #@projects = Project.find_by_sql("SELECT * FROM projects WHERE id IN (select MAX(id) from projects GROUP BY enterprise_name)") - @organizations = Organization.all - respond_to do |format| - format.html - end - end - - def new - @organizations = Organization.new - respond_to do |format| - format.html - end - end - - def create - @organizations = Organization.new - @organizations.name = params[:organization][:name] - if @organizations.save - redirect_to admin_organization_url - end - end - - def edit - @organization = Organization.find params[:id] - respond_to do |format| - format.html - end - rescue Exception => e - render_404 - end - - def update - @organization = Organization.find params[:id] - @organization.name = params[:organization][:name] - if @organization.save - redirect_to admin_organization_url - end - rescue Exception => e - render_404 - end - - def destroy - @organization = Organization.find params[:id] - if @organization.destroy - redirect_to admin_organization_url - end - rescue Exception => e - render_404 - end -end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb new file mode 100644 index 000000000..b75742164 --- /dev/null +++ b/app/controllers/organizations_controller.rb @@ -0,0 +1,149 @@ +# encoding: utf-8 +class OrganizationsController < ApplicationController + + + helper :sort + include SortHelper + helper :custom_fields + include CustomFieldsHelper + include AvatarHelper + include WordsHelper + include GitlabHelper + include UserScoreHelper + + include PollHelper + helper :user_score + helper :journals + + # added by liuping 关注 + + helper :watchers + helper :activities + + ### added by william + include ActsAsTaggableOn::TagsHelper + + # fq + helper :words + helper :project_score + helper :issues + include UsersHelper + before_filter :find_organization, :only => [:show, :members] + layout 'base_org' + def index + + end + def new + @organization = Organization.new + render :layout => 'new_base' + end + def create + @organization = Organization.new + @organization.name = params[:organization][:name] + @organization.description = params[:organization][:description] + @organization.is_public = params[:organization][:is_public] + @organization.creator_id = User.current.id + member = OrgMember.new(:user_id => User.current.id) + + @organization.org_members << member + if @organization.save + OrgMemberRole.create(:org_member_id => member.id, :role_id => 11) + redirect_to organization_path(@organization) + end + end + + def show + if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) + @organization = Organization.find(params[:id]) + @org_activities = OrgActivity.where('container_id =? and container_type =? ', + @organization.id, 'Organization ').order('updated_at desc').page(params[:page]).per(10) + @org_activities_count = OrgActivity.where('container_id =? and container_type =? ', + @organization.id, 'Organization ').order('updated_at desc').count + project_ids = @organization.projects.map(&:id) << 0 + @org_project_activties = ForgeActivity.where("project_id in (#{project_ids.join(',')}) and forge_act_type in('Issue','Message','ProjectCreateInfo')").order("updated_at desc").page(params[:page] || 1).per(10) + @org_project_activties_count = ForgeActivity.where('project_id in (?)',project_ids.join(',')).count + #@org_activities = paginateHelper @org_activities, 10 + @page = params[:page] + else + render_403 + end + respond_to do |format| + format.html + format.js + end + end + + def update + @organization = Organization.find(params[:id]) + @organization.name = params[:organization][:name] + @organization.description = params[:organization][:description] + @organization.domain = params[:organization][:domain] + @organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0 + #@organization.name = params[:organization][:name] + @organization.save + respond_to do |format| + format.html { redirect_to setting_organization_path(@organization)} + end + end + + def check_uniq + @check = false; + @org_name = params[:org_name].strip + @config_page = params[:config_page] + sameName = @config_page ? Organization.where('name = ? and id != ?',params[:org_name],params[:org_id].to_i).count == 0 : Organization.where('name = ?',params[:org_name]).count == 0 + if sameName == true + @check = true + end + respond_to do |format| + format.js + end + end + + def find_organization + @organization = Organization.find(params[:id]) + end + + def setting + @organization = Organization.find(params[:id]) + + if User.current.admin? || User.current.admin_of_org?(@organization) + else + render_403 + end + end + + + def clear_org_avatar_temp + + end + + def set_homepage + @org = Organization.find(params[:id]) + @org.home_id = params[:home_id] + @org.save + # respond_to do |format| + # format.html {redirect_to organization_path(org)} + # end + end + + def autocomplete_search + @project = Project.find(params[:project_id]) + #@flag = params[:flag] || false + respond_to do |format| + format.js + end + end + + def members + @members = OrgMember.where("organization_id =?", @organization.id) + end + + def more_org_projects + @organization = Organization.find params[:id] + @page = params[:page] + @org_projects = @organization.org_projects.reorder('created_at').page((params[:page].to_i || 1) +1).per(5) + respond_to do |format| + format.js + end + end +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 065adf596..baa7db060 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -69,6 +69,29 @@ class ProjectsController < ApplicationController ### added by william include ActsAsTaggableOn::TagsHelper + #查找组织 + def search_public_orgs_not_in_project + condition = '%%' + if !params[:name].nil? + condition = "%#{params[:name].strip}%".gsub(" ","") + end + project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:id]}").map(&:organization_id) + if project_org_ids.empty? + @orgs_not_in_project = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(10) + @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count + else + project_org_ids = "(" + project_org_ids.join(',') + ")" + @orgs_not_in_project = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(10) + @org_count = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count + end + # @project_count = Project.project_entities.visible.like(params[:name]).page(params[:page]).count + @orgs_page = Paginator.new @org_count, 10,params[:page] + #render :json => {:orgs => @orgs_not_in_project, :count => @org_count}.to_json + respond_to do |format| + format.js + end + end + def index render_404 end @@ -338,6 +361,15 @@ class ProjectsController < ApplicationController @wiki ||= @project.wiki @select_tab = params[:tab] + #找出所有不属于项目的公共组织 + project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{@project.id}") + if project_org_ids.empty? + @orgs_not_in_project = Organization.where("is_public = 1") + else + project_org_ids = "(" + project_org_ids.join(',') + ")" + @orgs_not_in_project = Organization.where("id not in #{project_org_ids} and is_public = 1") + end + # 处理从新建版本库返回来的错误信息 if !params[:repository_error_message].to_s.blank? html = "" @@ -833,5 +865,4 @@ class ProjectsController < ApplicationController end #gcmend - end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0d9588d24..273d48ccf 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1910,6 +1910,14 @@ class UsersController < ApplicationController end end + def user_organizations + @user = User.current + @orgs = @user.organizations + respond_to do |format| + format.html {render :layout => 'static_base'} + end + end + private def find_user diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e5cd9b52b..e08259b11 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -48,6 +48,15 @@ module ApplicationHelper end end end + # 获取组织成员中文名字 + def get_org_member_role_name member + case member.roles[0].name + when 'orgManager' + '管理人员' + when 'orgMember' + '组织成员' + end + end # Time 2015-03-24 16:38:05 # Author lizanle diff --git a/app/helpers/org_document_comment_helper.rb b/app/helpers/org_document_comment_helper.rb new file mode 100644 index 000000000..b430114f2 --- /dev/null +++ b/app/helpers/org_document_comment_helper.rb @@ -0,0 +1,2 @@ +module OrgDocumentCommentHelper +end diff --git a/app/helpers/org_member_helper.rb b/app/helpers/org_member_helper.rb new file mode 100644 index 000000000..fd70a0516 --- /dev/null +++ b/app/helpers/org_member_helper.rb @@ -0,0 +1,16 @@ +module OrgMemberHelper + include ApplicationHelper + def find_user_not_in_current_org_by_name org + if params[:q] && params[:q].lstrip.rstrip != "" + scope = Principal.active.sorted.not_member_of_org(org).like(params[:q]) + else + scope = [] + end + principals = paginateHelper scope,10 + s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals') + links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options| + link_to text, org_member_autocomplete_org_member_index_path(parameters.merge(:q => params[:q],:flag => true,:org=> org, :format => 'js')), :remote => true + } + s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" ) + end +end diff --git a/app/helpers/org_projects_helper.rb b/app/helpers/org_projects_helper.rb new file mode 100644 index 000000000..f3a7025bd --- /dev/null +++ b/app/helpers/org_projects_helper.rb @@ -0,0 +1,2 @@ +module OrgProjectsHelper +end diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index 10321ba16..607d2af5c 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -1,2 +1,22 @@ -module EnterprisesHelper +# encoding: utf-8 +module OrganizationsHelper + include ApplicationHelper + + + def find_user_not_in_current_org_by_name org + if params[:q] && params[:q].lstrip.rstrip != "" + scope = Principal.active.sorted.not_member_of_org(org).like(params[:q]) + else + scope = [] + end + principals = paginateHelper scope,10 + s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals') + links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options| + link_to text, org_member_autocomplete_org_member_index_path( parameters.merge(:q => params[:q],:flag => true,:org=>org, :format => 'js')), :remote => true + } + s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" ) + end + + + end diff --git a/app/models/news.rb b/app/models/news.rb index a9e9d1d18..e9b8b5314 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -66,7 +66,7 @@ class News < ActiveRecord::Base scope :course_visible, lambda {|*args| includes(:course).where(Course.allowed_to_condition(args.shift || User.current, :view_course_news, *args)) } - safe_attributes 'title', 'summary', 'description' + safe_attributes 'title', 'summary', 'description', 'sticky' def visible?(user=User.current) !user.nil? && user.allowed_to?(:view_news, project) diff --git a/app/models/org_activity.rb b/app/models/org_activity.rb new file mode 100644 index 000000000..c48ebdf8e --- /dev/null +++ b/app/models/org_activity.rb @@ -0,0 +1,5 @@ +class OrgActivity < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :org_act ,:polymorphic => true + belongs_to :container,:polymorphic => true +end diff --git a/app/models/org_document_comment.rb b/app/models/org_document_comment.rb new file mode 100644 index 000000000..2b3c9132a --- /dev/null +++ b/app/models/org_document_comment.rb @@ -0,0 +1,16 @@ +class OrgDocumentComment < ActiveRecord::Base + attr_accessible :content, :creator_id, :organization_id, :parent_id, :reply_id, :title,:sticky,:locked + include Redmine::SafeAttributes + belongs_to :organization + belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' + + acts_as_tree :order => "#{OrgDocumentComment.table_name}.sticky asc, #{OrgDocumentComment.table_name}.created_at desc" + has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy + after_create :document_save_as_org_activity + + def document_save_as_org_activity + if(self.parent().nil?) + self.org_acts << OrgActivity.new(:user_id => User.current.id, :container_id => self.organization.id, :container_type => 'Organization') + end + end +end diff --git a/app/models/org_member.rb b/app/models/org_member.rb new file mode 100644 index 000000000..a1c61f99d --- /dev/null +++ b/app/models/org_member.rb @@ -0,0 +1,8 @@ +class OrgMember < ActiveRecord::Base + attr_accessible :organization_id, :role, :user_id + belongs_to :organization + belongs_to :user + has_many :roles ,:through => :org_member_roles,:foreign_key => 'role_id' + has_many :org_member_roles,:dependent => :destroy + +end diff --git a/app/models/org_member_role.rb b/app/models/org_member_role.rb new file mode 100644 index 000000000..0ce4f8141 --- /dev/null +++ b/app/models/org_member_role.rb @@ -0,0 +1,5 @@ +class OrgMemberRole < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :org_member + belongs_to :role +end diff --git a/app/models/org_project.rb b/app/models/org_project.rb new file mode 100644 index 000000000..ec01013fc --- /dev/null +++ b/app/models/org_project.rb @@ -0,0 +1,5 @@ +class OrgProject < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :organization + belongs_to :project +end diff --git a/app/models/organization.rb b/app/models/organization.rb index 5f52dee98..7778da477 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,5 +1,14 @@ class Organization < ActiveRecord::Base - attr_accessible :logo_link, :name + attr_accessible :name, :description, :creator_id, :home_id, :domain, :is_public + has_many :org_members, :dependent => :destroy + has_many :org_projects ,:dependent => :destroy + has_many :projects,:through => :org_projects + has_many :org_document_comments, :dependent => :destroy + has_many :users, :through => :org_members + validates_uniqueness_of :name + after_create :save_as_org_activity - has_many :projects + def save_as_org_activity + OrgActivity.create(:user_id => User.current.id, :org_act_id => self.id, :org_act_type => 'CreateOrganization', :container_id => self.id, :container_type => 'Organization') + end end diff --git a/app/models/principal.rb b/app/models/principal.rb index 0f0746f78..dd376f609 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -87,6 +87,16 @@ class Principal < ActiveRecord::Base end } + 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 + } + scope :sorted, lambda { order(*Principal.fields_for_order_statement)} scope :applied_members, lambda {|project| diff --git a/app/models/project.rb b/app/models/project.rb index fd1012fa0..0b0420920 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -69,6 +69,7 @@ class Project < ActiveRecord::Base has_many :applied_projects, :dependent => :destroy has_many :invite_lists, :dependent => :destroy has_one :dts + has_many :organizations,:through => :org_projects # end #ADDED BY NIE @@ -96,7 +97,8 @@ class Project < ActiveRecord::Base # 关联虚拟表 has_many :forge_messages, :class_name =>'ForgeMessage', :as => :forge_message, :dependent => :destroy - belongs_to :organization + has_many :org_projects,:dependent => :destroy + has_many :organization,:through => :org_projects # has_many :journals diff --git a/app/models/role.rb b/app/models/role.rb index 8bf5ebc05..f6a24a27f 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -55,6 +55,8 @@ class Role < ActiveRecord::Base has_many :member_roles, :dependent => :destroy has_many :members, :through => :member_roles + has_many :org_member_roles, :dependent => :destroy + has_many :org_members,:through => :org_member_roles acts_as_list serialize :permissions, ::Role::PermissionsAttributeCoder diff --git a/app/models/user.rb b/app/models/user.rb index edc29c015..85b9e2591 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -94,8 +94,11 @@ class User < Principal has_one :preference, :dependent => :destroy, :class_name => 'UserPreference' has_one :rss_token, :class_name => 'Token', :conditions => "action='feeds'" has_one :blog, :class_name => 'Blog', :foreign_key => "author_id" + has_many :org_document_comments, :dependent =>:destroy has_one :api_token, :class_name => 'Token', :conditions => "action='api'" belongs_to :auth_source + has_many :org_members + has_many :organizations, :through => :org_members belongs_to :ucourse, :class_name => 'Course', :foreign_key => :id #huang ## added by xianbo for delete # has_many :biding_projects, :dependent => :destroy @@ -769,6 +772,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/blog_comments/show.html.erb b/app/views/blog_comments/show.html.erb index 54c9541f2..cf24f0f2d 100644 --- a/app/views/blog_comments/show.html.erb +++ b/app/views/blog_comments/show.html.erb @@ -28,7 +28,7 @@ showNormalImage('message_description_<%= @article.id %>'); }); -
- <%= render :partial=>"avatar/avatar_form",:locals=> {source:@organizations} %> -
-<% end %> -- - <%= f.text_field :name, :required => true, :size => 60, :style => "width:290px;" %> -
- - - <%#= l(:field_description)%> - - - - diff --git a/app/views/organization/edit.html.erb b/app/views/organization/edit.html.erb deleted file mode 100644 index 60b7c06a0..000000000 --- a/app/views/organization/edit.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<%= form_for(@organization) do |f|%> -- <%= render :partial=>"avatar/avatar_form",:locals=> {source:@organization} %> -
-- - <%= f.text_field :name, :required => true, :size => 60, :style => "width:290px;" %> -
- - <%= submit_tag l(:button_create), :class => "enterprise"%> - -<%= string %>
+ <% end %> + <% end %> +<%= reply.notes.nil? ? "" : reply.notes.html_safe %>
+添加成员
+ <%= form_tag url_for(:controller => 'org_member',:action => 'create',:org=>@organization),:id=>'org_member_add_form',:remote=>true do |f|%> + + <%= javascript_tag "observeSearchfield('not_org_member_search', null, '#{ escape_javascript org_member_autocomplete_org_member_index_path(:org=>@organization, :format => 'js') }')" %> +