Merge pull request #1570 from NARKOZ/refactoring

models cleanup
This commit is contained in:
Dmitriy Zaporozhets 2012-09-27 07:06:36 -07:00
commit e0d0c1b225
21 changed files with 181 additions and 284 deletions

View file

@ -52,7 +52,6 @@ class Ability
:admin_wiki :admin_wiki
] if project.master_access_for?(user) || project.owner == user ] if project.master_access_for?(user) || project.owner == user
rules.flatten rules.flatten
end end

View file

@ -4,24 +4,11 @@ class Commit
include StaticModel include StaticModel
extend ActiveModel::Naming extend ActiveModel::Naming
attr_accessor :commit attr_accessor :commit, :head, :refs
attr_accessor :head
attr_accessor :refs
delegate :message, delegate :message, :authored_date, :committed_date, :parents, :sha,
:authored_date, :date, :committer, :author, :message, :diffs, :tree, :id,
:committed_date, :to_patch, to: :commit
:parents,
:sha,
:date,
:committer,
:author,
:message,
:diffs,
:tree,
:id,
:to_patch,
to: :commit
class << self class << self
def find_or_first(repo, commit_id = nil, root_ref) def find_or_first(repo, commit_id = nil, root_ref)
@ -30,6 +17,7 @@ class Commit
else else
repo.commits(root_ref).first repo.commits(root_ref).first
end end
Commit.new(commit) if commit Commit.new(commit) if commit
end end

View file

@ -16,6 +16,10 @@ class Event < ActiveRecord::Base
Joined = 8 # User joined project Joined = 8 # User joined project
Left = 9 # User left project Left = 9 # User left project
delegate :name, :email, to: :author, prefix: true, allow_nil: true
delegate :title, to: :issue, prefix: true, allow_nil: true
delegate :title, to: :merge_request, prefix: true, allow_nil: true
belongs_to :project belongs_to :project
belongs_to :target, polymorphic: true belongs_to :target, polymorphic: true
@ -134,25 +138,20 @@ class Event < ActiveRecord::Base
"opened" "opened"
end end
end end
delegate :name, :email, to: :author, prefix: true, allow_nil: true
delegate :title, to: :issue, prefix: true, allow_nil: true
delegate :title, to: :merge_request, prefix: true, allow_nil: true
end end
# == Schema Information # == Schema Information
# #
# Table name: events # Table name: events
# #
# id :integer(4) not null, primary key # id :integer not null, primary key
# target_type :string(255) # target_type :string(255)
# target_id :integer(4) # target_id :integer
# title :string(255) # title :string(255)
# data :text # data :text
# project_id :integer(4) # project_id :integer
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# action :integer(4) # action :integer
# author_id :integer(4) # author_id :integer
# #

View file

@ -9,8 +9,7 @@ class Issue < ActiveRecord::Base
belongs_to :milestone belongs_to :milestone
validates :description, validates :description, length: { within: 0..2000 }
length: { within: 0..2000 }
def self.open_for(user) def self.open_for(user)
opened.assigned(user) opened.assigned(user)
@ -32,22 +31,21 @@ class Issue < ActiveRecord::Base
closed_changed? && !closed closed_changed? && !closed
end end
end end
# == Schema Information # == Schema Information
# #
# Table name: issues # Table name: issues
# #
# id :integer(4) not null, primary key # id :integer not null, primary key
# title :string(255) # title :string(255)
# assignee_id :integer(4) # assignee_id :integer
# author_id :integer(4) # author_id :integer
# project_id :integer(4) # project_id :integer
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# closed :boolean(1) default(FALSE), not null # closed :boolean default(FALSE), not null
# position :integer(4) default(0) # position :integer default(0)
# critical :boolean(1) default(FALSE), not null
# branch_name :string(255) # branch_name :string(255)
# description :text # description :text
# milestone_id :integer(4) # milestone_id :integer
# #

View file

