Skip to content
Snippets Groups Projects
Commit 77541891 authored by Robert Speicher's avatar Robert Speicher
Browse files

Fully embrace Ruby 1.9 hash syntax

Didn't bother with files in db/, config/, or features/
parent 1413c23c
No related branches found
No related tags found
1 merge request!1219Fully embrace Ruby 1.9 hash syntax
Showing
with 131 additions and 131 deletions
Loading
Loading
@@ -11,7 +11,7 @@ class Tree
:size,
:text?,
:colorize,
:to => :tree
to: :tree
 
def initialize(raw_tree, project, ref = nil, path = nil)
@project, @ref, @path = project, ref, path,
Loading
Loading
Loading
Loading
@@ -11,58 +11,58 @@ class User < ActiveRecord::Base
 
attr_accessor :force_random_password
 
has_many :users_projects, :dependent => :destroy
has_many :projects, :through => :users_projects
has_many :my_own_projects, :class_name => "Project", :foreign_key => :owner_id
has_many :keys, :dependent => :destroy
has_many :users_projects, dependent: :destroy
has_many :projects, through: :users_projects
has_many :my_own_projects, class_name: "Project", foreign_key: :owner_id
has_many :keys, dependent: :destroy
 
has_many :events,
:class_name => "Event",
:foreign_key => :author_id,
:dependent => :destroy
class_name: "Event",
foreign_key: :author_id,
dependent: :destroy
 
has_many :recent_events,
:class_name => "Event",
:foreign_key => :author_id,
:order => "id DESC"
class_name: "Event",
foreign_key: :author_id,
order: "id DESC"
 
has_many :issues,
:foreign_key => :author_id,
:dependent => :destroy
foreign_key: :author_id,
dependent: :destroy
 
has_many :notes,
:foreign_key => :author_id,
:dependent => :destroy
foreign_key: :author_id,
dependent: :destroy
 
has_many :assigned_issues,
:class_name => "Issue",
:foreign_key => :assignee_id,
:dependent => :destroy
class_name: "Issue",
foreign_key: :assignee_id,
dependent: :destroy
 
has_many :merge_requests,
:foreign_key => :author_id,
:dependent => :destroy
foreign_key: :author_id,
dependent: :destroy
 
has_many :assigned_merge_requests,
:class_name => "MergeRequest",
:foreign_key => :assignee_id,
:dependent => :destroy
class_name: "MergeRequest",
foreign_key: :assignee_id,
dependent: :destroy
 
validates :projects_limit,
:presence => true,
:numericality => {:greater_than_or_equal_to => 0}
presence: true,
numericality: {greater_than_or_equal_to: 0}
 
validates :bio, :length => { :within => 0..255 }
validates :bio, length: { within: 0..255 }
 
before_save :ensure_authentication_token
alias_attribute :private_token, :authentication_token
 
scope :not_in_project, lambda { |project| where("id not in (:ids)", :ids => project.users.map(&:id) ) }
scope :admins, where(:admin => true)
scope :blocked, where(:blocked => true)
scope :active, where(:blocked => false)
scope :not_in_project, lambda { |project| where("id not in (:ids)", ids: project.users.map(&:id) ) }
scope :admins, where(admin: true)
scope :blocked, where(blocked: true)
scope :active, where(blocked: false)
 
before_validation :generate_password, :on => :create
before_validation :generate_password, on: :create
 
def generate_password
if self.force_random_password
Loading
Loading
@@ -94,17 +94,17 @@ class User < ActiveRecord::Base
else
password = Devise.friendly_token[0, 8].downcase
@user = User.create(
:name => name,
:email => email,
:password => password,
:password_confirmation => password,
:projects_limit => Gitlab.config.default_projects_limit
name: name,
email: email,
password: password,
password_confirmation: password,
projects_limit: Gitlab.config.default_projects_limit
)
end
end
 
def self.search query
where("name like :query or email like :query", :query => "%#{query}%")
where("name like :query or email like :query", query: "%#{query}%")
end
end
# == Schema Information
Loading
Loading
Loading
Loading
@@ -12,18 +12,18 @@ class UsersProject < ActiveRecord::Base
after_save :update_repository
after_destroy :update_repository
 
validates_uniqueness_of :user_id, :scope => [:project_id]
validates_uniqueness_of :user_id, scope: [:project_id]
validates_presence_of :user_id
validates_presence_of :project_id
 
delegate :name, :email, :to => :user, :prefix => true
delegate :name, :email, to: :user, prefix: true
 
