From 71c1a4afcf1a87a287e99212d84c754c2ceefb0b Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Sat, 31 Mar 2012 02:45:05 +0400 Subject: [PATCH 1/2] [issue #195] Owner removed from list of collaborators when editing list --- app/controllers/collaborators_controller.rb | 15 +++++++++++---- app/models/group.rb | 1 + app/models/user.rb | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/collaborators_controller.rb b/app/controllers/collaborators_controller.rb index a149b06b9..ac237350a 100644 --- a/app/controllers/collaborators_controller.rb +++ b/app/controllers/collaborators_controller.rb @@ -34,7 +34,9 @@ class CollaboratorsController < ApplicationController role = params['user'][user_id] if relation = @project.relations.find_by_object_id_and_object_type(user_id, 'User') - relation.update_attribute(:role, role) + unless @project.owner_type == 'User' and @project.owner_id.to_i == user_id.to_i + relation.update_attribute(:role, role) + end else relation = @project.relations.build(:object_id => user_id, :object_type => 'User', :role => role) relation.save @@ -44,7 +46,9 @@ class CollaboratorsController < ApplicationController params['group'].keys.each { |group_id| role = params['group'][group_id] if relation = @project.relations.find_by_object_id_and_object_type(group_id, 'Group') - relation.update_attribute(:role, role) + unless @project.owner_type == 'Group' and @project.owner_id.to_i == group_id.to_i + relation.update_attribute(:role, role) + end else relation = @project.relations.build(:object_id => user_id, :object_type => 'Group', :role => role) relation.save @@ -71,13 +75,14 @@ class CollaboratorsController < ApplicationController all_group_ids << group_id if params['group_remove'][group_id] == ["1"] } if params['group_remove'] + all_user_ids.each do |user_id| u = User.find(user_id) - Relation.by_object(u).by_target(@project).each {|r| r.destroy} + Relation.by_object(u).by_target(@project).each {|r| r.destroy} unless u.id == @project.owner_id and @project.owner_type == 'User' end all_group_ids.each do |group_id| g = Group.find(group_id) - Relation.by_object(g).by_target(@project).each {|r| r.destroy} + Relation.by_object(g).by_target(@project).each {|r| r.destroy} unless g.id == @project.owner_id and @project.owner_type == 'Group' end redirect_to edit_project_collaborators_path(@project) + "##{params['user_remove'].present? ? 'users' : 'groups'}" @@ -126,10 +131,12 @@ class CollaboratorsController < ApplicationController def find_users @users = @project.collaborators.order('uname')#User.all + @users = @users.without(@project.owner_id) if @project.owner_type == 'User' end def find_groups @groups = @project.groups.order('uname')#Group.all + @groups = @groups.without(@project.owner_id) if @project.owner_type == 'Group' end def authorize_collaborators diff --git a/app/models/group.rb b/app/models/group.rb index fd541923c..867be4104 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -18,6 +18,7 @@ class Group < ActiveRecord::Base validate { errors.add(:uname, :taken) if User.where('uname LIKE ?', uname).present? } scope :search_order, order("CHAR_LENGTH(uname) ASC") + scope :without, lambda {|l| where("groups.id NOT IN (?)", Array(l))} scope :search, lambda {|q| where("uname ILIKE ?", "%#{q}%")} scope :by_owner, lambda {|owner| where(:owner_id => owner.id)} scope :by_admin, lambda {|admin| joins(:relations).where(:'relations.role' => 'admin', :'relations.target_id' => admin.id, :'relations.target_type' => 'User')} diff --git a/app/models/user.rb b/app/models/user.rb index de4a16f9a..59c103143 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -49,6 +49,7 @@ class User < ActiveRecord::Base attr_accessor :login scope :search_order, order("CHAR_LENGTH(uname) ASC") + scope :without, lambda {|l| where("users.id NOT IN (?)", Array(l))} scope :search, lambda {|q| where("uname ILIKE ?", "%#{q}%")} scope :banned, where(:role => 'banned') scope :admin, where(:role => 'admin') From 7234cb7f99afca7582a00016af5ecb6cdcdc6d1d Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Sat, 31 Mar 2012 03:13:09 +0400 Subject: [PATCH 2/2] [issue #195] Changed scopes. --- app/models/group.rb | 2 +- app/models/user.rb | 2 +- db/schema.rb | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/models/group.rb b/app/models/group.rb index 0a0eab9d1..b0a46de38 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -18,7 +18,7 @@ class Group < ActiveRecord::Base validate { errors.add(:uname, :taken) if User.where('uname LIKE ?', uname).present? } scope :search_order, order("CHAR_LENGTH(uname) ASC") - scope :without, lambda {|l| where("groups.id NOT IN (?)", Array(l))} + scope :without, lambda {|a| where("groups.id NOT IN (?)", a)} scope :search, lambda {|q| where("uname ILIKE ?", "%#{q.strip}%")} scope :opened, where('1=1') scope :by_owner, lambda {|owner| where(:owner_id => owner.id)} diff --git a/app/models/user.rb b/app/models/user.rb index 22336c3e7..463264110 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -48,7 +48,7 @@ class User < ActiveRecord::Base attr_accessor :login scope :search_order, order("CHAR_LENGTH(uname) ASC") - scope :without, lambda {|l| where("users.id NOT IN (?)", Array(l))} + scope :without, lambda {|a| where("users.id NOT IN (?)", a)} scope :search, lambda {|q| where("uname ILIKE ?", "%#{q.strip}%")} scope :opened, where('1=1') scope :banned, where(:role => 'banned') diff --git a/db/schema.rb b/db/schema.rb index d1166777e..1f2ad13ce 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -17,8 +17,8 @@ ActiveRecord::Schema.define(:version => 20120329182602) do t.integer "user_id", :null => false t.string "kind" t.text "data" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "arches", :force => true do |t| @@ -268,11 +268,11 @@ ActiveRecord::Schema.define(:version => 20120329182602) do t.text "description" t.string "ancestry" t.boolean "has_issues", :default => true + t.boolean "has_wiki", :default => false t.string "srpm_file_name" t.string "srpm_content_type" t.integer "srpm_file_size" t.datetime "srpm_updated_at" - t.boolean "has_wiki", :default => false t.string "default_branch", :default => "master" t.boolean "is_rpm", :default => true end @@ -292,7 +292,6 @@ ActiveRecord::Schema.define(:version => 20120329182602) do end add_index "register_requests", ["email"], :name => "index_register_requests_on_email", :unique => true, :case_sensitive => false - add_index "register_requests", ["token"], :name => "index_register_requests_on_token", :unique => true, :case_sensitive => false create_table "relations", :force => true do |t| t.integer "object_id" @@ -351,16 +350,16 @@ ActiveRecord::Schema.define(:version => 20120329182602) do t.string "name" t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false t.string "reset_password_token" + t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" + t.text "ssh_key" t.string "uname" t.string "role" t.string "language", :default => "en" t.integer "own_projects_count", :default => 0, :null => false - t.datetime "reset_password_sent_at" t.text "professional_experience" t.string "site" t.string "company"