Created new models and provided relationships between them.

This commit is contained in:
George Vinogradov 2011-10-13 19:55:03 +04:00
parent f3d32273d8
commit 229b4bb3f4
26 changed files with 225 additions and 3 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ public/stylesheets/compiled/*
public/assets/*
config/initializers/local.rb
public/system/*
.rvmrc

View File

@ -36,6 +36,7 @@ group :development, :test do
gem 'web-app-theme', '>= 0.6.2'
gem 'hpricot'
gem 'ruby_parser'
gem 'mysql2', '<= 0.2.9'
end
gem "devise"

View File

@ -81,6 +81,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
mysql2 (0.2.9)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
@ -158,6 +159,7 @@ DEPENDENCIES
haml-rails
hpricot
jammit
mysql2 (<= 0.2.9)
paperclip (~> 2.3)
pg
rails (= 3.0.5)

11
app/models/group.rb Normal file
View File

@ -0,0 +1,11 @@
class Group < ActiveRecord::Base
belongs_to :owner, :class_name => 'User'
has_many :objects, :as => :target, :class_name => 'Relation'
has_many :targets, :as => :object, :class_name => 'Relation'
has_many :users, :through => :objects, :source => :object, :source_type => 'User', :autosave => true
has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true
has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true
has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true
end

4
app/models/permission.rb Normal file
View File

@ -0,0 +1,4 @@
class Permission < ActiveRecord::Base
belongs_to :right
belongs_to :role
end

View File

@ -4,6 +4,10 @@ class Platform < ActiveRecord::Base
has_many :repositories, :dependent => :destroy
has_many :products, :dependent => :destroy
has_many :objects, :as => :target, :class_name => 'Relation'
has_many :members, :through => :objects, :source => :object, :source_type => 'User'
has_many :groups, :through => :objects, :source => :object, :source_type => 'Group'
validates :name, :presence => true, :uniqueness => true
validates :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false

View File

@ -1,7 +1,12 @@
class Project < ActiveRecord::Base
belongs_to :repository
has_many :build_lists, :dependent => :destroy
has_many :repositories, :through => :project_to_repository
has_many :members, :as => :target, :class_name => 'Relation'
has_many :collaborators, :through => :members, :source => :object, :source_type = 'User'
has_many :groups, :through => :members, :source => :object, :source_type = 'Group'
validates :name, :uniqueness => {:scope => :repository_id}, :presence => true, :allow_nil => false, :allow_blank => false
validates :unixname, :uniqueness => {:scope => :repository_id}, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false

View File

@ -0,0 +1,4 @@
class ProjectToRepository < ActiveRecord::Base
belongs_to :project
belongs_to :repository
end

5
app/models/relation.rb Normal file
View File

@ -0,0 +1,5 @@
class Relation < ActiveRecord::Base
belongs_to :target, :polymorphic => true
belongs_to :object, :polymorphic => true
belongs_to :role
end

View File

@ -1,6 +1,10 @@
class Repository < ActiveRecord::Base
belongs_to :platform
has_many :projects, :dependent => :destroy
has_many :projects, :through => :project_to_repository #, :dependent => :destroy
has_many :objects, :as => :target, :class_name => 'Relation'
has_many :members, :through => :objects, :source => :object, :source_type => 'User'
has_many :groups, :through => :objects, :source => :object, :source_type => 'Group'
validates :name, :uniqueness => {:scope => :platform_id}, :presence => true
validates :unixname, :uniqueness => {:scope => :platform_id}, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }

2
app/models/right.rb Normal file
View File

@ -0,0 +1,2 @@
class Right < ActiveRecord::Base
end

5
app/models/role.rb Normal file
View File

@ -0,0 +1,5 @@
class Role < ActiveRecord::Base
has_many :permissions
has_many :rights, :through => :permissions
has_many :relations
end

View File

@ -1,5 +1,13 @@
require 'digest/md5'
class User < ActiveRecord::Base
has_many :targets, :as => :object, :class_name => 'Relation'
has_many :groups, :through => :targets, :source => :target, :source_type => 'Group', :autosave => true
has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true
has_many :platforms, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true
has_many :repositories, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true
devise :database_authenticatable,
:recoverable, :rememberable, :validatable

View File

@ -0,0 +1,14 @@
class CreateRights < ActiveRecord::Migration
def self.up
create_table :rights do |t|
t.integer :id
t.string :name
t.timestamps
end
end
def self.down
drop_table :rights
end
end

View File

@ -0,0 +1,15 @@
class CreatePermissions < ActiveRecord::Migration
def self.up
create_table :permissions do |t|
t.integer :id
t.integer :right_id
t.integer :role_id
t.timestamps
end
end
def self.down
drop_table :permissions
end
end

View File

@ -0,0 +1,16 @@
class CreateRoles < ActiveRecord::Migration
def self.up
create_table :roles do |t|
t.integer :id
t.string :name
t.string :to
t.string :on
t.timestamps
end
end
def self.down
drop_table :roles
end
end

View File

@ -0,0 +1,17 @@
class CreateRelations < ActiveRecord::Migration
def self.up
create_table :relations do |t|
t.integer :object_id
t.string :object_type
t.integer :target_id
t.string :target_type
t.integer :role_id
t.timestamps
end
end
def self.down
drop_table :relations
end
end

View File

@ -0,0 +1,14 @@
class CreateGroups < ActiveRecord::Migration
def self.up
create_table :groups do |t|
t.string :name
t.integer :owner_id
t.timestamps
end
end
def self.down
drop_table :groups
end
end

View File

@ -0,0 +1,15 @@
class CreateProjectToRepositories < ActiveRecord::Migration
def self.up
create_table :project_to_repositories do |t|
t.integer :id
t.integer :project_id
t.integer :repository_id
t.timestamps
end
end
def self.down
drop_table :project_to_repositories
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110428140753) do
ActiveRecord::Schema.define(:version => 20111013150125) do
create_table "arches", :force => true do |t|
t.string "name", :null => false
@ -73,6 +73,20 @@ ActiveRecord::Schema.define(:version => 20110428140753) do
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
create_table "groups", :force => true do |t|
t.string "name"
t.integer "owner_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "permissions", :force => true do |t|
t.integer "right_id"
t.integer "role_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "platforms", :force => true do |t|
t.string "name"
t.string "unixname"
@ -103,6 +117,13 @@ ActiveRecord::Schema.define(:version => 20110428140753) do
t.boolean "use_cron", :default => false
end
create_table "project_to_repositories", :force => true do |t|
t.integer "project_id"
t.integer "repository_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "projects", :force => true do |t|
t.string "name"
t.string "unixname"
@ -111,6 +132,16 @@ ActiveRecord::Schema.define(:version => 20110428140753) do
t.integer "repository_id", :null => false
end
create_table "relations", :force => true do |t|
t.integer "object_id"
t.string "object_type"
t.integer "target_id"
t.string "target_type"
t.integer "role_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "repositories", :force => true do |t|
t.string "name", :null => false
t.integer "platform_id", :null => false
@ -119,6 +150,20 @@ ActiveRecord::Schema.define(:version => 20110428140753) do
t.string "unixname", :null => false
end
create_table "rights", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "roles", :force => true do |t|
t.string "name"
t.string "to"
t.string "on"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "rpms", :force => true do |t|
t.string "name", :null => false
t.integer "arch_id", :null => false

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Group do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Permission do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe ProjectToRepository do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Relation do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Right do
pending "add some examples to (or delete) #{__FILE__}"
end

5
spec/models/role_spec.rb Normal file
View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Role do
pending "add some examples to (or delete) #{__FILE__}"
end