def self.bulk_import(project, user_ids, project_access)
UsersProject.transaction do
user_ids.each do |user_id|
users_project = UsersProject.new(
:project_access => project_access,
:user_id => user_id
project_access: project_access,
user_id: user_id
)
users_project.project = project
users_project.save
Loading
Loading
@@ -35,7 +35,7 @@ class UsersProject < ActiveRecord::Base
UsersProject.transaction do
project_ids.each do |project_id|
users_project = UsersProject.new(
:project_access => project_access,
project_access: project_access,
)
users_project.project_id = project_id
users_project.user_id = user.id
Loading
Loading
class Wiki < ActiveRecord::Base
belongs_to :project
belongs_to :user
has_many :notes, :as => :noteable, :dependent => :destroy
has_many :notes, as: :noteable, dependent: :destroy
 
validates :content, :title, :user_id, :presence => true
validates :title, :length => 1..250
validates :content, :title, :user_id, presence: true
validates :title, length: 1..250
 
before_update :set_slug
 
Loading
Loading
Loading
Loading
@@ -3,22 +3,22 @@ class ActivityObserver < ActiveRecord::Observer
 
def after_create(record)
Event.create(
:project => record.project,
:target_id => record.id,
:target_type => record.class.name,
:action => Event.determine_action(record),
:author_id => record.author_id
project: record.project,
target_id: record.id,
target_type: record.class.name,
action: Event.determine_action(record),
author_id: record.author_id
)
end
 
def after_save(record)
if record.changed.include?("closed")
Event.create(
:project => record.project,
:target_id => record.id,
:target_type => record.class.name,
:action => (record.closed ? Event::Closed : Event::Reopened),
:author_id => record.author_id_of_changes
project: record.project,
target_id: record.id,
target_type: record.class.name,
action: (record.closed ? Event::Closed : Event::Reopened),
author_id: record.author_id_of_changes
)
end
end
Loading
Loading
Loading
Loading
@@ -71,7 +71,7 @@ class MailerObserver < ActiveRecord::Observer
 
# Create comment about status changed
if target.closed_changed?
note = Note.new(:noteable => target, :project => target.project)
note = Note.new(noteable: target, project: target.project)
note.author = current_user
note.note = "_Status changed to #{target.closed ? 'closed' : 'reopened'}_"
note.save()
Loading
Loading
Loading
Loading
@@ -24,7 +24,7 @@ module Account
end
 
def cared_merge_requests
MergeRequest.where("author_id = :id or assignee_id = :id", :id => self.id).opened
MergeRequest.where("author_id = :id or assignee_id = :id", id: self.id).opened
end
 
def project_ids
Loading
Loading
@@ -50,7 +50,7 @@ module Account
def recent_push project_id = nil
# Get push events not earlier than 2 hours ago
events = recent_events.code_push.where("created_at > ?", Time.now - 2.hours)
events = events.where(:project_id => project_id) if project_id
events = events.where(project_id: project_id) if project_id
 
# Take only latest one
events = events.recent.limit(1).first
Loading
Loading
Loading
Loading
@@ -3,56 +3,56 @@ module Authority
# Should be rewrited for new access rights
def add_access(user, *access)
access = if access.include?(:admin)
{ :project_access => UsersProject::MASTER }
{ project_access: UsersProject::MASTER }
elsif access.include?(:write)
{ :project_access => UsersProject::DEVELOPER }
{ project_access: UsersProject::DEVELOPER }
else
{ :project_access => UsersProject::REPORTER }
{ project_access: UsersProject::REPORTER }
end
opts = { :user => user }
opts = { user: user }
opts.merge!(access)
users_projects.create(opts)
end
 
def reset_access(user)
users_projects.where(:project_id => self.id, :user_id => user.id).destroy if self.id
users_projects.where(project_id: self.id, user_id: user.id).destroy if self.id
end
 
def repository_readers
keys = Key.joins({:user => :users_projects}).
keys = Key.joins({user: :users_projects}).
where("users_projects.project_id = ? AND users_projects.project_access = ?", id, UsersProject::REPORTER)
keys.map(&:identifier) + deploy_keys.map(&:identifier)
end
 
def repository_writers
keys = Key.joins({:user => :users_projects}).
keys = Key.joins({user: :users_projects}).
where("users_projects.project_id = ? AND users_projects.project_access = ?", id, UsersProject::DEVELOPER)
keys.map(&:identifier)
end
 
def repository_masters
keys = Key.joins({:user => :users_projects}).
keys = Key.joins({user: :users_projects}).
where("users_projects.project_id = ? AND users_projects.project_access = ?", id, UsersProject::MASTER)
keys.map(&:identifier)
end
 