@ -6,14 +6,10 @@ class Key < ActiveRecord::Base
attr_accessible :key, :title attr_accessible :key, :title
validates :title, validates :title, presence: true, length: { within: 0..255 }
presence: true, validates :key, presence: true,
length: { within: 0..255 } length: { within: 0..5000 },
format: { :with => /ssh-.{3} / }
validates :key,
presence: true,
format: { :with => /ssh-.{3} / },
length: { within: 0..5000 }
before_save :set_identifier before_save :set_identifier
before_validation :strip_white_space before_validation :strip_white_space
@ -34,7 +30,7 @@ class Key < ActiveRecord::Base
def set_identifier def set_identifier
if is_deploy_key if is_deploy_key
self.identifier = "deploy_" + Digest::MD5.hexdigest(key) self.identifier = "deploy_#{Digest::MD5.hexdigest(key)}"
else else
self.identifier = "#{user.identifier}_#{Time.now.to_i}" self.identifier = "#{user.identifier}_#{Time.now.to_i}"
end end
@ -57,17 +53,17 @@ class Key < ActiveRecord::Base
Key.where(identifier: identifier).count == 0 Key.where(identifier: identifier).count == 0
end end
end end
# == Schema Information # == Schema Information
# #
# Table name: keys # Table name: keys
# #
# id :integer(4) not null, primary key # id :integer not null, primary key
# user_id :integer(4) # user_id :integer
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# key :text # key :text
# title :string(255) # title :string(255)
# identifier :string(255) # identifier :string(255)
# project_id :integer(4) # project_id :integer
# #

View file

@ -18,8 +18,7 @@ class MergeRequest < ActiveRecord::Base
attr_accessor :should_remove_source_branch attr_accessor :should_remove_source_branch
validates_presence_of :source_branch validates_presence_of :source_branch, :target_branch
validates_presence_of :target_branch
validate :validate_branches validate :validate_branches
def self.find_all_by_branch(branch_name) def self.find_all_by_branch(branch_name)
@ -187,23 +186,23 @@ class MergeRequest < ActiveRecord::Base
patch_path patch_path
end end
end end
# == Schema Information # == Schema Information
# #
# Table name: merge_requests # Table name: merge_requests
# #
# id :integer(4) not null, primary key # id :integer not null, primary key
# target_branch :string(255) not null # target_branch :string(255) not null
# source_branch :string(255) not null # source_branch :string(255) not null
# project_id :integer(4) not null # project_id :integer not null
# author_id :integer(4) # author_id :integer
# assignee_id :integer(4) # assignee_id :integer
# title :string(255) # title :string(255)
# closed :boolean(1) default(FALSE), not null # closed :boolean default(FALSE), not null
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# st_commits :text(2147483647 # st_commits :text(2147483647
# st_diffs :text(2147483647 # st_diffs :text(2147483647
# merged :boolean(1) default(FALSE), not null # merged :boolean default(FALSE), not null
# state :integer(4) default(1), not null # state :integer default(1), not null
# #

View file

@ -1,32 +1,17 @@
# == Schema Information
#
# Table name: milestones
#
# id :integer(4) not null, primary key
# title :string(255) not null
# project_id :integer(4) not null
# description :text
# due_date :date
# closed :boolean(1) default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Milestone < ActiveRecord::Base class Milestone < ActiveRecord::Base
attr_accessible :title, :description, :due_date, :closed attr_accessible :title, :description, :due_date, :closed
belongs_to :project belongs_to :project
has_many :issues has_many :issues
validates_presence_of :project_id validates_presence_of :title, :project_id
validates_presence_of :title
def self.active def self.active
where("due_date > ? OR due_date IS NULL", Date.today) where("due_date > ? OR due_date IS NULL", Date.today)
end end
def participants def participants
User.where(id: issues.map(&:assignee_id)) User.where(id: issues.pluck(:assignee_id))
end end
def percent_complete def percent_complete
@ -39,3 +24,17 @@ class Milestone < ActiveRecord::Base
"expires at #{due_date.stamp("Aug 21, 2011")}" if due_date "expires at #{due_date.stamp("Aug 21, 2011")}" if due_date
end end
end end
# == Schema Information
#
# Table name: milestones
#
# id :integer not null, primary key
# title :string(255) not null
# project_id :integer not null
# description :text
# due_date :date
# closed :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
#

View file

