diff --git a/app/assets/javascripts/angularjs/controllers/project_schedule_controller.js b/app/assets/javascripts/angularjs/controllers/project_schedule_controller.js index eb2b7124b..3daf59b45 100644 --- a/app/assets/javascripts/angularjs/controllers/project_schedule_controller.js +++ b/app/assets/javascripts/angularjs/controllers/project_schedule_controller.js @@ -6,29 +6,19 @@ RosaABF.controller('ProjectScheduleController', ['$scope', '$http', function($sc '1': 'autostart_statuses.1', '2': 'autostart_statuses.2' }; - $scope.project = null; - $scope.owner = null; $scope.items = []; - - $scope.init = function(name_with_owner) { - var arr = name_with_owner.split('/'); - $scope.owner = arr[0]; - $scope.project = arr[1]; - } - $scope.updateStatus = function() { $http.put( - Routes.project_path($scope.owner, $scope.project), + Routes.project_path($scope.name_with_owner), {project: {autostart_status: $scope.autostart_status}, format: 'json'} ); } $scope.updateSchedule = function(obj) { $http.put( - Routes.project_schedule_path($scope.owner, $scope.project), + Routes.project_schedule_path($scope.name_with_owner), {enabled: obj.enabled, auto_publish: obj.auto_publish, repository_id: obj.repository_id, format: 'json'} ); } - -}]); \ No newline at end of file +}]); diff --git a/app/assets/javascripts/angularjs/models/build_list.js.erb b/app/assets/javascripts/angularjs/models/build_list.js.erb index d268d0887..d818e9d67 100644 --- a/app/assets/javascripts/angularjs/models/build_list.js.erb +++ b/app/assets/javascripts/angularjs/models/build_list.js.erb @@ -35,8 +35,8 @@ var BuildList = function(atts, dictionary) { self.version_link_text = self.commit_hash || self.project_version; self.version_link_url = Routes.commit_path(self.project.owner, self.project.name, self.version_link_text); } - self.project.url = Routes.project_path(self.project.owner, self.project.name); self.project.name_with_owner = self.project.owner + '/' + self.project.name; + self.project.url = Routes.project_path(self.project.name_with_owner); } if (self.user) diff --git a/app/controllers/platforms/products_controller.rb b/app/controllers/platforms/products_controller.rb index c3ca3a48e..0fdba7309 100644 --- a/app/controllers/platforms/products_controller.rb +++ b/app/controllers/platforms/products_controller.rb @@ -67,8 +67,6 @@ class Platforms::ProductsController < Platforms::BaseController protected def set_project - args = params[:src_project].try(:split, '/') || [] - @product.project = (args.length == 2) ? - Project.find_by_owner_and_name(*args) : nil + @product.project = Project.find_by_owner_and_name params[:src_project] end end diff --git a/app/controllers/projects/base_controller.rb b/app/controllers/projects/base_controller.rb index 7bd0dd194..081c803c1 100644 --- a/app/controllers/projects/base_controller.rb +++ b/app/controllers/projects/base_controller.rb @@ -12,7 +12,7 @@ class Projects::BaseController < ApplicationController end def find_project - @project = Project.find_by_owner_and_name!(params[:owner_name], params[:project_name]) if params[:owner_name].present? && params[:project_name].present? + @project = Project.find_by_owner_and_name! params[:owner_with_name] end def init_statistics diff --git a/app/controllers/projects/pull_requests_controller.rb b/app/controllers/projects/pull_requests_controller.rb index c8486f00c..f1a2f1680 100644 --- a/app/controllers/projects/pull_requests_controller.rb +++ b/app/controllers/projects/pull_requests_controller.rb @@ -152,8 +152,7 @@ class Projects::PullRequestsController < Projects::BaseController end def find_destination_project bang=true - args = params[:to_project].try(:split, '/') || [] - project = (args.length == 2) ? Project.find_by_owner_and_name(*args) : nil + project = Project.find_by_owner_and_name params[:to_project] raise ActiveRecord::RecordNotFound if bang && !project project || @project end diff --git a/app/controllers/users/users_controller.rb b/app/controllers/users/users_controller.rb index 32eee91e0..f3aeaefc0 100644 --- a/app/controllers/users/users_controller.rb +++ b/app/controllers/users/users_controller.rb @@ -3,8 +3,7 @@ class Users::UsersController < Users::BaseController before_filter :find_user_by_key, only: [:allowed, :discover] def allowed - owner_name, project_name = params[:project].split '/' - project = Project.find_by_owner_and_name!(owner_name, project_name ? project_name : '!') + project = Project.find_by_owner_and_name! params[:project] action = case params[:action_type] when 'git-upload-pack' then :read diff --git a/app/models/project.rb b/app/models/project.rb index 7dff5adc4..0eae4e2f2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -11,6 +11,7 @@ class Project < ActiveRecord::Base VISIBILITIES = ['open', 'hidden'] MAX_OWN_PROJECTS = 32000 NAME_REGEXP = /[\w\-\+\.]+/ + OWNER_AND_NAME_REGEXP = /#{User::NAME_REGEXP.source}\/#{NAME_REGEXP.source}/ belongs_to :owner, polymorphic: true, counter_cache: :own_projects_count belongs_to :maintainer, class_name: 'User' @@ -37,7 +38,7 @@ class Project < ActiveRecord::Base validates :name, uniqueness: { scope: [:owner_id, :owner_type], case_sensitive: false }, presence: true, - format: { with: /\A#{NAME_REGEXP}\z/, + format: { with: /\A#{NAME_REGEXP.source}\z/, message: I18n.t("activerecord.errors.project.uname") } validates :maintainer_id, presence: true, unless: :new_record? validates :url, presence: true, format: { with: /\Ahttps?:\/\/[\S]+\z/ }, if: :mass_import @@ -95,13 +96,15 @@ class Project < ActiveRecord::Base attr_accessor :url, :srpms_list, :mass_import, :add_to_repository_id class << self - def find_by_owner_and_name(owner_name, project_name) - where(owner_uname: owner_name, name: project_name).first || - by_owner_and_name(owner_name, project_name).first + def find_by_owner_and_name(first, last = nil) + arr = first.try(:split, '/') || [] + arr = (arr << last).compact + return nil if arr.length != 2 + where(owner_uname: arr.first, name: arr.last).first || by_owner_and_name(*arr).first end - def find_by_owner_and_name!(owner_name, project_name) - find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound + def find_by_owner_and_name!(first, last = nil) + find_by_owner_and_name(first, last) or raise ActiveRecord::RecordNotFound end end @@ -114,7 +117,7 @@ class Project < ActiveRecord::Base end def to_param - name + "#{owner_uname}/#{name}" end def all_members diff --git a/app/models/user.rb b/app/models/user.rb index 95cc7a7f3..1a2ddf08c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,6 +8,7 @@ class User < Avatar EXTENDED_ROLES = ROLES | ['system'] LANGUAGES_FOR_SELECT = [['Russian', 'ru'], ['English', 'en']] LANGUAGES = LANGUAGES_FOR_SELECT.map(&:last) + NAME_REGEXP = /[a-z0-9_]+/ devise :database_authenticatable, :registerable, :omniauthable, :recoverable, :rememberable, :validatable, :lockable, :confirmable @@ -40,7 +41,7 @@ class User < Avatar has_many :ssh_keys, dependent: :destroy validates :uname, presence: true, uniqueness: { case_sensitive: false }, - format: { with: /\A[a-z0-9_]+\z/ }, reserved_name: true + format: { with: /\A#{NAME_REGEXP.source}\z/ }, reserved_name: true validate { errors.add(:uname, :taken) if Group.by_uname(uname).present? } validates :role, inclusion: { in: EXTENDED_ROLES }, allow_blank: true validates :language, inclusion: { in: LANGUAGES }, allow_blank: true diff --git a/app/views/home/partials/_build_list_notification.haml b/app/views/home/partials/_build_list_notification.haml index 2e1c14aae..5617d3529 100644 --- a/app/views/home/partials/_build_list_notification.haml +++ b/app/views/home/partials/_build_list_notification.haml @@ -4,7 +4,8 @@ .text %span = raw t('notifications.bodies.build_task', id: build_list_id, task_link: build_list_path(build_list_id)) - = raw t('notifications.bodies.project', project_link: link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) + - name_with_owner = "#{project_owner}/#{project_name}" + = raw t('notifications.bodies.project', project_link: link_to(name_with_owner, name_with_owner) ) - message, error = case status - when BuildList::BUILD_PENDING - ['pending', nil] diff --git a/app/views/home/partials/_git_delete_branch_notification.haml b/app/views/home/partials/_git_delete_branch_notification.haml index 4bd299d77..87b10bf7f 100644 --- a/app/views/home/partials/_git_delete_branch_notification.haml +++ b/app/views/home/partials/_git_delete_branch_notification.haml @@ -5,7 +5,8 @@ %span -_user_link = defined?(user_email) ? user_link(user, defined?(user_name) ? user_name : user_email) : nil = t('notifications.bodies.delete_branch', branch_name: branch_name, user_link: _user_link).html_safe - = raw t("notifications.bodies.project", project_link: link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) + - name_with_owner = "#{project_owner}/#{project_name}" + = raw t("notifications.bodies.project", project_link: link_to(name_with_owner, project_path(name_with_owner)) ) .both = datetime_moment activity_feed.created_at, tag: :span, class: 'date' .both diff --git a/app/views/home/partials/_git_new_push_notification.haml b/app/views/home/partials/_git_new_push_notification.haml index dd7254024..a72658f31 100644 --- a/app/views/home/partials/_git_new_push_notification.haml +++ b/app/views/home/partials/_git_new_push_notification.haml @@ -5,7 +5,8 @@ %span -_user_link = defined?(user_email) ? user_link(user, defined?(user_name) ? user_name : user_email) : nil = raw t("notifications.bodies.#{change_type}_branch", {branch_name: branch_name, user_link: _user_link}) - = raw t("notifications.bodies.project", project_link: link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) + - name_with_owner = "#{project_owner}/#{project_name}" + = raw t("notifications.bodies.project", project_link: link_to(name_with_owner, project_path(name_with_owner)) ) .both = datetime_moment activity_feed.created_at, tag: :span, class: 'date' .both diff --git a/app/views/home/partials/_issue_assign_notification.haml b/app/views/home/partials/_issue_assign_notification.haml index 31f768ec3..5dd7a9944 100644 --- a/app/views/home/partials/_issue_assign_notification.haml +++ b/app/views/home/partials/_issue_assign_notification.haml @@ -2,7 +2,8 @@ .text %span = raw t("notifications.bodies.issue_assign_notification", { issue_link: link_to(issue_title, project_issue_path(project_owner, project_name, issue_serial_id))}) - = raw t("notifications.bodies.project", project_link: link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) + - name_with_owner = "#{project_owner}/#{project_name}" + = raw t("notifications.bodies.project", project_link: link_to(name_with_owner, project_path(name_with_owner)) ) .both = datetime_moment activity_feed.created_at, tag: :span, class: 'date' .both diff --git a/app/views/home/partials/_new_comment_commit_notification.haml b/app/views/home/partials/_new_comment_commit_notification.haml index 21d65a4b7..6da76bc68 100644 --- a/app/views/home/partials/_new_comment_commit_notification.haml +++ b/app/views/home/partials/_new_comment_commit_notification.haml @@ -5,7 +5,8 @@ %span = raw t("notifications.bodies.new_comment_notification.title", user_link: user_link(user, user_name)) = raw t("notifications.bodies.new_comment_notification.commit_content", {commit_link: link_to(commit_message, commit_path(project_owner, project_name, commit_id) + "#comment#{comment_id}")}) - = raw t("notifications.bodies.project", project_link: link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) + - name_with_owner = "#{project_owner}/#{project_name}" + = raw t("notifications.bodies.project", project_link: link_to(name_with_owner, project_path(name_with_owner)) ) .both = datetime_moment activity_feed.created_at, tag: :span, class: 'date' .both diff --git a/app/views/home/partials/_new_comment_notification.haml b/app/views/home/partials/_new_comment_notification.haml index 4298eabe2..61e351e6b 100644 --- a/app/views/home/partials/_new_comment_notification.haml +++ b/app/views/home/partials/_new_comment_notification.haml @@ -5,7 +5,8 @@ %span = raw t("notifications.bodies.new_comment_notification.title", {user_link: user_link(user, user_name)}) = raw t("notifications.bodies.new_comment_notification.content", {issue_link: link_to(issue_title, project_issue_path(project_owner, project_name, issue_serial_id) + "#comment#{comment_id}")}) - = raw t("notifications.bodies.project", project_link: link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) + - name_with_owner = "#{project_owner}/#{project_name}" + = raw t("notifications.bodies.project", project_link: link_to(name_with_owner, project_path(name_with_owner)) ) .both = datetime_moment activity_feed.created_at, tag: :span, class: 'date' .both diff --git a/app/views/home/partials/_new_issue_notification.haml b/app/views/home/partials/_new_issue_notification.haml index 8f6c58b22..cfb14bf80 100644 --- a/app/views/home/partials/_new_issue_notification.haml +++ b/app/views/home/partials/_new_issue_notification.haml @@ -4,7 +4,8 @@ .text %span = raw t("notifications.bodies.new_issue_notification", { user_link: user_link(user, user_name), issue_link: project_issue_path(project_owner, project_name, issue_serial_id)}) - = raw t("notifications.bodies.project", project_link: link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) + - name_with_owner = "#{project_owner}/#{project_name}" + = raw t("notifications.bodies.project", project_link: link_to(name_with_owner, project_path(name_with_owner)) ) .both = datetime_moment activity_feed.created_at, tag: :span, class: 'date' .both diff --git a/app/views/home/partials/_wiki_new_commit_notification.haml b/app/views/home/partials/_wiki_new_commit_notification.haml index 1a9a25711..0b2c0c32b 100644 --- a/app/views/home/partials/_wiki_new_commit_notification.haml +++ b/app/views/home/partials/_wiki_new_commit_notification.haml @@ -4,7 +4,8 @@ .text %span = raw t("notifications.bodies.wiki_new_commit_notification", {user_link: user_link(user, user_name), history_link: link_to("wiki", history_project_wiki_index_path(project_owner, project_name))}) - = raw t("notifications.bodies.project", project_link: link_to("#{project_owner}/#{project_name}", project_path(project_owner, project_name)) ) + - name_with_owner = "#{project_owner}/#{project_name}" + = raw t("notifications.bodies.project", project_link: link_to(name_with_owner, project_path(name_with_owner)) ) .both = datetime_moment activity_feed.created_at, tag: :span, class: 'date' .both diff --git a/app/views/layouts/menu/_bottom.html.haml b/app/views/layouts/menu/_bottom.html.haml index 3901b8a4f..829321a87 100644 --- a/app/views/layouts/menu/_bottom.html.haml +++ b/app/views/layouts/menu/_bottom.html.haml @@ -20,10 +20,10 @@ %li = image_tag 'square.png' = link_to t('bottom_menu.developer_api'), t('bottom_menu.developer_api_url') - -if Project.find_by_owner_and_name 'abf', 'abf-ideas' + -if pr = Project.find_by_owner_and_name('abf/abf-ideas') %li = image_tag 'square.png' - = link_to t('bottom_menu.abf_ideas'), project_issues_url('abf', 'abf-ideas') + = link_to t('bottom_menu.abf_ideas'), project_issues_url(pr) %li = image_tag 'square.png' = link_to t('bottom_menu.abf_blog'), t('bottom_menu.abf_blog_url') \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 4e7de8ae8..0ed1f119c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -292,7 +292,7 @@ Rosa::Application.routes.draw do get :mass_import end end - scope ':owner_name/:project_name', constraints: {project_name: Project::NAME_REGEXP} do # project + scope ':owner_with_name', constraints: { owner_with_name: Project::OWNER_AND_NAME_REGEXP } do # project scope as: 'project' do resources :wiki do collection do @@ -365,7 +365,7 @@ Rosa::Application.routes.draw do get '/tags' => "git/trees#tags", as: :tags # Branches get '/branches' => "git/trees#branches", as: :branches - get '/branches/:treeish' => "git/trees#branches", as: :treeish_branch + get '/branches/:treeish' => "git/trees#branches", as: :branch delete '/branches/:treeish' => "git/trees#destroy", as: :destroy_branch put '/branches/:treeish' => "git/trees#restore_branch", as: :restore_branch post '/branches' => "git/trees#create", as: :create_branch diff --git a/lib/ext/rails/url_for.rb b/lib/ext/rails/url_for.rb deleted file mode 100644 index 012f8d62c..000000000 --- a/lib/ext/rails/url_for.rb +++ /dev/null @@ -1,16 +0,0 @@ -module ActionDispatch - module Routing - module UrlFor - def url_for_with_defaults(options = nil) - if options.kind_of?(Hash) - if project = options[:owner_name] and project.is_a?(Project) # for project routes - # set the correct owner and name - options[:owner_name], options[:project_name] = project.owner, project - end - end - url_for_without_defaults(options) - end - alias_method_chain :url_for, :defaults - end - end -end diff --git a/lib/ext/rosa/constraints.rb b/lib/ext/rosa/constraints.rb index ab55c32bf..5220c8f02 100644 --- a/lib/ext/rosa/constraints.rb +++ b/lib/ext/rosa/constraints.rb @@ -22,7 +22,7 @@ module Rosa def self.matches?(request) if (params = request.path_parameters) && params[:treeish] # parse existing branch (tag) and path branch_or_tag = begin - (p = Project.find_by_owner_and_name params[:owner_name], params[:project_name]) && + (p = Project.find_by_owner_and_name params[:owner_and_name]) && p.repo.branches_and_tags.map(&:name).sort{|a,b| b.length <=> a.length}.detect{|b| params[:treeish].start_with?(b)} || params[:treeish].split('/').first end