diff --git a/app/assets/stylesheets/design/main.scss b/app/assets/stylesheets/design/main.scss index 2a2e18cb1..31a14e87c 100644 --- a/app/assets/stylesheets/design/main.scss +++ b/app/assets/stylesheets/design/main.scss @@ -65,7 +65,7 @@ header div.middle { background: image-url("top-middle.png"); float: left; height: 46px; - width: 912px; + width: 913px; } header div.right { diff --git a/app/controllers/admin/register_requests_controller.rb b/app/controllers/admin/register_requests_controller.rb index 6ee831a37..9da359399 100644 --- a/app/controllers/admin/register_requests_controller.rb +++ b/app/controllers/admin/register_requests_controller.rb @@ -5,25 +5,17 @@ class Admin::RegisterRequestsController < Admin::BaseController end def update - if params[:update_type].present? and params[:request_ids].present? - updates = RegisterRequest.where(:id => params[:request_ids]) - case params[:update_type] - when 'approve' # see approve method - updates.each {|req| req.update_attributes(:approved => true, :rejected => false)} - when 'reject' # see reject method - updates.each {|req| req.update_attributes(:approved => false, :rejected => true)} - end - end + RegisterRequest.where(:id => params[:request_ids]).each(¶ms[:update_type].to_sym) if params[:update_type].present? && params[:request_ids].present? redirect_to :action => :index end def approve - @register_request.update_attributes(:approved => true, :rejected => false) + @register_request.approve redirect_to :action => :index end def reject - @register_request.update_attributes(:approved => false, :rejected => true) + @register_request.reject redirect_to :action => :index end end diff --git a/app/controllers/groups/base_controller.rb b/app/controllers/groups/base_controller.rb index cbe73099b..f40eeece2 100644 --- a/app/controllers/groups/base_controller.rb +++ b/app/controllers/groups/base_controller.rb @@ -7,7 +7,7 @@ class Groups::BaseController < ApplicationController def find_group if group_id = params[:owner_name] || params[:group_id] || params[:id] - @group = Group.find_by_owner_name! group_id + @group = Group.find_by_insensitive_uname! group_id end end end diff --git a/app/controllers/groups/members_controller.rb b/app/controllers/groups/members_controller.rb index 76a0db2ab..eba2b55c5 100644 --- a/app/controllers/groups/members_controller.rb +++ b/app/controllers/groups/members_controller.rb @@ -1,7 +1,7 @@ # -*- encoding : utf-8 -*- class Groups::MembersController < Groups::BaseController is_related_controller! - belongs_to :group, :finder => 'find_by_owner_name!', :optional => true + belongs_to :group, :finder => 'find_by_insensitive_uname!', :optional => true before_filter lambda { authorize! :manage_members, @group } @@ -9,16 +9,15 @@ class Groups::MembersController < Groups::BaseController end def update - params['user'].keys.each { |user_id| + params['user'].keys.each do |user_id| role = params['user'][user_id] - if relation = parent.actors.where(:actor_id => user_id, :actor_type => 'User') #find_by_actor_id_and_actor_type(user_id, 'User') relation.update_all(:role => role) if parent.owner.id.to_s != user_id else relation = parent.actors.build(:actor_id => user_id, :actor_type => 'User', :role => role) relation.save! end - } if params['user'] + end if params['user'] if parent.save flash[:notice] = t("flash.members.successfully_changed") else @@ -29,9 +28,9 @@ class Groups::MembersController < Groups::BaseController def remove all_user_ids = [] - params['user_remove'].keys.each { |user_id| + params['user_remove'].keys.each do |user_id| all_user_ids << user_id if params['user_remove'][user_id] == ["1"] && parent.owner.id.to_s != user_id - } if params['user_remove'] + end if params['user_remove'] all_user_ids.each do |user_id| u = User.find(user_id) Relation.by_actor(u).by_target(parent).each {|r| r.destroy} diff --git a/app/controllers/users/base_controller.rb b/app/controllers/users/base_controller.rb index 5a6d4fb40..4f789e3fb 100644 --- a/app/controllers/users/base_controller.rb +++ b/app/controllers/users/base_controller.rb @@ -7,7 +7,7 @@ class Users::BaseController < ApplicationController def find_user if user_id = params[:owner_name] || params[:user_id] || params[:id] - @user = User.find_by_owner_name! user_id + @user = User.find_by_insensitive_uname! user_id end end end diff --git a/app/models/group.rb b/app/models/group.rb index bcb46ad7c..c09af034f 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -2,9 +2,9 @@ class Group < ActiveRecord::Base belongs_to :owner, :class_name => 'User' - has_many :relations, :as => :actor, :dependent => :destroy - has_many :actors, :as => :target, :class_name => 'Relation' - has_many :targets, :as => :actor, :class_name => 'Relation' + has_many :relations, :as => :actor, :dependent => :destroy, :dependent => :destroy + has_many :actors, :as => :target, :class_name => 'Relation', :dependent => :destroy + has_many :targets, :as => :actor, :class_name => 'Relation', :dependent => :destroy has_many :members, :through => :actors, :source => :actor, :source_type => 'User', :autosave => true has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true diff --git a/app/models/platform.rb b/app/models/platform.rb index e8056f4a9..826537d36 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -36,7 +36,7 @@ class Platform < ActiveRecord::Base scope :main, where(:platform_type => 'main') scope :personal, where(:platform_type => 'personal') - attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released #, :owner_id, :owner_type + attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type include Modules::Models::Owner diff --git a/app/models/project.rb b/app/models/project.rb index 0e1fbbfc5..0a1f0f759 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -59,6 +59,7 @@ class Project < ActiveRecord::Base owner = User.find_by_uname(owner_name) || Group.find_by_uname(owner_name) || User.by_uname(owner_name).first || Group.by_uname(owner_name).first and scoped = where(:owner_id => owner.id, :owner_type => owner.class) and scoped.find_by_name(project_name) || scoped.by_name(project_name).first + # owner.projects.find_by_name(project_name) || owner.projects.by_name(project_name).first # TODO force this work? end def self.find_by_owner_and_name!(owner_name, project_name) diff --git a/app/models/register_request.rb b/app/models/register_request.rb index f84771a10..972dc1029 100644 --- a/app/models/register_request.rb +++ b/app/models/register_request.rb @@ -11,6 +11,14 @@ class RegisterRequest < ActiveRecord::Base validates :email, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i } + def approve + update_attributes(:approved => true, :rejected => false) + end + + def reject + update_attributes(:approved => false, :rejected => true) + end + protected def generate_token diff --git a/config/routes.rb b/config/routes.rb index 4baca4e70..37de8ec35 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,16 @@ Rosa::Application.routes.draw do get '/forbidden' => 'pages#forbidden', :as => 'forbidden' get '/terms-of-service' => 'pages#tos', :as => 'tos' + get '/activity_feeds.:format' => 'activity_feeds#index', :as => 'atom_activity_feeds', :format => /atom/ + if APP_CONFIG['anonymous_access'] + authenticated do + root :to => 'activity_feeds#index' + end + root :to => 'pages#root' + else + root :to => 'activity_feeds#index' + end + scope :module => 'platforms' do resources :platforms do resources :private_users, :except => [:show, :destroy, :update] @@ -109,7 +119,7 @@ Rosa::Application.routes.draw do constraints OwnerConstraint.new(User) do get '/' => 'users/profile#show', :as => :user end - constraints OwnerConstraint.new(Group) do + constraints OwnerConstraint.new(Group, true) do get '/' => 'groups/profile#show', :as => :group_profile end scope ':project_name', :as => 'project', :module => 'projects' do @@ -190,14 +200,4 @@ Rosa::Application.routes.draw do get '/archive/:format/tree/:treeish' => "git/trees#archive", :defaults => {:treeish => :master}, :as => :archive, :format => /zip|tar/ end end - - get '/activity_feeds.:format' => 'activity_feeds#index', :as => 'atom_activity_feeds', :format => /atom/ - if APP_CONFIG['anonymous_access'] - authenticated do - root :to => 'activity_feeds#index' - end - root :to => 'pages#root' - else - root :to => 'activity_feeds#index' - end end diff --git a/lib/ext/rails/owner_constraint.rb b/lib/ext/rails/owner_constraint.rb index 921df1b4b..93b32935a 100644 --- a/lib/ext/rails/owner_constraint.rb +++ b/lib/ext/rails/owner_constraint.rb @@ -1,10 +1,12 @@ # -*- encoding : utf-8 -*- class OwnerConstraint - def initialize(class_name) + def initialize(class_name, bang = false) @class_name = class_name + @finder = 'find_by_insensitive_uname' + @finder << '!' if bang end def matches?(request) - !!(@class_name.find_by_uname(request.params[:owner_name]) || @class_name.by_uname(request.params[:owner_name]).first) + @class_name.send(@finder, request.params[:owner_name]).present? end end diff --git a/lib/modules/models/acts_like_member.rb b/lib/modules/models/acts_like_member.rb index 44af7f18e..d413bb834 100644 --- a/lib/modules/models/acts_like_member.rb +++ b/lib/modules/models/acts_like_member.rb @@ -29,8 +29,12 @@ module Modules end module ClassMethods - def find_by_owner_name!(uname) - by_uname(uname).first! + def find_by_insensitive_uname(uname) + find_by_uname(uname) || by_uname(uname).first + end + + def find_by_insensitive_uname!(uname) + find_by_insensitive_uname(uname) or raise ActiveRecord::RecordNotFound end end end