@ -2,39 +2,26 @@ require 'carrierwave/orm/activerecord'
require 'file_size_validator' require 'file_size_validator'
class Note < ActiveRecord::Base class Note < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
attr_accessible :note, :noteable, :noteable_id, :noteable_type, :project_id, attr_accessible :note, :noteable, :noteable_id, :noteable_type, :project_id,
:attachment, :line_code :attachment, :line_code
belongs_to :project belongs_to :project
belongs_to :noteable, polymorphic: true belongs_to :noteable, polymorphic: true
belongs_to :author, belongs_to :author, class_name: "User"
class_name: "User"
delegate :name, delegate :name, to: :project, prefix: true
to: :project, delegate :name, :email, to: :author, prefix: true
prefix: true
delegate :name,
:email,
to: :author,
prefix: true
attr_accessor :notify attr_accessor :notify
attr_accessor :notify_author attr_accessor :notify_author
validates_presence_of :project validates_presence_of :project
validates :note, validates :note, presence: true, length: { within: 0..5000 }
presence: true, validates :attachment, file_size: { maximum: 10.megabytes.to_i }
length: { within: 0..5000 }
validates :attachment,
file_size: {
maximum: 10.megabytes.to_i
}
scope :common, where(noteable_id: nil) scope :common, where(noteable_id: nil)
scope :today, where("created_at >= :date", date: Date.today) scope :today, where("created_at >= :date", date: Date.today)
scope :last_week, where("created_at >= :date", date: (Date.today - 7.days)) scope :last_week, where("created_at >= :date", date: (Date.today - 7.days))
scope :since, lambda { |day| where("created_at >= :date", date: (day)) } scope :since, lambda { |day| where("created_at >= :date", date: (day)) }
@ -42,14 +29,13 @@ class Note < ActiveRecord::Base
scope :inc_author_project, includes(:project, :author) scope :inc_author_project, includes(:project, :author)
scope :inc_author, includes(:author) scope :inc_author, includes(:author)
mount_uploader :attachment, AttachmentUploader
def self.create_status_change_note(noteable, author, status) def self.create_status_change_note(noteable, author, status)
create({ noteable: noteable, create({
project: noteable.project, noteable: noteable,
author: author, project: noteable.project,
note: "_Status changed to #{status}_" }, author: author,
without_protection: true) note: "_Status changed to #{status}_"
}, without_protection: true)
end end
def notify def notify
@ -114,19 +100,19 @@ class Note < ActiveRecord::Base
note.start_with?('-1') || note.start_with?(':-1:') note.start_with?('-1') || note.start_with?(':-1:')
end end
end end
# == Schema Information # == Schema Information
# #
# Table name: notes # Table name: notes
# #
# id :integer(4) not null, primary key # id :integer not null, primary key
# note :text # note :text
# noteable_id :string(255) # noteable_id :string(255)
# noteable_type :string(255) # noteable_type :string(255)
# author_id :integer(4) # author_id :integer
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# project_id :integer(4) # project_id :integer
# attachment :string(255) # attachment :string(255)
# line_code :string(255) # line_code :string(255)
# #

View file