def allow_read_for?(user)
!users_projects.where(:user_id => user.id).empty?
!users_projects.where(user_id: user.id).empty?
end
 
def guest_access_for?(user)
!users_projects.where(:user_id => user.id).empty?
!users_projects.where(user_id: user.id).empty?
end
 
def report_access_for?(user)
!users_projects.where(:user_id => user.id, :project_access => [UsersProject::REPORTER, UsersProject::DEVELOPER, UsersProject::MASTER]).empty?
!users_projects.where(user_id: user.id, project_access: [UsersProject::REPORTER, UsersProject::DEVELOPER, UsersProject::MASTER]).empty?
end
 
def dev_access_for?(user)
!users_projects.where(:user_id => user.id, :project_access => [UsersProject::DEVELOPER, UsersProject::MASTER]).empty?
!users_projects.where(user_id: user.id, project_access: [UsersProject::DEVELOPER, UsersProject::MASTER]).empty?
end
 
def master_access_for?(user)
!users_projects.where(:user_id => user.id, :project_access => [UsersProject::MASTER]).empty? || owner_id == user.id
!users_projects.where(user_id: user.id, project_access: [UsersProject::MASTER]).empty? || owner_id == user.id
end
end
Loading
Loading
@@ -6,39 +6,39 @@ module IssueCommonality
attr_protected :author, :author_id, :project, :project_id
 
belongs_to :project
belongs_to :author, :class_name => "User"
belongs_to :assignee, :class_name => "User"
has_many :notes, :as => :noteable, :dependent => :destroy
belongs_to :author, class_name: "User"
belongs_to :assignee, class_name: "User"
has_many :notes, as: :noteable, dependent: :destroy
 
validates_presence_of :project_id
validates_presence_of :author_id
 
validates :title,
:presence => true,
:length => { :within => 0..255 }
presence: true,
length: { within: 0..255 }
 
 
scope :opened, where(:closed => false)
scope :closed, where(:closed => true)
scope :assigned, lambda { |u| where(:assignee_id => u.id)}
scope :opened, where(closed: false)
scope :closed, where(closed: true)
scope :assigned, lambda { |u| where(assignee_id: u.id)}
 
delegate :name,
:email,
:to => :author,
:prefix => true
to: :author,
prefix: true
 
delegate :name,
:email,
:to => :assignee,
:allow_nil => true,
:prefix => true
to: :assignee,
allow_nil: true,
prefix: true
 
attr_accessor :author_id_of_changes
end
 
module ClassMethods
def search(query)
where("title like :query", :query => "%#{query}%")
where("title like :query", query: "%#{query}%")
end
end
 
Loading
Loading
Loading
Loading
@@ -3,10 +3,10 @@ module ProjectPush
data = post_receive_data(oldrev, newrev, ref, user)
 
Event.create(
:project => self,
:action => Event::Pushed,
:data => data,
:author_id => data[:user_id]
project: self,
action: Event::Pushed,
data: data,
author_id: data[:user_id]
)
end
 
Loading
Loading
@@ -20,7 +20,7 @@ module ProjectPush
mrs.each { |merge_request| merge_request.reload_code; merge_request.mark_as_unchecked }
 
# Close merge requests
mrs = self.merge_requests.opened.where(:target_branch => branch_name).all
mrs = self.merge_requests.opened.where(target_branch: branch_name).all
mrs = mrs.select(&:last_commit).select { |mr| c_ids.include?(mr.last_commit.id) }
mrs.each { |merge_request| merge_request.merge!(user.id) }
 
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@ module SshKey
def repository_delete_key
Gitlab::GitHost.system.new.configure do |c|
#delete key file is there is no identically deploy keys
if !is_deploy_key || Key.where(:identifier => identifier).count() == 0
if !is_deploy_key || Key.where(identifier: identifier).count() == 0
c.delete_key(identifier)
end
c.update_projects(projects)
Loading
Loading
Loading
Loading
@@ -25,8 +25,8 @@ module Team
# with passed access role by user id
def add_user_id_to_team(user_id, access_role)
users_projects.create(
:user_id => user_id,
:project_access => access_role
user_id: user_id,
project_access: access_role
)
end
 
Loading
Loading
Loading
Loading
@@ -23,7 +23,7 @@ class AttachmentUploader < CarrierWave::Uploader::Base
# end
 
