socialforge/app/controllers/organizations_controller.rb

150 lines
4.5 KiB
Ruby

# 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])
project_ids = @organization.projects.map(&:id) << 0
@org_activities = OrgActivity.where("(container_id =? and container_type =?) or (container_type ='Project' and container_id in (#{project_ids.join(',')}))",
@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
@org_activities_count = OrgActivity.where("(container_id =? and container_type =?) or (container_type ='Project' and container_id in (#{project_ids.join(',')}))" ,
@organization.id, 'Organization ').count
# @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]
respond_to do |format|
format.html
format.js
end
else
render_403
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