@ -8,10 +8,9 @@ class Project < ActiveRecord::Base
attr_accessible :name, :path, :description, :code, :default_branch, :issues_enabled, attr_accessible :name, :path, :description, :code, :default_branch, :issues_enabled,
:wall_enabled, :merge_requests_enabled, :wiki_enabled :wall_enabled, :merge_requests_enabled, :wiki_enabled
attr_accessor :error_code
#
# Relations # Relations
#
belongs_to :owner, class_name: "User" belongs_to :owner, class_name: "User"
has_many :users, through: :users_projects has_many :users, through: :users_projects
has_many :events, dependent: :destroy has_many :events, dependent: :destroy
@ -26,11 +25,7 @@ class Project < ActiveRecord::Base
has_many :wikis, dependent: :destroy has_many :wikis, dependent: :destroy
has_many :protected_branches, dependent: :destroy has_many :protected_branches, dependent: :destroy
attr_accessor :error_code
#
# Scopes # Scopes
#
scope :public_only, where(private_flag: false) scope :public_only, where(private_flag: false)
scope :without_user, lambda { |user| where("id not in (:ids)", ids: user.projects.map(&:id) ) } scope :without_user, lambda { |user| where("id not in (:ids)", ids: user.projects.map(&:id) ) }
@ -47,7 +42,6 @@ class Project < ActiveRecord::Base
Project.transaction do Project.transaction do
project.owner = user project.owner = user
project.save! project.save!
# Add user as project master # Add user as project master
@ -76,36 +70,19 @@ class Project < ActiveRecord::Base
id && valid? id && valid?
end end
#
# Validations # Validations
#
validates :name,
uniqueness: true,
presence: true,
length: { within: 0..255 }
validates :path,
uniqueness: true,
presence: true,
format: { with: /^[a-zA-Z][a-zA-Z0-9_\-\.]*$/,
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" },
length: { within: 0..255 }
validates :description,
length: { within: 0..2000 }
validates :code,
presence: true,
uniqueness: true,
format: { with: /^[a-zA-Z][a-zA-Z0-9_\-\.]*$/,
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" },
length: { within: 1..255 }
validates :owner, presence: true validates :owner, presence: true
validates :description, length: { within: 0..2000 }
validates :name, uniqueness: true, presence: true, length: { within: 0..255 }
validates :path, uniqueness: true, presence: true, length: { within: 0..255 },
format: { with: /\A[a-zA-Z][a-zA-Z0-9_\-\.]*\z/,
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
validates :code, presence: true, uniqueness: true, length: { within: 1..255 },
format: { with: /\A[a-zA-Z][a-zA-Z0-9_\-\.]*\z/,
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
validates :issues_enabled, :wall_enabled, :merge_requests_enabled, validates :issues_enabled, :wall_enabled, :merge_requests_enabled,
:wiki_enabled, inclusion: { in: [true, false] } :wiki_enabled, inclusion: { in: [true, false] }
validate :check_limit validate :check_limit, :repo_name
validate :repo_name
def check_limit def check_limit
unless owner.can_create_project? unless owner.can_create_project?
@ -170,7 +147,7 @@ class Project < ActiveRecord::Base
end end
def wiki_notes def wiki_notes
Note.where(noteable_id: wikis.map(&:id), noteable_type: 'Wiki', project_id: self.id) Note.where(noteable_id: wikis.pluck(:id), noteable_type: 'Wiki', project_id: self.id)
end end
def project_id def project_id
@ -182,19 +159,18 @@ end
# #
# Table name: projects # Table name: projects
# #
# id :integer(4) not null, primary key # id :integer not null, primary key
# name :string(255) # name :string(255)
# path :string(255) # path :string(255)
# description :text # description :text
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# private_flag :boolean(1) default(TRUE), not null # private_flag :boolean default(TRUE), not null
# code :string(255) # code :string(255)
# owner_id :integer(4) # owner_id :integer
# default_branch :string(255) # default_branch :string(255)
# issues_enabled :boolean(1) default(TRUE), not null # issues_enabled :boolean default(TRUE), not null
# wall_enabled :boolean(1) default(TRUE), not null # wall_enabled :boolean default(TRUE), not null
# merge_requests_enabled :boolean(1) default(TRUE), not null # merge_requests_enabled :boolean default(TRUE), not null
# wiki_enabled :boolean(1) default(TRUE), not null # wiki_enabled :boolean default(TRUE), not null
# #

View file

@ -1,3 +1,15 @@
class ProjectHook < WebHook class ProjectHook < WebHook
belongs_to :project belongs_to :project
end end
# == Schema Information
#
# Table name: web_hooks
#
# id :integer not null, primary key
# url :string(255)
# project_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# type :string(255) default("ProjectHook")
#

View file

@ -4,8 +4,7 @@ class ProtectedBranch < ActiveRecord::Base
attr_accessible :name attr_accessible :name
belongs_to :project belongs_to :project
validates_presence_of :project_id validates_presence_of :name, :project_id
validates_presence_of :name
after_save :update_repository after_save :update_repository
after_destroy :update_repository after_destroy :update_repository
@ -18,14 +17,14 @@ class ProtectedBranch < ActiveRecord::Base
project.commit(self.name) project.commit(self.name)
end end
end end
# == Schema Information # == Schema Information
# #
# Table name: protected_branches # Table name: protected_branches
# #
# id :integer(4) not null, primary key # id :integer not null, primary key
# project_id :integer(4) not null # project_id :integer not null
# name :string(255) not null # name :string(255) not null
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# #

View file

@ -7,25 +7,12 @@ class Snippet < ActiveRecord::Base
belongs_to :author, class_name: "User" belongs_to :author, class_name: "User"
has_many :notes, as: :noteable, dependent: :destroy has_many :notes, as: :noteable, dependent: :destroy
delegate :name, delegate :name, :email, to: :author, prefix: true
:email,
to: :author,
prefix: true
validates_presence_of :project_id validates_presence_of :author_id, :project_id
validates_presence_of :author_id validates :title, presence: true, length: { within: 0..255 }
validates :file_name, presence: true, length: { within: 0..255 }
validates :title, validates :content, presence: true, length: { within: 0..10000 }
presence: true,
length: { within: 0..255 }
validates :file_name,
presence: true,
length: { within: 0..255 }
validates :content,
presence: true,
length: { within: 0..10000 }
scope :fresh, order("created_at DESC") scope :fresh, order("created_at DESC")
scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current]) scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current])
@ -59,18 +46,18 @@ class Snippet < ActiveRecord::Base
expires_at && expires_at < Time.current expires_at && expires_at < Time.current
end end
end end
# == Schema Information # == Schema Information
# #
# Table name: snippets # Table name: snippets
# #
# id :integer(4) not null, primary key # id :integer not null, primary key
# title :string(255) # title :string(255)
# content :text # content :text
# author_id :integer(4) not null # author_id :integer not null
# project_id :integer(4) not null # project_id :integer not null
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# file_name :string(255) # file_name :string(255)
# expires_at :datetime # expires_at :datetime
# #

