socialforge/app/controllers/organizations_controller.rb

104 lines
2.9 KiB
Ruby
Raw Normal View History

2015-11-05 17:57:07 +08:00
# encoding: utf-8
class OrganizationsController < ApplicationController
2015-11-12 20:57:41 +08:00
before_filter :find_organization, :only => [:show, :members]
2015-11-03 17:21:32 +08:00
layout 'base_org'
2015-11-05 17:57:07 +08:00
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
2015-11-05 17:57:07 +08:00
member = OrgMember.new(:user_id => User.current.id)
@organization.org_members << member
2015-11-03 17:21:32 +08:00
if @organization.save
2015-11-05 17:57:07 +08:00
OrgMemberRole.create(:org_member_id => member.id, :role_id => 11)
2015-11-03 17:21:32 +08:00
redirect_to organization_path(@organization)
end
end
def show
2015-11-12 20:57:41 +08:00
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
2015-11-12 17:52:47 +08:00
@organization = Organization.find(params[:id])
2015-11-13 19:46:04 +08:00
@activities = OrgActivity.where('container_id =? and container_type =? ',
@organization.id, 'Organization ').order('updated_at desc')
2015-11-12 17:52:47 +08:00
@activities = paginateHelper @activities, 10
else
render_403
end
2015-11-03 17:21:32 +08:00
end
def update
2015-11-05 17:57:07 +08:00
@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;
2015-11-12 20:57:41 +08:00
@org_name = params[:org_name].strip
2015-11-05 17:57:07 +08:00
@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
2015-11-12 17:52:47 +08:00
@organization = Organization.find(params[:id])
if User.current.admin? || User.current.admin_of_org?(@organization)
else
render_403
end
2015-11-05 17:57:07 +08:00
end
def clear_org_avatar_temp
2015-11-03 17:21:32 +08:00
end
2015-11-12 09:32:00 +08:00
def set_homepage
2015-11-13 15:02:12 +08:00
@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
2015-11-12 09:32:00 +08:00
end
def autocomplete_search
@project = Project.find(params[:project_id])
#@flag = params[:flag] || false
respond_to do |format|
format.js
end
end
2015-11-12 20:57:41 +08:00
def members
@members = OrgMember.where("organization_id =?", @organization.id)
end
end