diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index c46b62879..fa9dc3a28 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -14,7 +14,6 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - class MembersController < ApplicationController model_object Member before_filter :find_model_object, :except => [:index, :create, :autocomplete] @@ -22,7 +21,6 @@ class MembersController < ApplicationController before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete] before_filter :authorize accept_api_auth :index, :show, :create, :update, :destroy - def index @offset, @limit = api_offset_and_limit @member_count = @project.member_principals.count @@ -49,17 +47,32 @@ class MembersController < ApplicationController def create members = [] + project_info = [] if params[:membership] if params[:membership][:user_ids] attrs = params[:membership].dup user_ids = attrs.delete(:user_ids) user_ids.each do |user_id| members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) + ## added by nie + if params[:membership][:role_ids][0] == "3" + project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id) + # ProjectInfo.create(:name => "test", :user_id => 123) + end + ## end end else members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id]) + ## added by nie + if params[:membership][:role_ids][0] == "3" + project_info << Project_info.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id]) + end + ## end end - @project.members << members + @project.members << members + # added by nie + @project.project_infos << project_info + # end end respond_to do |format| @@ -79,7 +92,21 @@ class MembersController < ApplicationController def update if params[:membership] @member.role_ids = params[:membership][:role_ids] + + #added by nie + if params[:membership][:role_ids][0] == "3" + @projectInfo = ProjectInfo.new(:user_id => @member.user_id, :project_id => @project.id) + @projectInfo.save + else + user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id) + if user_admin.size > 0 + user_admin.each do |user| + user.destroy + end + end + end end + saved = @member.save respond_to do |format| format.html { redirect_to_settings_in_projects } @@ -96,7 +123,13 @@ class MembersController < ApplicationController def destroy if request.delete? && @member.deletable? - @member.destroy + @member.destroy + end + user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id) + if user_admin.size > 0 + user_admin.each do |user| + user.destroy + end end respond_to do |format| format.html { redirect_to_settings_in_projects } diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index afbf983bd..f749c641b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -50,7 +50,6 @@ class ProjectsController < ApplicationController helper :members helper :activities helper :documents - helper :watchers ### added by william @@ -85,8 +84,18 @@ class ProjectsController < ApplicationController # @project_pages = Paginator.new @project_count, @limit, params['page'] # @offset ||= @project_pages.offset # @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all + @offset, @limit = api_offset_and_limit({:limit => 10}) @projects = Project.visible + # @projects.each do |project| + # @admin = project.users_by_role[Role.find(3)] + # unless @admin.nil? + # @admin.each do |user| + # ProjectInfo.create(:user_id => user.id, :project_id => project.id) + # end +# + # end + # end @projects = Project.visible.like(params[:name]) if params[:name].present? @project_count = @projects.count @project_pages = Paginator.new @project_count, @limit, params['page'] diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 8c78c82a0..229fc67ab 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -2,7 +2,6 @@ class TagsController < ApplicationController before_filter :require_admin,:only => :show - include ProjectsHelper include IssuesHelper include UsersHelper @@ -10,7 +9,6 @@ class TagsController < ApplicationController $selected_tags = Array.new $related_tags = Array.new - def index $selected_tags = [] @@ -26,17 +24,13 @@ class TagsController < ApplicationController @users_results = get_users_by_tag($selected_tags) @obj_id = params[:obj_id] - @show_flag = params[:object_flag] - - case @show_flag + case params[:object_flag] when '1' then @obj = User.find_by_id(@obj_id) when '2' then @obj = Project.find_by_id(@obj_id) when '3' then @obj = Issue.find_by_id(@obj_id) - when '4' then - @obj = Bid.find_by_id(@obj_id) else @obj = nil end @@ -79,10 +73,5 @@ class TagsController < ApplicationController def show end - - def show_all - @tags = ActsAsTaggableOn::Tag.find(:all) - @tags = @tags.to_a - end end diff --git a/app/models/project.rb b/app/models/project.rb index c7c506593..9a0265a86 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -51,6 +51,9 @@ class Project < ActiveRecord::Base has_one :repository, :conditions => ["is_default = ?", true] has_many :repositories, :dependent => :destroy has_many :changesets, :through => :repository + #ADDED BY NIE + has_many :project_infos, :dependent => :destroy + #end has_one :wiki, :dependent => :destroy # Custom field for the project issues has_and_belongs_to_many :issue_custom_fields, diff --git a/app/models/project_info.rb b/app/models/project_info.rb new file mode 100644 index 000000000..1327d2040 --- /dev/null +++ b/app/models/project_info.rb @@ -0,0 +1,8 @@ +class ProjectInfo < ActiveRecord::Base + attr_accessible :project_id, :user_id + + belongs_to :project + belongs_to :user + validates_presence_of :project_id, :user_id + validates_uniqueness_of :project_id, :scope => :user_id +end diff --git a/app/models/user.rb b/app/models/user.rb index 78b757d43..e27c6a782 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -85,6 +85,9 @@ class User < Principal has_many :activities ##### +######added by nie + has_many :project_infos, :dependent => :destroy + ##### scope :logged, lambda { where("#{User.table_name}.status <> #{STATUS_ANONYMOUS}") } scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) } diff --git a/app/views/projects/_project.html.erb b/app/views/projects/_project.html.erb index 340b25d02..33a270762 100644 --- a/app/views/projects/_project.html.erb +++ b/app/views/projects/_project.html.erb @@ -26,10 +26,10 @@