View file

@ -1,5 +1,4 @@
class SystemHook < WebHook class SystemHook < WebHook
def async_execute(data) def async_execute(data)
Resque.enqueue(SystemHookWorker, id, data) Resque.enqueue(SystemHookWorker, id, data)
end end
@ -9,5 +8,16 @@ class SystemHook < WebHook
sh.async_execute data sh.async_execute data
end end
end end
end end
# == Schema Information
#
# Table name: web_hooks
#
# id :integer not null, primary key
# url :string(255)
# project_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# type :string(255) default("ProjectHook")
#

View file

@ -2,16 +2,8 @@ class Tree
include Linguist::BlobHelper include Linguist::BlobHelper
attr_accessor :path, :tree, :project, :ref attr_accessor :path, :tree, :project, :ref
delegate :contents, delegate :contents, :basename, :name, :data, :mime_type,
:basename, :mode, :size, :text?, :colorize, to: :tree
:name,
:data,
:mime_type,
:mode,
:size,
:text?,
:colorize,
to: :tree
def initialize(raw_tree, project, ref = nil, path = nil) def initialize(raw_tree, project, ref = nil, path = nil)
@project, @ref, @path = project, ref, path @project, @ref, @path = project, ref, path

View file

@ -1,64 +1,31 @@
class User < ActiveRecord::Base class User < ActiveRecord::Base
include Account include Account
devise :database_authenticatable, :token_authenticatable, :lockable, devise :database_authenticatable, :token_authenticatable, :lockable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable :recoverable, :rememberable, :trackable, :validatable, :omniauthable
attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name,
:name, :skype, :linkedin, :twitter, :dark_scheme, :skype, :linkedin, :twitter, :dark_scheme, :theme_id, :force_random_password,
:theme_id, :force_random_password, :extern_uid, :provider, :as => [:default, :admin] :extern_uid, :provider, :as => [:default, :admin]
attr_accessible :projects_limit, :as => :admin attr_accessible :projects_limit, :as => :admin
attr_accessor :force_random_password 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 :keys, dependent: :destroy
has_many :projects, through: :users_projects
has_many :events, has_many :users_projects, dependent: :destroy
class_name: "Event", has_many :issues, foreign_key: :author_id, dependent: :destroy
foreign_key: :author_id, has_many :notes, foreign_key: :author_id, dependent: :destroy
dependent: :destroy has_many :merge_requests, foreign_key: :author_id, dependent: :destroy
has_many :my_own_projects, class_name: "Project", foreign_key: :owner_id
has_many :recent_events, has_many :events, class_name: "Event", foreign_key: :author_id, dependent: :destroy
class_name: "Event", has_many :recent_events, class_name: "Event", foreign_key: :author_id, order: "id DESC"
foreign_key: :author_id, has_many :assigned_issues, class_name: "Issue", foreign_key: :assignee_id, dependent: :destroy
order: "id DESC" has_many :assigned_merge_requests, class_name: "MergeRequest", foreign_key: :assignee_id, dependent: :destroy
has_many :issues,
foreign_key: :author_id,
dependent: :destroy
has_many :notes,
foreign_key: :author_id,
dependent: :destroy
has_many :assigned_issues,
class_name: "Issue",
foreign_key: :assignee_id,
dependent: :destroy
has_many :merge_requests,
foreign_key: :author_id,
dependent: :destroy
has_many :assigned_merge_requests,
class_name: "MergeRequest",
foreign_key: :assignee_id,
dependent: :destroy
validates :projects_limit,
presence: true,
numericality: {greater_than_or_equal_to: 0}
validates :bio, length: { within: 0..255 } validates :bio, length: { within: 0..255 }
validates :extern_uid, :allow_blank => true, :uniqueness => {:scope => :provider} validates :extern_uid, :allow_blank => true, :uniqueness => {:scope => :provider}
validates :projects_limit, presence: true, numericality: {greater_than_or_equal_to: 0}
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 :not_in_project, lambda { |project| where("id not in (:ids)", ids: project.users.map(&:id) ) }
scope :admins, where(admin: true) scope :admins, where(admin: true)
@ -66,6 +33,8 @@ class User < ActiveRecord::Base
scope :active, where(blocked: false) scope :active, where(blocked: false)
before_validation :generate_password, on: :create before_validation :generate_password, on: :create
before_save :ensure_authentication_token
alias_attribute :private_token, :authentication_token
def generate_password def generate_password
if self.force_random_password if self.force_random_password
@ -107,17 +76,18 @@ class User < ActiveRecord::Base
where("name like :query or email like :query", query: "%#{query}%") where("name like :query or email like :query", query: "%#{query}%")
end end
end end
# == Schema Information # == Schema Information
# #
# Table name: users # Table name: users
# #
# id :integer(4) not null, primary key # id :integer not null, primary key
# email :string(255) default(""), not null # email :string(255) default(""), not null
# encrypted_password :string(128) default(""), not null # encrypted_password :string(128) default(""), not null
# reset_password_token :string(255) # reset_password_token :string(255)
# reset_password_sent_at :datetime # reset_password_sent_at :datetime
# remember_created_at :datetime # remember_created_at :datetime
# sign_in_count :integer(4) default(0) # sign_in_count :integer default(0)
# current_sign_in_at :datetime # current_sign_in_at :datetime
# last_sign_in_at :datetime # last_sign_in_at :datetime
# current_sign_in_ip :string(255) # current_sign_in_ip :string(255)
@ -125,14 +95,18 @@ end
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# name :string(255) # name :string(255)
# admin :boolean(1) default(FALSE), not null # admin :boolean default(FALSE), not null
# projects_limit :integer(4) default(10) # projects_limit :integer default(10)
# skype :string(255) default(""), not null # skype :string(255) default(""), not null
# linkedin :string(255) default(""), not null # linkedin :string(255) default(""), not null
# twitter :string(255) default(""), not null # twitter :string(255) default(""), not null
# authentication_token :string(255) # authentication_token :string(255)
# dark_scheme :boolean(1) default(FALSE), not null # dark_scheme :boolean default(FALSE), not null
# theme_id :integer(4) default(1), not null # theme_id :integer default(1), not null
# bio :string(255) # bio :string(255)
# blocked :boolean(1) default(FALSE), not null # blocked :boolean default(FALSE), not null
# failed_attempts :integer default(0)
# locked_at :datetime
# extern_uid :string(255)
# provider :string(255)
# #