# Process files as they are uploaded:
# process :scale => [200, 300]
# process scale: [200, 300]
#
# def scale(width, height)
# # do something
Loading
Loading
@@ -31,7 +31,7 @@ class AttachmentUploader < CarrierWave::Uploader::Base
 
# Create different versions of your uploaded files:
# version :thumb do
# process :scale => [50, 50]
# process scale: [50, 50]
# end
 
# Add a white list of extensions which are allowed to be uploaded.
Loading
Loading
Loading
Loading
@@ -5,11 +5,11 @@
Resque Workers
.data.padded
= link_to admin_resque_path do
%h1{:class => @workers.present? ? "cgreen" : "cred"}
%h1{class: @workers.present? ? "cgreen" : "cred"}
= @workers.count
%hr
%p
%strong{:class => @pending_jobs > 0 ? "cred" : "cgreen"}
%strong{class: @pending_jobs > 0 ? "cred" : "cgreen"}
#{@pending_jobs} post receive jobs waiting
 
.span4
Loading
Loading
@@ -19,7 +19,7 @@
= link_to admin_projects_path do
%h1= Project.count
%hr
= link_to 'New Project', new_admin_project_path, :class => "btn small"
= link_to 'New Project', new_admin_project_path, class: "btn small"
.span4
.ui-box
%h5 Users
Loading
Loading
@@ -27,7 +27,7 @@
= link_to admin_users_path do
%h1= User.count
%hr
= link_to 'New User', new_admin_user_path, :class => "btn small"
= link_to 'New User', new_admin_user_path, class: "btn small"
 
 
.row
Loading
Loading
Loading
Loading
@@ -3,9 +3,9 @@
Post receive hooks for binding events.
%br
Read more about system hooks
%strong #{link_to "here", help_system_hooks_path, :class => "vlink"}
%strong #{link_to "here", help_system_hooks_path, class: "vlink"}
 
= form_for @hook, :as => :hook, :url => admin_hooks_path do |f|
= form_for @hook, as: :hook, url: admin_hooks_path do |f|
-if @hook.errors.any?
.alert-message.block-message.error
- @hook.errors.full_messages.each do |msg|
Loading
Loading
@@ -13,9 +13,9 @@
.clearfix
= f.label :url, "URL:"
.input
= f.text_field :url, :class => "text_field xxlarge"
= f.text_field :url, class: "text_field xxlarge"
&nbsp;
= f.submit "Add System Hook", :class => "btn primary"
= f.submit "Add System Hook", class: "btn primary"
%hr
 
-if @hooks.any?
Loading
Loading
@@ -33,7 +33,7 @@
%td
= link_to admin_hook_path(hook) do
%strong= hook.url
= link_to 'Test Hook', admin_hook_test_path(hook), :class => "btn small right"
= link_to 'Test Hook', admin_hook_test_path(hook), class: "btn small right"
%td POST
%td
= link_to 'Remove', admin_hook_path(hook), :confirm => 'Are you sure?', :method => :delete, :class => "danger btn small right"
= link_to 'Remove', admin_hook_path(hook), confirm: 'Are you sure?', method: :delete, class: "danger btn small right"
Loading
Loading
@@ -9,8 +9,8 @@
= f.label :name do
Project name is
.input
= f.text_field :name, :placeholder => "Example Project", :class => "xxlarge"
= f.submit project.new_record? ? 'Create project' : 'Save Project', :class => "btn primary"
= f.text_field :name, placeholder: "Example Project", class: "xxlarge"
= f.submit project.new_record? ? 'Create project' : 'Save Project', class: "btn primary"
 
%hr
.alert.alert-info
Loading
Loading
@@ -21,7 +21,7 @@
.input
.input-prepend
%span.add-on= Gitlab.config.ssh_path
= f.text_field :path, :placeholder => "example_project", :disabled => !!project.id
= f.text_field :path, placeholder: "example_project", disabled: !!project.id
%span.add-on= ".git"
.clearfix
= f.label :code do
Loading
Loading
@@ -29,7 +29,7 @@
.input
.input-prepend
%span.add-on= web_app_url
= f.text_field :code, :placeholder => "example"
= f.text_field :code, placeholder: "example"
 
- unless project.new_record?
.clearfix
Loading
Loading
@@ -39,7 +39,7 @@
- if project.repo_exists?
.clearfix
= f.label :default_branch, "Default Branch"
.input= f.select(:default_branch, project.heads.map(&:name), {}, :style => "width:210px;")
.input= f.select(:default_branch, project.heads.map(&:name), {}, style: "width:210px;")
 
