diff --git a/.gitignore b/.gitignore index dd86dc098..2774c7312 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ public/stylesheets/compiled/* public/assets/* config/initializers/local.rb public/system/* +.rvmrc diff --git a/Gemfile b/Gemfile index c4e9780d0..400fd1879 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index 5582f021e..2c4ef8509 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/models/group.rb b/app/models/group.rb new file mode 100644 index 000000000..de53d5c40 --- /dev/null +++ b/app/models/group.rb @@ -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 diff --git a/app/models/permission.rb b/app/models/permission.rb new file mode 100644 index 000000000..da2599966 --- /dev/null +++ b/app/models/permission.rb @@ -0,0 +1,4 @@ +class Permission < ActiveRecord::Base + belongs_to :right + belongs_to :role +end diff --git a/app/models/platform.rb b/app/models/platform.rb index a0a6bf8ca..5921ddd55 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index e925a8070..555e1d087 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb new file mode 100644 index 000000000..e18381fd1 --- /dev/null +++ b/app/models/project_to_repository.rb @@ -0,0 +1,4 @@ +class ProjectToRepository < ActiveRecord::Base + belongs_to :project + belongs_to :repository +end diff --git a/app/models/relation.rb b/app/models/relation.rb new file mode 100644 index 000000000..c351cffcb --- /dev/null +++ b/app/models/relation.rb @@ -0,0 +1,5 @@ +class Relation < ActiveRecord::Base + belongs_to :target, :polymorphic => true + belongs_to :object, :polymorphic => true + belongs_to :role +end diff --git a/app/models/repository.rb b/app/models/repository.rb index 247010c60..2db832487 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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\-.]+$/ } diff --git a/app/models/right.rb b/app/models/right.rb new file mode 100644 index 000000000..8289fc2e8 --- /dev/null +++ b/app/models/right.rb @@ -0,0 +1,2 @@ +class Right < ActiveRecord::Base +end diff --git a/app/models/role.rb b/app/models/role.rb new file mode 100644 index 000000000..cf9a70496 --- /dev/null +++ b/app/models/role.rb @@ -0,0 +1,5 @@ +class Role < ActiveRecord::Base + has_many :permissions + has_many :rights, :through => :permissions + has_many :relations +end diff --git a/app/models/user.rb b/app/models/user.rb index 37d2e86bb..3d926fa0a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/db/migrate/20111012222824_create_rights.rb b/db/migrate/20111012222824_create_rights.rb new file mode 100644 index 000000000..37f5cfaaf --- /dev/null +++ b/db/migrate/20111012222824_create_rights.rb @@ -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 diff --git a/db/migrate/20111012223006_create_permissions.rb b/db/migrate/20111012223006_create_permissions.rb new file mode 100644 index 000000000..8001623a4 --- /dev/null +++ b/db/migrate/20111012223006_create_permissions.rb @@ -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 diff --git a/db/migrate/20111012223306_create_roles.rb b/db/migrate/20111012223306_create_roles.rb new file mode 100644 index 000000000..947201455 --- /dev/null +++ b/db/migrate/20111012223306_create_roles.rb @@ -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 diff --git a/db/migrate/20111012223521_create_relations.rb b/db/migrate/20111012223521_create_relations.rb new file mode 100644 index 000000000..b29830025 --- /dev/null +++ b/db/migrate/20111012223521_create_relations.rb @@ -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 diff --git a/db/migrate/20111012223944_create_groups.rb b/db/migrate/20111012223944_create_groups.rb new file mode 100644 index 000000000..c5b3522ea --- /dev/null +++ b/db/migrate/20111012223944_create_groups.rb @@ -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 diff --git a/db/migrate/20111013150125_create_project_to_repositories.rb b/db/migrate/20111013150125_create_project_to_repositories.rb new file mode 100644 index 000000000..148561c4c --- /dev/null +++ b/db/migrate/20111013150125_create_project_to_repositories.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 727a3cb43..b21ea15d2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb new file mode 100644 index 000000000..8f2de370f --- /dev/null +++ b/spec/models/group_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Group do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/permission_spec.rb b/spec/models/permission_spec.rb new file mode 100644 index 000000000..60a42775b --- /dev/null +++ b/spec/models/permission_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Permission do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/project_to_repository_spec.rb b/spec/models/project_to_repository_spec.rb new file mode 100644 index 000000000..f908dee57 --- /dev/null +++ b/spec/models/project_to_repository_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe ProjectToRepository do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/relation_spec.rb b/spec/models/relation_spec.rb new file mode 100644 index 000000000..da5c5a4ff --- /dev/null +++ b/spec/models/relation_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Relation do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/right_spec.rb b/spec/models/right_spec.rb new file mode 100644 index 000000000..d866fdc4f --- /dev/null +++ b/spec/models/right_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Right do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb new file mode 100644 index 000000000..b575576c3 --- /dev/null +++ b/spec/models/role_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Role do + pending "add some examples to (or delete) #{__FILE__}" +end