View file

@ -88,15 +88,15 @@ class UsersProject < ActiveRecord::Base
self.class.access_roles.invert[self.project_access] self.class.access_roles.invert[self.project_access]
end end
end end
# == Schema Information # == Schema Information
# #
# Table name: users_projects # Table name: users_projects
# #
# id :integer(4) not null, primary key # id :integer not null, primary key
# user_id :integer(4) not null # user_id :integer not null
# project_id :integer(4) not null # project_id :integer not null
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# project_access :integer(4) default(0), not null # project_access :integer default(0), not null
# #

View file

@ -6,34 +6,31 @@ class WebHook < ActiveRecord::Base
# HTTParty timeout # HTTParty timeout
default_timeout 10 default_timeout 10
validates :url, validates :url, presence: true,
presence: true, format: { with: URI::regexp(%w(http https)), message: "should be a valid url" }
format: {
with: URI::regexp(%w(http https)),
message: "should be a valid url" }
def execute(data) def execute(data)
parsed_url = URI.parse(url) parsed_url = URI.parse(url)
if parsed_url.userinfo.blank? if parsed_url.userinfo.blank?
WebHook.post(url, body: data.to_json, headers: { "Content-Type" => "application/json" }) WebHook.post(url, body: data.to_json, headers: { "Content-Type" => "application/json" })
else else
post_url = url.gsub(parsed_url.userinfo+"@", "") post_url = url.gsub("#{parsed_url.userinfo}@", "")
WebHook.post(post_url, WebHook.post(post_url,
body: data.to_json, body: data.to_json,
headers: { "Content-Type" => "application/json" }, headers: {"Content-Type" => "application/json"},
basic_auth: {username: parsed_url.user, password: parsed_url.password}) basic_auth: {username: parsed_url.user, password: parsed_url.password})
end end
end end
end end
# == Schema Information # == Schema Information
# #
# Table name: web_hooks # Table name: web_hooks
# #
# id :integer(4) not null, primary key # id :integer not null, primary key
# url :string(255) # url :string(255)
# project_id :integer(4) # project_id :integer
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# type :string(255) default("ProjectHook")
# #

View file

@ -32,17 +32,17 @@ class Wiki < ActiveRecord::Base
end end
end end
end end
# == Schema Information # == Schema Information
# #
# Table name: wikis # Table name: wikis
# #
# id :integer(4) not null, primary key # id :integer not null, primary key
# title :string(255) # title :string(255)
# content :text # content :text
# project_id :integer(4) # project_id :integer
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# slug :string(255) # slug :string(255)
# user_id :integer(4) # user_id :integer
# #

View file

@ -9,13 +9,12 @@ production:
pool: 5 pool: 5
username: root username: root
password: "secure password" password: "secure password"
# host: localhost
# socket: /tmp/mysql.sock # socket: /tmp/mysql.sock
# #
# Development specific # Development specific
# #
#
development: development:
adapter: mysql2 adapter: mysql2
encoding: utf8 encoding: utf8
@ -38,6 +37,3 @@ test: &test
username: root username: root
password: "secure password" password: "secure password"
# socket: /tmp/mysql.sock # socket: /tmp/mysql.sock
cucumber:
<<: *test

View file

@ -9,13 +9,12 @@ production:
pool: 5 pool: 5
username: root username: root
password: "secure password" password: "secure password"
# host: localhost
# socket: /tmp/mysql.sock # socket: /tmp/mysql.sock
# #
# Development specific # Development specific
# #
#
development: development:
adapter: mysql2 adapter: mysql2
encoding: utf8 encoding: utf8
@ -38,6 +37,3 @@ test: &test
username: root username: root
password: password:
# socket: /tmp/mysql.sock # socket: /tmp/mysql.sock
cucumber:
<<: *test

View file

@ -12,12 +12,9 @@ production:
pool: 5 pool: 5
timeout: 5000 timeout: 5000
# #
# Development specific # Development specific
# #
#
#
development: development:
adapter: sqlite3 adapter: sqlite3
database: db/development.sqlite3 database: db/development.sqlite3
@ -32,6 +29,3 @@ test: &test
database: db/test.sqlite3 database: db/test.sqlite3
pool: 5 pool: 5
timeout: 5000 timeout: 5000
cucumber:
<<: *test