- unless project.new_record?
.alert.alert-info
Loading
Loading
@@ -63,7 +63,7 @@
 
- unless project.new_record?
.actions
= f.submit 'Save Project', :class => "btn primary"
= f.submit 'Save Project', class: "btn primary"
 
 
 
Loading
Loading
%h3.page_title #{@admin_project.name} &rarr; Edit project
%hr
= render 'form', :project => @admin_project
= render 'form', project: @admin_project
%h3
Projects
= link_to 'New Project', new_admin_project_path, :class => "btn small right"
= link_to 'New Project', new_admin_project_path, class: "btn small right"
%br
= form_tag admin_projects_path, :method => :get do
= text_field_tag :name, params[:name], :class => "xlarge"
= submit_tag "Search", :class => "btn submit primary"
= form_tag admin_projects_path, method: :get do
= text_field_tag :name, params[:name], class: "xlarge"
= submit_tag "Search", class: "btn submit primary"
 
%table.admin-table
%thead
Loading
Loading
@@ -21,8 +21,8 @@
%td= link_to project.name, [:admin, project]
%td= project.path
%td= project.users_projects.count
%td= check_box_tag :post_receive_file, 1, project.has_post_receive_file?, :disabled => true
%td= check_box_tag :post_receive_file, 1, project.has_post_receive_file?, disabled: true
%td= last_commit(project)
%td= link_to 'Edit', edit_admin_project_path(project), :id => "edit_#{dom_id(project)}", :class => "btn small"
%td.bgred= link_to 'Destroy', [:admin, project], :confirm => "REMOVE #{project.name}? Are you sure?", :method => :delete, :class => "btn small danger"
= paginate @admin_projects, :theme => "admin"
%td= link_to 'Edit', edit_admin_project_path(project), id: "edit_#{dom_id(project)}", class: "btn small"
%td.bgred= link_to 'Destroy', [:admin, project], confirm: "REMOVE #{project.name}? Are you sure?", method: :delete, class: "btn small danger"
= paginate @admin_projects, theme: "admin"
%h3.page_title New project
%hr
= render 'form', :project => @admin_project
= render 'form', project: @admin_project
%h3
= @admin_project.name
= link_to 'Edit', edit_admin_project_path(@admin_project), :class => "btn right small"
= link_to 'Edit', edit_admin_project_path(@admin_project), class: "btn right small"
 
%br
%table.zebra-striped.table-bordered
Loading
Loading
@@ -33,7 +33,7 @@
%b
Post Receive File:
%td
= check_box_tag :post_receive_file, 1, @admin_project.has_post_receive_file?, :disabled => true
= check_box_tag :post_receive_file, 1, @admin_project.has_post_receive_file?, disabled: true
%br
%h3
Team
Loading
Loading
@@ -52,14 +52,14 @@
%tr
%td
= link_to tm.user_name, admin_user_path(tm.user)
%td= select_tag :tm_project_access, options_for_select(Project.access_options, tm.project_access), :class => "medium project-access-select", :disabled => :disabled
%td= link_to 'Edit Access', edit_admin_team_member_path(tm), :class => "btn small"
%td= link_to 'Remove from team', admin_team_member_path(tm), :confirm => 'Are you sure?', :method => :delete, :class => "btn danger small"
%td= select_tag :tm_project_access, options_for_select(Project.access_options, tm.project_access), class: "medium project-access-select", disabled: :disabled
%td= link_to 'Edit Access', edit_admin_team_member_path(tm), class: "btn small"
%td= link_to 'Remove from team', admin_team_member_path(tm), confirm: 'Are you sure?', method: :delete, class: "btn danger small"
 
%br
%h3 Add new team member
%br
= form_tag team_update_admin_project_path(@admin_project), :class => "bulk_import", :method => :put do
= form_tag team_update_admin_project_path(@admin_project), class: "bulk_import", method: :put do
%table.zebra-striped.table-bordered
%thead
%tr
Loading
Loading
@@ -67,14 +67,14 @@
%th Project Access:
 
%tr
%td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name), :multiple => true
%td= select_tag :project_access, options_for_select(Project.access_options), :class => "project-access-select"
%td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name), multiple: true
%td= select_tag :project_access, options_for_select(Project.access_options), class: "project-access-select"
 
%tr
%td= submit_tag 'Add', :class => "btn primary"
%td= submit_tag 'Add', class: "btn primary"
%td
Read more about project permissions
%strong= link_to "here", help_permissions_path, :class => "vlink"
%strong= link_to "here", help_permissions_path, class: "vlink"
 
:css
form select {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment