From 229b4bb3f4bcfe6d030d1da1e12f860659336e17 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Thu, 13 Oct 2011 19:55:03 +0400 Subject: [PATCH 01/19] Created new models and provided relationships between them. --- .gitignore | 1 + Gemfile | 1 + Gemfile.lock | 2 + app/models/group.rb | 11 +++++ app/models/permission.rb | 4 ++ app/models/platform.rb | 4 ++ app/models/project.rb | 7 ++- app/models/project_to_repository.rb | 4 ++ app/models/relation.rb | 5 ++ app/models/repository.rb | 6 ++- app/models/right.rb | 2 + app/models/role.rb | 5 ++ app/models/user.rb | 8 ++++ db/migrate/20111012222824_create_rights.rb | 14 ++++++ .../20111012223006_create_permissions.rb | 15 ++++++ db/migrate/20111012223306_create_roles.rb | 16 +++++++ db/migrate/20111012223521_create_relations.rb | 17 +++++++ db/migrate/20111012223944_create_groups.rb | 14 ++++++ ...13150125_create_project_to_repositories.rb | 15 ++++++ db/schema.rb | 47 ++++++++++++++++++- spec/models/group_spec.rb | 5 ++ spec/models/permission_spec.rb | 5 ++ spec/models/project_to_repository_spec.rb | 5 ++ spec/models/relation_spec.rb | 5 ++ spec/models/right_spec.rb | 5 ++ spec/models/role_spec.rb | 5 ++ 26 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 app/models/group.rb create mode 100644 app/models/permission.rb create mode 100644 app/models/project_to_repository.rb create mode 100644 app/models/relation.rb create mode 100644 app/models/right.rb create mode 100644 app/models/role.rb create mode 100644 db/migrate/20111012222824_create_rights.rb create mode 100644 db/migrate/20111012223006_create_permissions.rb create mode 100644 db/migrate/20111012223306_create_roles.rb create mode 100644 db/migrate/20111012223521_create_relations.rb create mode 100644 db/migrate/20111012223944_create_groups.rb create mode 100644 db/migrate/20111013150125_create_project_to_repositories.rb create mode 100644 spec/models/group_spec.rb create mode 100644 spec/models/permission_spec.rb create mode 100644 spec/models/project_to_repository_spec.rb create mode 100644 spec/models/relation_spec.rb create mode 100644 spec/models/right_spec.rb create mode 100644 spec/models/role_spec.rb 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 From 91cc89d31ce9da709f55d3ccdfa4352e092f82c6 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 14 Oct 2011 02:35:16 +0400 Subject: [PATCH 02/19] Some fixed bugs in models. Fixed: Project, Repository --- app/models/project.rb | 7 ++++--- app/models/repository.rb | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 555e1d087..c1fcf68e5 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,11 +1,12 @@ class Project < ActiveRecord::Base has_many :build_lists, :dependent => :destroy - has_many :repositories, :through => :project_to_repository + has_many :project_to_repositories + has_many :repositories, :through => :project_to_repositories 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' + 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/repository.rb b/app/models/repository.rb index 2db832487..b4e19fd2a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1,6 +1,8 @@ class Repository < ActiveRecord::Base belongs_to :platform - has_many :projects, :through => :project_to_repository #, :dependent => :destroy + + has_many :projects, :through => :project_to_repositories #, :dependent => :destroy + has_many :project_to_repositories has_many :objects, :as => :target, :class_name => 'Relation' has_many :members, :through => :objects, :source => :object, :source_type => 'User' @@ -11,8 +13,8 @@ class Repository < ActiveRecord::Base scope :recent, order("name ASC") - before_create :xml_rpc_create - before_destroy :xml_rpc_destroy +# before_create :xml_rpc_create +# before_destroy :xml_rpc_destroy def path build_path(unixname) From f76a3aee39ad8f709faa0a3013eec0c48dc13b59 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 17 Oct 2011 00:39:45 +0400 Subject: [PATCH 03/19] Added groups representation. --- app/controllers/groups_controller.rb | 50 +++++++++++++++++++ app/models/group.rb | 20 +++++++- app/views/groups/_form.html.haml | 13 +++++ app/views/groups/_list.html.haml | 24 +++++++++ app/views/groups/_sidebar.html.haml | 5 ++ app/views/groups/edit.html.haml | 12 +++++ app/views/groups/index.html.haml | 7 +++ app/views/groups/new.html.haml | 11 ++++ app/views/groups/show.html.haml | 39 +++++++++++++++ app/views/layouts/application.html.haml | 4 ++ app/views/platforms/_list.html.haml | 28 +++++++++++ app/views/projects/_list.html.haml | 28 +++++++++++ app/views/repositories/_list.html.haml | 28 +++++++++++ .../20111016130557_add_uname_to_groups.rb | 9 ++++ 14 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 app/controllers/groups_controller.rb create mode 100644 app/views/groups/_form.html.haml create mode 100644 app/views/groups/_list.html.haml create mode 100644 app/views/groups/_sidebar.html.haml create mode 100644 app/views/groups/edit.html.haml create mode 100644 app/views/groups/index.html.haml create mode 100644 app/views/groups/new.html.haml create mode 100644 app/views/groups/show.html.haml create mode 100644 app/views/platforms/_list.html.haml create mode 100644 app/views/projects/_list.html.haml create mode 100644 app/views/repositories/_list.html.haml create mode 100644 db/migrate/20111016130557_add_uname_to_groups.rb diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb new file mode 100644 index 000000000..5e47b5a78 --- /dev/null +++ b/app/controllers/groups_controller.rb @@ -0,0 +1,50 @@ +# coding: UTF-8 + +class GroupsController < ApplicationController + before_filter :authenticate_user! + + before_filter :find_group, :only => [:show, :edit, :update, :destroy] + + def index + @groups = Group.paginate(:page => params[:page], :per_page => 15) + end + + def show + @platforms = @group.platforms.paginate(:page => params[:platform_page], :per_page => 10) + @repositories = @group.repositories.paginate(:page => params[:repository_page], :per_page => 10) + @projects = @group.projects.paginate(:page => params[:project_page], :per_page => 10) + end + + def edit + end + + def destroy + @user.destroy + + flash[:notice] = t("flash.group.destroyed") + redirect_to groups_path + end + + def new + @group = Group.new + end + + def create + @group = Group.new params[:group] + @group.owner = current_user + @group.members << current_user + if @group.save + flash[:notice] = t('flash.group.saved') + redirect_to edit_group_path(@group) + else + flash[:error] = t('flash.group.save_error') + render :action => :new + end + end + + private + def find_group + @group = Group.find(params[:id]) + end + +end diff --git a/app/models/group.rb b/app/models/group.rb index de53d5c40..3866664f9 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,11 +1,29 @@ class Group < ActiveRecord::Base + + validates :name, :uname, :owner_id, :presence => true + validates :name, :uname, :uniqueness => true + 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 :members, :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 + + def roles_of(user) + objects.where(:object_id => user.id, :object_type => user.class).map {|rel| rel.role}.reject {|r| r.nil?} + end + + def add_role(user, role) + roles = objects.where(:object_id => user.id, :object_type => user.class).map {|rel| rel.role}.reject {|r| r.nil?} + unless roles.include? role + rel = Relation.create(:object_type => user.class.to_s, :object_id => user.id, + :target_type => self.class.to_s, :target_id => id) + rel.role = role + rel.save + end + end end diff --git a/app/views/groups/_form.html.haml b/app/views/groups/_form.html.haml new file mode 100644 index 000000000..7fe4a3e9a --- /dev/null +++ b/app/views/groups/_form.html.haml @@ -0,0 +1,13 @@ +.group + = f.label :name, t("activerecord.attributes.group.name"), :class => :label + = f.text_field :name, :class => 'text_field' +.group + = f.label :uname, t("activerecord.attributes.group.uname"), :class => :label + = f.text_field :uname, :class => 'text_field' + +.group.navform.wat-cf + %button.button{:type => "submit"} + = image_tag("web-app-theme/icons/tick.png", :alt => t("layout.save")) + = t("layout.save") + %span.text_button_padding= t("layout.or") + = link_to t("layout.cancel"), users_path, :class => "text_button_padding link_button" diff --git a/app/views/groups/_list.html.haml b/app/views/groups/_list.html.haml new file mode 100644 index 000000000..d66c0364e --- /dev/null +++ b/app/views/groups/_list.html.haml @@ -0,0 +1,24 @@ +.content + %h2.title + = t("layout.groups.list_header") + .inner + %table.table + %tr + %th.first ID + %th= t("activerecord.attributes.group.name") + %th= t("activerecord.attributes.group.owner") + %th.last   + - @groups.each do |group| + %tr{:class => cycle("odd", "even")} + %td + = group.id + %td + = link_to group.name, group_path(group) + %td + = link_to group.owner.name, user_path(group.owner) + %td.last + #{link_to t("layout.show"), group_path(group)} | #{link_to t("layout.edit"), edit_group_path(group)} | #{link_to t("layout.delete"), group_path(group), :method => :delete, :confirm => t("layout.groups.confirm_delete")} + .actions-bar.wat-cf + .actions + - if !!paginate + = paginate diff --git a/app/views/groups/_sidebar.html.haml b/app/views/groups/_sidebar.html.haml new file mode 100644 index 000000000..83cef0324 --- /dev/null +++ b/app/views/groups/_sidebar.html.haml @@ -0,0 +1,5 @@ +.block.notice + %h3= t("layout.groups.members") + .content + - @group.members.uniq.each do |member| + %p= link_to member.name + " (#{@group.roles_of(member).map{|r| r.name}.join(', ')})", user_path(member) diff --git a/app/views/groups/edit.html.haml b/app/views/groups/edit.html.haml new file mode 100644 index 000000000..5d29b63b7 --- /dev/null +++ b/app/views/groups/edit.html.haml @@ -0,0 +1,12 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first= link_to t("layout.groups.list"), groups_path + %li= link_to t("layout.groups.new"), new_group_path + %li.active= link_to t("layout.groups.edit"), edit_group_path + .content + %h2.title= t("layout.groups.edit_header") + .inner + = form_for @group, :url => group_path(@group), :html => { :class => :form } do |f| + = render :partial => "form", :locals => {:f => f} +- content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/groups/index.html.haml b/app/views/groups/index.html.haml new file mode 100644 index 000000000..005f4b168 --- /dev/null +++ b/app/views/groups/index.html.haml @@ -0,0 +1,7 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.groups.list"), users_path + %li= link_to t("layout.groups.new"), new_group_path + =render :partial => 'list', :object => @groups, :locals => {:paginate => will_paginate(@groups)} +-# content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/groups/new.html.haml b/app/views/groups/new.html.haml new file mode 100644 index 000000000..04a96c3e0 --- /dev/null +++ b/app/views/groups/new.html.haml @@ -0,0 +1,11 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first= link_to t("layout.groups.list"), groups_path + %li.active= link_to t("layout.groups.new"), new_group_path + .content + %h2.title= t("layout.groups.new_header") + .inner + = form_for :group, :url => groups_path, :html => { :class => :form } do |f| + = render :partial => "form", :locals => {:f => f} +-# content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml new file mode 100644 index 000000000..f905d1a12 --- /dev/null +++ b/app/views/groups/show.html.haml @@ -0,0 +1,39 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first= link_to t("layout.groups.list"), groups_path + %li= link_to t("layout.groups.new"), new_group_path + %li.active= link_to t("layout.groups.show"), group_path + .content + .inner + %p + %b + Id + \: + = @group.id + %p + %b + = t("activerecord.attributes.group.name") + \: + = @group.name + %p + %b + = t("activerecord.attributes.group.owner") + \: + = link_to @group.owner.name, user_path(@group.owner) + %p + %b + = t("activerecord.attributes.group.created_at") + \: + = @group.created_at + .wat-cf + = link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_group_path(@group), :class => "button" + = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), group_path(@group), :method => "delete", :class => "button", :confirm => t("layout.groups.confirm_delete") + += render :partial => 'platforms/list', :object => @platforms + += render :partial => 'repositories/list', :object => @repositories + += render :partial => 'projects/list', :object => @projects + +- content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 5f3ed52f2..f03c87859 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -13,11 +13,15 @@ #user-navigation %ul.wat-cf %li + = t("layout.logged_in_as") + ' ' + current_user.name +   |   = link_to t('layout.logout'), destroy_user_session_path, :class => "logout" #main-navigation %ul.wat-cf %li{:class => controller.controller_path == 'users' ? 'active' : '' } %a{:href => users_path}= t("layout.menu.users") + %li{:class => controller.controller_path == 'groups' ? 'active' : '' } + %a{:href => groups_path}= t("layout.menu.groups") %li{:class => controller.controller_path == 'platforms' ? 'active' : '' } %a{:href => platforms_path}= t("layout.menu.platforms") #wrapper.wat-cf diff --git a/app/views/platforms/_list.html.haml b/app/views/platforms/_list.html.haml new file mode 100644 index 000000000..1bd464eec --- /dev/null +++ b/app/views/platforms/_list.html.haml @@ -0,0 +1,28 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.platforms.list"), platforms_path + %li= link_to t("layout.platforms.new"), new_platform_path + .content + %h2.title + = t("layout.platforms.list_header") + .inner + = form_tag '#', :method => :get do#platform_repository_path(@platform, @repository), :method => :get do + .group + = label_tag :query, t("layout.search_by_name"), :class => :label + = text_field_tag :query + %button.search{:type => "submit"} + = t("layout.search") + %table.table + %tr + %th.first= t("activerecord.attributes.platform.name") + %th.last   + - @platforms.each do |platform| + %tr{:class => cycle("odd", "even")} + %td + = link_to platform.name, platform_path(platform) + %td.last + #{link_to t("layout.show"), platform_path(platform)} | #{link_to t("layout.delete"), platform_path(platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete")} + .actions-bar.wat-cf + .actions + = will_paginate @platforms, :param_name => :platform_page diff --git a/app/views/projects/_list.html.haml b/app/views/projects/_list.html.haml new file mode 100644 index 000000000..b90152316 --- /dev/null +++ b/app/views/projects/_list.html.haml @@ -0,0 +1,28 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.projects.list"), '#'#platform_repository_path(@platform, @repository) + "#projects" + %li= link_to t("layout.projects.new"), '#'#new_platform_repository_project_path(@platform, @repository) + .content + %h2.title + = t("layout.projects.list_header") + .inner + = form_tag '#', :method => :get do#platform_repository_path(@platform, @repository), :method => :get do + .group + = label_tag :query, t("layout.search_by_name"), :class => :label + = text_field_tag :query + %button.search{:type => "submit"} + = t("layout.search") + %table.table + %tr + %th.first= t("activerecord.attributes.project.name") + %th.last   + - @projects.each do |project| + %tr{:class => cycle("odd", "even")} + %td + = link_to project.name, project_path(project) + %td.last + #{link_to t("layout.show"), project_path(project)} | #{link_to t("layout.delete"), project_path(project), :method => :delete, :confirm => t("layout.projects.confirm_delete")} + .actions-bar.wat-cf + .actions + = will_paginate @projects, :param_name => :project_page diff --git a/app/views/repositories/_list.html.haml b/app/views/repositories/_list.html.haml new file mode 100644 index 000000000..fe9dac995 --- /dev/null +++ b/app/views/repositories/_list.html.haml @@ -0,0 +1,28 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.repositories.list"), '#'#platform_path(@platform) + "#repositories" + %li= link_to t("layout.repositories.new"), '#' #new_platform_repository_path(@platform) + .content + %h2.title + = t("layout.repositories.list_header") + .inner + = form_tag '#', :method => :get do#platform_repository_path(@platform, @repository), :method => :get do + .group + = label_tag :query, t("layout.search_by_name"), :class => :label + = text_field_tag :query + %button.search{:type => "submit"} + = t("layout.search") + %table.table + %tr + %th.first= t("activerecord.attributes.repository.name") + %th.last   + - @repositories.each do |repository| + %tr{:class => cycle("odd", "even")} + %td + = link_to repository.name, repository_path(repository) + %td.last + #{link_to t("layout.show"), repository_path(repository)} | #{link_to t("layout.delete"), repository_path(repository), :method => :delete, :confirm => t("layout.repositories.confirm_delete")} + .actions-bar.wat-cf + .actions + = will_paginate @repositories, :param_name => :repository_page diff --git a/db/migrate/20111016130557_add_uname_to_groups.rb b/db/migrate/20111016130557_add_uname_to_groups.rb new file mode 100644 index 000000000..37805aabf --- /dev/null +++ b/db/migrate/20111016130557_add_uname_to_groups.rb @@ -0,0 +1,9 @@ +class AddUnameToGroups < ActiveRecord::Migration + def self.up + add_column :groups, :uname, :string + end + + def self.down + remove_column :groups, :uname + end +end From d7cddecbe8a51e0c9dba41b37d50a5cc1ad28034 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 17 Oct 2011 00:48:31 +0400 Subject: [PATCH 04/19] Changed User representation. --- app/controllers/users_controller.rb | 4 +++ app/views/users/_groups_roled_list.html.haml | 25 ++++++++++++++++ app/views/users/_sidebar.html.haml | 5 ++++ app/views/users/index.html.haml | 2 +- app/views/users/new.html.haml | 2 +- app/views/users/show.html.haml | 6 ++++ config/routes.rb | 30 ++++++++++++++++++-- 7 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 app/views/users/_groups_roled_list.html.haml diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e5d8c2540..0c5c84ec0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -6,6 +6,10 @@ class UsersController < ApplicationController end def show + @groups = @user.groups.uniq + @platforms = @user.platforms.paginate(:page => params[:platform_page], :per_page => 10) + @repositories = @user.repositories.paginate(:page => params[:repository_page], :per_page => 10) + @projects = @user.projects.paginate(:page => params[:project_page], :per_page => 10) end def new diff --git a/app/views/users/_groups_roled_list.html.haml b/app/views/users/_groups_roled_list.html.haml new file mode 100644 index 000000000..60325749a --- /dev/null +++ b/app/views/users/_groups_roled_list.html.haml @@ -0,0 +1,25 @@ +.block + .content + %h2.title + = t("layout.groups.list_header") + .inner + %table.table + %tr + %th.first ID + %th= t("activerecord.attributes.group.name") + %th= t("activerecord.attributes.user.roles") + %th.last   + - @groups.each do |group| + %tr{:class => cycle("odd", "even")} + %td + = group.id + %td + = link_to group.name, group_path(group) + %td + = group.roles_of(@user).map {|r| r.name}.join(', ') + %td.last + #{link_to t("layout.show"), group_path(group)} | #{link_to t("layout.edit"), edit_group_path(group)} | #{link_to t("layout.delete"), group_path(group), :method => :delete, :confirm => t("layout.groups.confirm_delete")} + .actions-bar.wat-cf + .actions + - if paginate + = paginate diff --git a/app/views/users/_sidebar.html.haml b/app/views/users/_sidebar.html.haml index e69de29bb..78f72b290 100644 --- a/app/views/users/_sidebar.html.haml +++ b/app/views/users/_sidebar.html.haml @@ -0,0 +1,5 @@ +.block.notice + %h3= t("layout.users.groups") + .content + - @groups.each do |group| + %p= link_to group.name + " (#{group.roles_of(@user).map{|r| r.name}.join(', ')})", group_path(group) diff --git a/app/views/users/index.html.haml b/app/views/users/index.html.haml index 7b05d0bd3..e147bd57e 100644 --- a/app/views/users/index.html.haml +++ b/app/views/users/index.html.haml @@ -25,4 +25,4 @@ #{link_to t("layout.show"), user_path(user)} | #{link_to t("layout.edit"), edit_user_path(user)} | #{link_to t("layout.delete"), user_path(user), :method => :delete, :confirm => t("layout.users.confirm_delete")} .actions-bar.wat-cf .actions -- content_for :sidebar, render(:partial => 'sidebar') +-# content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/users/new.html.haml b/app/views/users/new.html.haml index 65a4228de..0c86e995f 100644 --- a/app/views/users/new.html.haml +++ b/app/views/users/new.html.haml @@ -8,4 +8,4 @@ .inner = form_for :user, :url => users_path, :html => { :class => :form } do |f| = render :partial => "form", :locals => {:f => f} -- content_for :sidebar, render(:partial => 'sidebar') \ No newline at end of file +-# content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index ab8c9d039..22c49e43c 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -30,4 +30,10 @@ = link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_user_path(@user), :class => "button" = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), user_path(@user), :method => "delete", :class => "button", :confirm => t("layout.users.confirm_delete") += render :partial => 'platforms/list', :object => @platforms + += render :partial => 'repositories/list', :object => @repositories + += render :partial => 'projects/list', :object => @projects + - content_for :sidebar, render(:partial => 'sidebar') diff --git a/config/routes.rb b/config/routes.rb index 151faf1b1..589a55435 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,8 +37,34 @@ Rosa::Application.routes.draw do end end - resources :users - + resources :projects + + resources :repositories + + resources :users do + resources :platforms, :only => [:new, :create] + + resources :projects, :only => [:new, :create] + + resources :repositories, :only => [:new, :create] +# resources :groups do +# collection do +# get :add +# end +# member do +# get :add +# end +# end + end + + resources :groups do + resources :platforms, :only => [:new, :create] + + resources :projects, :only => [:new, :create] + + resources :repositories, :only => [:new, :create] + end + match 'build_lists/status_build', :to => "build_lists#status_build" match 'build_lists/post_build', :to => "build_lists#post_build" match 'build_lists/pre_build', :to => "build_lists#pre_build" From e672c20d3fe1012f9e759fb23d6ea24bb0f2fa84 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 17 Oct 2011 00:49:55 +0400 Subject: [PATCH 05/19] Some new translations --- config/locales/ru.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 69248a18c..09042e71e 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -20,6 +20,7 @@ ru: true_: Да false_: Нет publish: Опубликовать + add: Добавить weekdays: Monday: Понедельник @@ -33,6 +34,7 @@ ru: menu: users: Пользователи platforms: Платформы + groups: Группы sessions: sign_in_header: Вход в систему @@ -113,6 +115,18 @@ ru: current_build_lists: Текущие сборки build_button: Начать сборку + groups: + list: Список + new: Создать + edit: Редактировать + members: Участники + new_header: Новая группа + edit_header: Редактировать + list_header: Группы + show: Группа + back_to_the_list: ⇐ К списку групп + confirm_delete: Вы уверены, что хотите удалить эту группу? + users: list: Список new: Создать @@ -120,6 +134,7 @@ ru: new_header: Новый пользователь edit_header: Редактировать list_header: Пользователи + groups: Группы show: Пользователь back_to_the_list: ⇐ К списку пользователей confirm_delete: Вы уверены, что хотите удалить этого пользователя? @@ -180,6 +195,11 @@ ru: save_error: Не удалось сохранить данные о пользователе destroyed: Учетная запись успешно удалена + group: + saved: Группа успешно сохранена + save_error: Не удалось сохранить группу + destroyed: Группа успешно удалена + repository: saved: Репозиторий успешно добавлен save_error: Не удалось добавить репозиторий @@ -222,6 +242,7 @@ ru: arch: Arch container: Container platform: Платформа + group: Группа project: Проект rpm: RPM user: Пользователь @@ -295,9 +316,17 @@ ru: created_at: Создан updated_at: Обновлен + group: + name: Название + uname: Unixname + owner: Владелец + created_at: Создана + updated_at: Обновлена + user: name: Имя email: Email + roles: Роли created_at: Создан updated_at: Обновлен From fa3359b025515afe8e627c7743b1940ee982a9e8 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 17 Oct 2011 00:50:56 +0400 Subject: [PATCH 06/19] Some changes in representation --- app/controllers/platforms_controller.rb | 21 ++++++------ app/controllers/projects_controller.rb | 6 ++-- app/models/platform.rb | 45 +++++++++++++------------ app/models/project.rb | 4 +-- app/models/relation.rb | 2 +- app/views/platforms/index.html.haml | 43 +++++++++++------------ 6 files changed, 63 insertions(+), 58 deletions(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index fb508a727..a2a7e35cc 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -6,7 +6,7 @@ class PlatformsController < ApplicationController before_filter :find_platform, :only => [:freeze, :unfreeze, :clone] def index - @platforms = Platform.all + @platforms = Platform.paginate(:page => params[:platform_page]) end def show @@ -20,15 +20,16 @@ class PlatformsController < ApplicationController end def create - @platform = Platform.new params[:platform] - if @platform.save - flash[:notice] = I18n.t("flash.platform.saved") - redirect_to @platform - else - flash[:error] = I18n.t("flash.platform.saved_error") - @platforms = Platform.all - render :action => :new - end + pp params +# @platform = Platform.new params[:platform] +# if @platform.save +# flash[:notice] = I18n.t("flash.platform.saved") +# redirect_to @platform +# else +# flash[:error] = I18n.t("flash.platform.saved_error") +# @platforms = Platform.all +# render :action => :new +# end end def freeze diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 76f69c1f7..773d9b533 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,7 +1,7 @@ class ProjectsController < ApplicationController before_filter :authenticate_user! - before_filter :find_platform - before_filter :find_repository +# before_filter :find_platform +# before_filter :find_repository before_filter :find_project, :only => [:show, :destroy, :build, :process_build] def new @@ -72,7 +72,7 @@ class ProjectsController < ApplicationController end def find_project - @project = @repository.projects.find params[:id] + @project = Project.find params[:id] end def check_arches diff --git a/app/models/platform.rb b/app/models/platform.rb index 5921ddd55..6099d97ff 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -11,9 +11,9 @@ class Platform < ActiveRecord::Base validates :name, :presence => true, :uniqueness => true validates :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false - before_create :xml_rpc_create - before_destroy :xml_rpc_destroy - before_update :check_freezing +# before_create :xml_rpc_create +# before_destroy :xml_rpc_destroy +# before_update :check_freezing def path @@ -55,30 +55,33 @@ class Platform < ActiveRecord::Base end def xml_rpc_create - result = BuildServer.add_platform unixname, APP_CONFIG['root_path'] - if result == BuildServer::SUCCESS - return true - else - raise "Failed to create platform #{name}. Path: #{build_path(unixname)}" - end + return true +# result = BuildServer.add_platform unixname, APP_CONFIG['root_path'] +# if result == BuildServer::SUCCESS +# return true +# else +# raise "Failed to create platform #{name}. Path: #{build_path(unixname)}" +# end end def xml_rpc_destroy - result = BuildServer.delete_platform unixname - if result == BuildServer::SUCCESS - return true - else - raise "Failed to delete platform #{unixname}." - end + return true +# result = BuildServer.delete_platform unixname +# if result == BuildServer::SUCCESS +# return true +# else +# raise "Failed to delete platform #{unixname}." +# end end def xml_rpc_clone(new_unixname) - result = BuildServer.clone_platform new_unixname, self.unixname, APP_CONFIG['root_path'] - if result == BuildServer::SUCCESS - return true - else - raise "Failed to clone platform #{name}. Path: #{build_path(unixname)} to platform #{new_unixname}" - end + return true +# result = BuildServer.clone_platform new_unixname, self.unixname, APP_CONFIG['root_path'] +# if result == BuildServer::SUCCESS +# return true +# else +# raise "Failed to clone platform #{name}. Path: #{build_path(unixname)} to platform #{new_unixname}" +# end end def check_freezing diff --git a/app/models/project.rb b/app/models/project.rb index c1fcf68e5..aaaa0e2c1 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -17,8 +17,8 @@ class Project < ActiveRecord::Base scope :by_name, lambda { |name| {:conditions => ['name like ?', '%' + name + '%']} } #before_create :create_directory, :create_git_repo - before_create :xml_rpc_create - before_destroy :xml_rpc_destroy +# before_create :xml_rpc_create +# before_destroy :xml_rpc_destroy # Redefining a method from Project::HasRepository module to reflect current situation def git_repo_path diff --git a/app/models/relation.rb b/app/models/relation.rb index c351cffcb..53cf77a69 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -1,5 +1,5 @@ class Relation < ActiveRecord::Base belongs_to :target, :polymorphic => true belongs_to :object, :polymorphic => true - belongs_to :role + belongs_to :role, :autosave => true end diff --git a/app/views/platforms/index.html.haml b/app/views/platforms/index.html.haml index 61bfbfdac..4af4c9181 100644 --- a/app/views/platforms/index.html.haml +++ b/app/views/platforms/index.html.haml @@ -1,21 +1,22 @@ -.block - .secondary-navigation - %ul.wat-cf - %li.first.active= link_to t("layout.platforms.list"), platforms_path - %li= link_to t("layout.platforms.new"), new_platform_path - .content - %h2.title - = t("layout.platforms.list_header") - .inner - %table.table - %tr - %th.first= t("activerecord.attributes.platform.name") - %th.last   - - @platforms.each do |platform| - %tr{:class => cycle("odd", "even")} - %td - = link_to platform.name, platform_path(platform) - %td.last - #{link_to t("layout.show"), platform_path(platform)} | #{link_to t("layout.delete"), platform_path(platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete")} - .actions-bar.wat-cf - .actions +=render :partial => 'list', :object => @platforms +/.block +/ .secondary-navigation +/ %ul.wat-cf +/ %li.first.active= link_to t("layout.platforms.list"), platforms_path +/ %li= link_to t("layout.platforms.new"), new_platform_path +/ .content +/ %h2.title +/ = t("layout.platforms.list_header") +/ .inner +/ %table.table +/ %tr +/ %th.first= t("activerecord.attributes.platform.name") +/ %th.last   +/ - @platforms.each do |platform| +/ %tr{:class => cycle("odd", "even")} +/ %td +/ = link_to platform.name, platform_path(platform) +/ %td.last +/ #{link_to t("layout.show"), platform_path(platform)} | #{link_to t("layout.delete"), platform_path(platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete")} +/ .actions-bar.wat-cf +/ .actions From ff5aa09c30124891f41e3553dfcf3fd0997cdd01 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 17 Oct 2011 18:16:21 +0400 Subject: [PATCH 07/19] Added method to determine current acter (group or user) --- app/controllers/application_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 51b260773..8b5af54af 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -11,6 +11,12 @@ class ApplicationController < ActionController::Base end end + def get_acter + return User.find params[:user_id] if params[:user_id] + return Group.find params[:group_id] if params[:group_id] + return current_user + end + def authenticate_build_service! if request.remote_ip != APP_CONFIG['build_service_ip'] render :nothing => true, :status => 403 From 76e8b52812213638b1754d4c5c20f6f17777d433 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 17 Oct 2011 18:18:37 +0400 Subject: [PATCH 08/19] Changed DB structure. --- ...50436_remove_repository_id_from_project.rb | 9 ++++++++ .../20111016220428_platform_restruct.rb | 18 ++++++++++++++++ db/migrate/20111016224709_project_restruct.rb | 14 +++++++++++++ .../20111016225240_repositories_restruct.rb | 14 +++++++++++++ db/schema.rb | 21 ++++++++++++++----- 5 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20111014150436_remove_repository_id_from_project.rb create mode 100644 db/migrate/20111016220428_platform_restruct.rb create mode 100644 db/migrate/20111016224709_project_restruct.rb create mode 100644 db/migrate/20111016225240_repositories_restruct.rb diff --git a/db/migrate/20111014150436_remove_repository_id_from_project.rb b/db/migrate/20111014150436_remove_repository_id_from_project.rb new file mode 100644 index 000000000..bc85b3ae0 --- /dev/null +++ b/db/migrate/20111014150436_remove_repository_id_from_project.rb @@ -0,0 +1,9 @@ +class RemoveRepositoryIdFromProject < ActiveRecord::Migration + def self.up + remove_column :projects, :repository_id + end + + def self.down + add_column :projects, :repository_id, :integer, :null => false + end +end diff --git a/db/migrate/20111016220428_platform_restruct.rb b/db/migrate/20111016220428_platform_restruct.rb new file mode 100644 index 000000000..60d49c43d --- /dev/null +++ b/db/migrate/20111016220428_platform_restruct.rb @@ -0,0 +1,18 @@ +class PlatformRestruct < ActiveRecord::Migration + def self.up + change_table :platforms do |t| + t.references :owner, :polymorphic => true + t.string :visibility, :default => 'open' + t.string :platform_type, :default => 'main' + t.string :distrib_type + end + end + + def self.down + remove_column :platforms, :visibility + remove_column :platforms, :owner_id + remove_column :platforms, :owner_type + remove_column :platforms, :platform_type + remove_column :platforms, :distrib_type + end +end diff --git a/db/migrate/20111016224709_project_restruct.rb b/db/migrate/20111016224709_project_restruct.rb new file mode 100644 index 000000000..89d190c12 --- /dev/null +++ b/db/migrate/20111016224709_project_restruct.rb @@ -0,0 +1,14 @@ +class ProjectRestruct < ActiveRecord::Migration + def self.up + change_table :projects do |t| + t.references :owner, :polymorphic => true + t.string :visibility, :default => 'open' + end + end + + def self.down + remove_column :projects, :visibility + remove_column :projects, :owner_id + remove_column :projects, :owner_type + end +end diff --git a/db/migrate/20111016225240_repositories_restruct.rb b/db/migrate/20111016225240_repositories_restruct.rb new file mode 100644 index 000000000..21a3a5b60 --- /dev/null +++ b/db/migrate/20111016225240_repositories_restruct.rb @@ -0,0 +1,14 @@ +class RepositoriesRestruct < ActiveRecord::Migration + def self.up + change_table :repositories do |t| + t.references :owner, :polymorphic => true + t.string :visibility, :default => 'open' + end + end + + def self.down + remove_column :repositories, :visibility + remove_column :repositories, :owner_id + remove_column :repositories, :owner_type + end +end diff --git a/db/schema.rb b/db/schema.rb index b21ea15d2..f8e3e5745 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 => 20111013150125) do +ActiveRecord::Schema.define(:version => 20111016225240) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -78,6 +78,7 @@ ActiveRecord::Schema.define(:version => 20111013150125) do t.integer "owner_id" t.datetime "created_at" t.datetime "updated_at" + t.string "uname" end create_table "permissions", :force => true do |t| @@ -94,6 +95,11 @@ ActiveRecord::Schema.define(:version => 20111013150125) do t.datetime "created_at" t.datetime "updated_at" t.boolean "released", :default => false + t.integer "owner_id" + t.string "owner_type" + t.string "visibility", :default => "open" + t.string "platform_type", :default => "main" + t.string "distrib_type" end create_table "products", :force => true do |t| @@ -129,7 +135,9 @@ ActiveRecord::Schema.define(:version => 20111013150125) do t.string "unixname" t.datetime "created_at" t.datetime "updated_at" - t.integer "repository_id", :null => false + t.integer "owner_id" + t.string "owner_type" + t.string "visibility", :default => "open" end create_table "relations", :force => true do |t| @@ -143,11 +151,14 @@ ActiveRecord::Schema.define(:version => 20111013150125) do end create_table "repositories", :force => true do |t| - t.string "name", :null => false - t.integer "platform_id", :null => false + t.string "name", :null => false + t.integer "platform_id", :null => false t.datetime "created_at" t.datetime "updated_at" - t.string "unixname", :null => false + t.string "unixname", :null => false + t.integer "owner_id" + t.string "owner_type" + t.string "visibility", :default => "open" end create_table "rights", :force => true do |t| From 75cd0c7ae6237ff29baf8552346febe073c718a3 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 17 Oct 2011 18:20:35 +0400 Subject: [PATCH 09/19] Changed representation of Repositories. --- app/controllers/repositories_controller.rb | 40 ++++++++++++++++++---- app/models/repository.rb | 14 ++++++-- app/views/repositories/_form.html.haml | 6 +++- app/views/repositories/_list.html.haml | 38 ++++++-------------- app/views/repositories/index.html.haml | 14 ++++++++ app/views/repositories/new.html.haml | 8 ++--- app/views/repositories/show.html.haml | 2 +- 7 files changed, 79 insertions(+), 43 deletions(-) create mode 100644 app/views/repositories/index.html.haml diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9a9b1c2d9..07e5c6c03 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -1,7 +1,13 @@ class RepositoriesController < ApplicationController before_filter :authenticate_user! - before_filter :find_platform +# before_filter :find_platform, :except => [:index, :new, :create] before_filter :find_repository, :only => [:show, :destroy] + before_filter :get_paths, :only => [:new, :create] + before_filter :find_platforms, :only => [:new, :create] + + def index + @repositories = Repository.paginate(:page => params[:repository_page]) + end def show if params[:query] @@ -12,7 +18,7 @@ class RepositoriesController < ApplicationController end def new - @repository = @platform.repositories.new + @repository = Repository.new end def destroy @@ -23,10 +29,11 @@ class RepositoriesController < ApplicationController end def create - @repository = @platform.repositories.new(params[:repository]) + @repository = Repository.new(params[:repository]) + @repository.owner = get_acter if @repository.save flash[:notice] = t('flash.repository.saved') - redirect_to [@platform, @repository] + redirect_to @repositories_path else flash[:error] = t('flash.repository.save_error') render :action => :new @@ -35,11 +42,30 @@ class RepositoriesController < ApplicationController protected - def find_platform - @platform = Platform.find params[:platform_id] + def get_paths + if params[:user_id] + @user = User.find params[:user_id] + @repositories_path = user_repositories_path @user + @new_repository_path = new_user_repository_path @user + elsif params[:group_id] + @group = Group.find params[:group_id] + @repositories_path = group_repositories_path @group + @new_repository_path = new_group_repository_path @group + elsif params[:platform_id] + @platform = Platform.find params[:platform_id] + @repositories_path = platform_repositories_path @platform + @new_repository_path = new_platform_repository_path @platform + else + @repositories_path = repositories_path + @new_repository_path = new_repository_path + end + end + + def find_platforms + @platforms = Platform.all end def find_repository - @repository = @platform.repositories.find(params[:id]) + @repository = Repository.find(params[:id]) end end diff --git a/app/models/repository.rb b/app/models/repository.rb index b4e19fd2a..0b90d4c4d 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1,5 +1,6 @@ class Repository < ActiveRecord::Base belongs_to :platform + belongs_to :owner, :polymorphic => true has_many :projects, :through => :project_to_repositories #, :dependent => :destroy has_many :project_to_repositories @@ -8,11 +9,14 @@ class Repository < ActiveRecord::Base 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\-.]+$/ } + validates :name, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true + validates :unixname, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ } + validates :platform_id, :presence => true scope :recent, order("name ASC") + after_create :make_owner_rel + # before_create :xml_rpc_create # before_destroy :xml_rpc_destroy @@ -30,6 +34,12 @@ class Repository < ActiveRecord::Base protected + def make_owner_rel + members << owner if owner.instance_of? User + groups << owner if owner.instance_of? Group + save + end + def build_path(dir) File.join(platform.path, dir) end diff --git a/app/views/repositories/_form.html.haml b/app/views/repositories/_form.html.haml index 1ec4e7935..e34e61de3 100644 --- a/app/views/repositories/_form.html.haml +++ b/app/views/repositories/_form.html.haml @@ -5,10 +5,14 @@ = f.label :unixname, t("activerecord.attributes.repository.unixname"), :class => :label = f.text_field :unixname, :class => 'text_field' +.group + = f.label :parent, :class => :label + = f.select :platform_id, @platforms.map { |p| [p.name, p.id] }, :include_blank => true + .group.navform.wat-cf %button.button{:type => "submit"} = image_tag("web-app-theme/icons/tick.png", :alt => t("layout.save")) = t("layout.save") %span.text_button_padding= t("layout.or") - = link_to t("layout.cancel"), platform_path(@platform) + "#repositories", :class => "text_button_padding link_button" + = link_to t("layout.cancel"), @repositories_path + "#repositories", :class => "text_button_padding link_button" diff --git a/app/views/repositories/_list.html.haml b/app/views/repositories/_list.html.haml index fe9dac995..581f705d3 100644 --- a/app/views/repositories/_list.html.haml +++ b/app/views/repositories/_list.html.haml @@ -1,28 +1,10 @@ -.block - .secondary-navigation - %ul.wat-cf - %li.first.active= link_to t("layout.repositories.list"), '#'#platform_path(@platform) + "#repositories" - %li= link_to t("layout.repositories.new"), '#' #new_platform_repository_path(@platform) - .content - %h2.title - = t("layout.repositories.list_header") - .inner - = form_tag '#', :method => :get do#platform_repository_path(@platform, @repository), :method => :get do - .group - = label_tag :query, t("layout.search_by_name"), :class => :label - = text_field_tag :query - %button.search{:type => "submit"} - = t("layout.search") - %table.table - %tr - %th.first= t("activerecord.attributes.repository.name") - %th.last   - - @repositories.each do |repository| - %tr{:class => cycle("odd", "even")} - %td - = link_to repository.name, repository_path(repository) - %td.last - #{link_to t("layout.show"), repository_path(repository)} | #{link_to t("layout.delete"), repository_path(repository), :method => :delete, :confirm => t("layout.repositories.confirm_delete")} - .actions-bar.wat-cf - .actions - = will_paginate @repositories, :param_name => :repository_page +%table.table + %tr + %th.first= t("activerecord.attributes.repository.name") + %th.last   + - @repositories.each do |repository| + %tr{:class => cycle("odd", "even")} + %td + = link_to repository.name, repository_path(repository) + %td.last + #{link_to t("layout.show"), repository_path(repository)} | #{link_to t("layout.delete"), repository_path(repository), :method => :delete, :confirm => t("layout.repositories.confirm_delete")} diff --git a/app/views/repositories/index.html.haml b/app/views/repositories/index.html.haml new file mode 100644 index 000000000..3ee0282ab --- /dev/null +++ b/app/views/repositories/index.html.haml @@ -0,0 +1,14 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.repositories.list"), repositories_path + %li= link_to t("layout.platforms.new"), new_repository_path + .content + %h2.title + = t("layout.platforms.list_header") + .inner + = render :partial => 'shared/search_form' + = render :partial => 'list', :object => @repositories + .actions-bar.wat-cf + .actions + = will_paginate @repositories, :param_name => :repository_page diff --git a/app/views/repositories/new.html.haml b/app/views/repositories/new.html.haml index d2509bd2c..36708efde 100644 --- a/app/views/repositories/new.html.haml +++ b/app/views/repositories/new.html.haml @@ -1,11 +1,11 @@ .block .secondary-navigation %ul.wat-cf - %li.first= link_to t("layout.repositories.list"), platform_path(@platform) + "#platforms" - %li.active= link_to t("layout.repositories.new"), new_platform_repository_path(@platform) + %li.first= link_to t("layout.repositories.list"), @repositories_path + "#platforms" + %li.active= link_to t("layout.repositories.new"), @new_repository_path .content %h2.title= t("layout.repositories.new_header") .inner - = form_for [@platform, @repository], :html => { :class => :form } do |f| + = form_for :repository, :url => @repositories_path, :html => { :class => :form } do |f| = render :partial => "form", :locals => {:f => f} -- content_for :sidebar, render(:partial => 'sidebar') \ No newline at end of file +-# content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/repositories/show.html.haml b/app/views/repositories/show.html.haml index 47a2b547f..1237c8ab7 100644 --- a/app/views/repositories/show.html.haml +++ b/app/views/repositories/show.html.haml @@ -29,7 +29,7 @@ .secondary-navigation %ul.wat-cf %li.first.active= link_to t("layout.projects.list"), platform_repository_path(@platform, @repository) + "#projects" - %li= link_to t("layout.projects.new"), new_platform_repository_project_path(@platform, @repository) + %li= link_to t("layout.projects.new"), new_project_path(@platform, @repository) .content %h2.title = t("layout.projects.list_header") From 5a6248c1af50861bfcf2bce1361706cfe34e9e59 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 17 Oct 2011 18:21:29 +0400 Subject: [PATCH 10/19] Changed representation of Projects --- app/controllers/projects_controller.rb | 24 ++++++++++++++-- app/models/project.rb | 12 ++++++-- app/views/projects/_form.html.haml | 2 +- app/views/projects/_list.html.haml | 38 +++++++------------------- app/views/projects/new.html.haml | 8 +++--- app/views/projects/show.html.haml | 32 ++++++++++++++-------- 6 files changed, 67 insertions(+), 49 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 773d9b533..839442128 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -3,9 +3,10 @@ class ProjectsController < ApplicationController # before_filter :find_platform # before_filter :find_repository before_filter :find_project, :only => [:show, :destroy, :build, :process_build] + before_filter :get_paths, :only => [:new, :create] def new - @project = @repository.projects.new + @project = Project.new end def show @@ -44,10 +45,12 @@ class ProjectsController < ApplicationController end def create - @project = @repository.projects.new params[:project] + @project = Project.new params[:project] + @project.owner = get_acter + if @project.save flash[:notice] = t('flash.project.saved') - redirect_to [@platform, @repository] + redirect_to @project.owner else flash[:error] = t('flash.project.save_error') render :action => :new @@ -63,6 +66,21 @@ class ProjectsController < ApplicationController protected + def get_paths + if params[:user_id] + @user = User.find params[:user_id] + @projects_path = user_projects_path @user + @new_project_path = new_user_project_path @user + elsif params[:group_id] + @group = Group.find params[:group_id] + @projects_path = group_projects_path @group + @new_projects_path = new_group_project_path @group + else + @projects_path = projects_path + @new_projects_path = new_project_path + end + end + def find_platform @platform = Platform.find params[:platform_id] end diff --git a/app/models/project.rb b/app/models/project.rb index aaaa0e2c1..d6483450b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,4 +1,5 @@ class Project < ActiveRecord::Base + belongs_to :owner, :polymorphic => true has_many :build_lists, :dependent => :destroy has_many :project_to_repositories @@ -8,14 +9,15 @@ class Project < ActiveRecord::Base 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 + validates :name, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :allow_nil => false, :allow_blank => false + validates :unixname, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false include Project::HasRepository scope :recent, order("name ASC") scope :by_name, lambda { |name| {:conditions => ['name like ?', '%' + name + '%']} } + after_create :make_owner_rel #before_create :create_directory, :create_git_repo # before_create :xml_rpc_create # before_destroy :xml_rpc_destroy @@ -47,6 +49,12 @@ class Project < ActiveRecord::Base protected + def make_owner_rel + collaborators << owner if owner.instance_of? User + groups << owner if owner.instance_of? Group + save + end + def build_path(dir) File.join(repository.path, dir) end diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 6322f58e4..51a3bf29e 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -10,4 +10,4 @@ = image_tag("web-app-theme/icons/tick.png", :alt => t("layout.save")) = t("layout.save") %span.text_button_padding= t("layout.or") - = link_to t("layout.cancel"), platform_repository_path(@platform, @repository), :class => "text_button_padding link_button" \ No newline at end of file + = link_to t("layout.cancel"), @projects_path, :class => "text_button_padding link_button" diff --git a/app/views/projects/_list.html.haml b/app/views/projects/_list.html.haml index b90152316..32f63774b 100644 --- a/app/views/projects/_list.html.haml +++ b/app/views/projects/_list.html.haml @@ -1,28 +1,10 @@ -.block - .secondary-navigation - %ul.wat-cf - %li.first.active= link_to t("layout.projects.list"), '#'#platform_repository_path(@platform, @repository) + "#projects" - %li= link_to t("layout.projects.new"), '#'#new_platform_repository_project_path(@platform, @repository) - .content - %h2.title - = t("layout.projects.list_header") - .inner - = form_tag '#', :method => :get do#platform_repository_path(@platform, @repository), :method => :get do - .group - = label_tag :query, t("layout.search_by_name"), :class => :label - = text_field_tag :query - %button.search{:type => "submit"} - = t("layout.search") - %table.table - %tr - %th.first= t("activerecord.attributes.project.name") - %th.last   - - @projects.each do |project| - %tr{:class => cycle("odd", "even")} - %td - = link_to project.name, project_path(project) - %td.last - #{link_to t("layout.show"), project_path(project)} | #{link_to t("layout.delete"), project_path(project), :method => :delete, :confirm => t("layout.projects.confirm_delete")} - .actions-bar.wat-cf - .actions - = will_paginate @projects, :param_name => :project_page +%table.table + %tr + %th.first= t("activerecord.attributes.project.name") + %th.last   + - @projects.each do |project| + %tr{:class => cycle("odd", "even")} + %td + = link_to project.name, project_path(project) + %td.last + #{link_to t("layout.show"), project_path(project)} | #{link_to t("layout.delete"), project_path(project), :method => :delete, :confirm => t("layout.projects.confirm_delete")} diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index dee8efad4..666eaea30 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -1,14 +1,14 @@ .block .secondary-navigation %ul.wat-cf - %li.first= link_to t("layout.projects.list"), platform_repository_path(@platform, @repository) + "#projects" - %li.active= link_to t("layout.projects.new"), new_platform_repository_project_path(@platform, @repository) + %li.first= link_to t("layout.projects.list"), @projects_path#url_for(get_acter) + "#projects" + %li.active= link_to t("layout.projects.new"), @new_project_path#new_platform_repository_project_path(@platform, @repository) -#%li= link_to "git-repo", platform_repository_project_repo_path(@platform, @repository, @project) -#%li= link_to t("layout.projects.build"), build_platform_repository_project_path(@platform, @repository, @project) .content %h2.title= t("layout.projects.new_header") .inner - = form_for [@platform, @repository, @project], :html => { :class => :form } do |f| + = form_for :project, :url => @projects_path, :html => { :class => :form } do |f| = render :partial => "form", :locals => {:f => f} -- content_for :sidebar, render(:partial => 'sidebar') +-# content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 417edd325..a8198dc0f 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -1,11 +1,11 @@ .block .secondary-navigation %ul.wat-cf - %li.first= link_to t("layout.projects.list"), platform_repository_path(@platform, @repository) + "#projects" - %li= link_to t("layout.projects.new"), new_platform_repository_project_path(@platform, @repository) - %li.active= link_to t("layout.projects.show"), platform_repository_project_path(@platform, @repository, @project) - %li= link_to "git-repo", platform_repository_project_repo_path(@platform, @repository, @project) - %li= link_to t("layout.projects.build"), build_platform_repository_project_path(@platform, @repository, @project) + %li.first= link_to t("layout.projects.list"), projects_path + %li= link_to t("layout.projects.new"), new_project_path + %li.active= link_to t("layout.projects.show"), project_path(@project) + %li= link_to "git-repo", '#'#platform_repository_project_repo_path(@platform, @repository, @project) + %li= link_to t("layout.projects.build"), '#'#build_platform_repository_project_path(@platform, @repository, @project) .content .inner @@ -21,21 +21,31 @@ = @project.unixname %p %b - = t("activerecord.attributes.project.repository") + = t("activerecord.attributes.project.owner") \: - = @project.repository.name + = link_to @project.owner.name, url_for(@project.owner) + %p + %b + = t("activerecord.attributes.project.visibility") + \: + = @project.visibility + / %p + / %b + / = t("activerecord.attributes.project.repository") + / \: + / = @project.repository.name .wat-cf - = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_repository_project_path(@platform, @repository, @project), :method => "delete", :class => "button", :confirm => t("layout.projects.confirm_delete") + = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), project_path(@project), :method => "delete", :class => "button", :confirm => t("layout.projects.confirm_delete") %a{ :name => "build_lists"} .block .secondary-navigation %ul.wat-cf - %li.first.active= link_to t("layout.build_lists.current"), platform_repository_project_path(@platform, @repository, @project) + "#build_lists" - %li= link_to t("layout.build_lists.all"), platform_repository_project_build_lists_path(@platform, @repository, @project) + %li.first.active= link_to t("layout.build_lists.current"), project_path(@project) + "#build_lists" + %li= link_to t("layout.build_lists.all"), project_build_lists_path(@project) .content = render :partial => "build_lists/build_lists", :object => @current_build_lists -- content_for :sidebar, render(:partial => 'sidebar') +-# content_for :sidebar, render(:partial => 'sidebar') From b1a801f7f932b91fdb64bd082709080b3de3c6c0 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 17 Oct 2011 18:22:30 +0400 Subject: [PATCH 11/19] Added search form and changed group representation --- app/views/groups/show.html.haml | 45 +++++++++++++++++++++++-- app/views/shared/_search_form.html.haml | 6 ++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 app/views/shared/_search_form.html.haml diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index f905d1a12..29522f7e2 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -30,10 +30,49 @@ = link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_group_path(@group), :class => "button" = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), group_path(@group), :method => "delete", :class => "button", :confirm => t("layout.groups.confirm_delete") -= render :partial => 'platforms/list', :object => @platforms +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.platforms.list"), platforms_path + %li= link_to t("layout.platforms.new"), new_group_platform_path(@group) + .content + %h2.title + = t("layout.platforms.list_header") + .inner + = render :partial => 'shared/search_form' + = render :partial => 'platforms/list', :object => @platforms + .actions-bar.wat-cf + .actions + = will_paginate @platforms, :param_name => :platform_page -= render :partial => 'repositories/list', :object => @repositories +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.repositories.list"), repositories_path + %li= link_to t("layout.repositories.new"), new_group_repository_path(@group) + .content + %h2.title + = t("layout.repositories.list_header") + .inner + = render :partial => 'shared/search_form' + = render :partial => 'repositories/list', :object => @repositories + .actions-bar.wat-cf + .actions + = will_paginate @repositories, :param_name => :repository_page -= render :partial => 'projects/list', :object => @projects +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.projects.list"), projects_path + %li= link_to t("layout.projects.new"), new_group_project_path(@group) + .content + %h2.title + = t("layout.projects.list_header") + .inner + = render :partial => 'shared/search_form' + = render :partial => 'projects/list', :object => @projects + .actions-bar.wat-cf + .actions + = will_paginate @projects, :param_name => :project_page - content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/shared/_search_form.html.haml b/app/views/shared/_search_form.html.haml new file mode 100644 index 000000000..b94ba5a3e --- /dev/null +++ b/app/views/shared/_search_form.html.haml @@ -0,0 +1,6 @@ += form_tag '#', :method => :get do#platform_repository_path(@platform, @repository), :method => :get do + .group + = label_tag :query, t("layout.search_by_name"), :class => :label + = text_field_tag :query + %button.search{:type => "submit"} + = t("layout.search") From 0d10c5071044ec4095f436b1de39fe73554bf6cf Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 17 Oct 2011 18:23:51 +0400 Subject: [PATCH 12/19] Changed representation of Users --- app/controllers/users_controller.rb | 1 + app/models/user.rb | 8 ++--- app/views/users/show.html.haml | 45 +++++++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0c5c84ec0..8707ec422 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -6,6 +6,7 @@ class UsersController < ApplicationController end def show + puts params.inspect @groups = @user.groups.uniq @platforms = @user.platforms.paginate(:page => params[:platform_page], :per_page => 10) @repositories = @user.repositories.paginate(:page => params[:repository_page], :per_page => 10) diff --git a/app/models/user.rb b/app/models/user.rb index 3d926fa0a..9bdd8b36b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,10 +2,10 @@ 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 + 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 => 'Platform', :autosave => true + has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true devise :database_authenticatable, diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 22c49e43c..0089b5bfc 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -30,10 +30,49 @@ = link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_user_path(@user), :class => "button" = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), user_path(@user), :method => "delete", :class => "button", :confirm => t("layout.users.confirm_delete") -= render :partial => 'platforms/list', :object => @platforms +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.platforms.list"), platforms_path + %li= link_to t("layout.platforms.new"), new_user_platform_path(@user) + .content + %h2.title + = t("layout.platforms.list_header") + .inner + = render :partial => 'shared/search_form' + = render :partial => 'platforms/list', :object => @platforms + .actions-bar.wat-cf + .actions + = will_paginate @platforms, :param_name => :platform_page -= render :partial => 'repositories/list', :object => @repositories +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.repositories.list"), repositories_path + %li= link_to t("layout.repositories.new"), new_user_repository_path(@user) + .content + %h2.title + = t("layout.repositories.list_header") + .inner + = render :partial => 'shared/search_form' + = render :partial => 'repositories/list', :object => @repositories + .actions-bar.wat-cf + .actions + = will_paginate @repositories, :param_name => :repository_page -= render :partial => 'projects/list', :object => @projects +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.projects.list"), projects_path + %li= link_to t("layout.projects.new"), new_user_project_path(@user) + .content + %h2.title + = t("layout.projects.list_header") + .inner + = render :partial => 'shared/search_form' + = render :partial => 'projects/list', :object => @projects + .actions-bar.wat-cf + .actions + = will_paginate @projects, :param_name => :project_page - content_for :sidebar, render(:partial => 'sidebar') From 6d065ea01cb0ed2da7a0d2ea4039760295dda3f5 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 17 Oct 2011 18:24:45 +0400 Subject: [PATCH 13/19] Changed routes and added some translations --- config/locales/ru.yml | 6 ++++ config/routes.rb | 82 +++++++++++++++++++++++++------------------ 2 files changed, 53 insertions(+), 35 deletions(-) diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 09042e71e..40ffe378f 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -59,6 +59,10 @@ ru: released_suffix: (выпущена) confirm_delete: Вы уверены, что хотите удалить эту платформу? current_platform_header: Текущая платформа + owner: Владелец + visibility: Видимость + platform_type: Тип платформы + distrib_type: Тип дистрибутива repositories: list: Список @@ -302,6 +306,8 @@ ru: project: name: Название unixname: Unixname + owner: Владелец + visibility: Видимость repository_id: Репозиторий repository: Репозиторий created_at: Создан diff --git a/config/routes.rb b/config/routes.rb index 589a55435..54d8d0a3f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,42 @@ Rosa::Application.routes.draw do devise_for :users +# resources :platforms do +# member do +# get 'freeze' +# get 'unfreeze' +# get 'clone' +# end +# +# resources :products do +# member do +# get :clone +# get :build +# end +# end +# +# resources :repositories do +# resources :projects do +# resource :repo, :controller => "git/repositories", :only => [:show] +# resources :build_lists, :only => [:index, :show] do +# collection do +# get :recent +# post :filter +# end +# member do +# post :publish +# end +# end +# +# member do +# get :build +# post :process_build +# end +# +# end +# end +# end + resources :platforms do member do get 'freeze' @@ -16,48 +52,24 @@ Rosa::Application.routes.draw do end resources :repositories do - resources :projects do - resource :repo, :controller => "git/repositories", :only => [:show] - resources :build_lists, :only => [:index, :show] do - collection do - get :recent - post :filter - end - member do - post :publish - end - end - - member do - get :build - post :process_build - end + end + end + resources :projects do + resources :build_lists, :only => [:index, :show] do + collection do + get :recent + post :filter + end + member do + post :publish end end end - resources :projects - resources :repositories - resources :users do - resources :platforms, :only => [:new, :create] - - resources :projects, :only => [:new, :create] - - resources :repositories, :only => [:new, :create] -# resources :groups do -# collection do -# get :add -# end -# member do -# get :add -# end -# end - end - - resources :groups do + resources :users, :groups do resources :platforms, :only => [:new, :create] resources :projects, :only => [:new, :create] From 3c31bdf29ce82a230ab7903a99d707c6980b1bd0 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 17 Oct 2011 18:27:07 +0400 Subject: [PATCH 14/19] Changed Platforms representation --- app/controllers/platforms_controller.rb | 39 ++++++++++++++++++------- app/models/platform.rb | 22 ++++++++++++++ app/views/platforms/_form.html.haml | 2 +- app/views/platforms/_list.html.haml | 38 +++++++----------------- app/views/platforms/_sidebar.html.haml | 5 ++++ app/views/platforms/index.html.haml | 15 +++++++++- app/views/platforms/new.html.haml | 8 ++--- app/views/platforms/show.html.haml | 28 ++++++++++++++++-- 8 files changed, 111 insertions(+), 46 deletions(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index a2a7e35cc..9494dd461 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -4,6 +4,7 @@ class PlatformsController < ApplicationController before_filter :authenticate_user! before_filter :find_platform, :only => [:freeze, :unfreeze, :clone] + before_filter :get_paths, :only => [:new, :create] def index @platforms = Platform.paginate(:page => params[:platform_page]) @@ -12,6 +13,7 @@ class PlatformsController < ApplicationController def show @platform = Platform.find params[:id], :include => :repositories @repositories = @platform.repositories + @members = @platform.members.uniq end def new @@ -20,16 +22,18 @@ class PlatformsController < ApplicationController end def create - pp params -# @platform = Platform.new params[:platform] -# if @platform.save -# flash[:notice] = I18n.t("flash.platform.saved") -# redirect_to @platform -# else -# flash[:error] = I18n.t("flash.platform.saved_error") -# @platforms = Platform.all -# render :action => :new -# end + @platform = Platform.new params[:platform] + + @platform.owner = get_acter + + if @platform.save + flash[:notice] = I18n.t("flash.platform.saved") + redirect_to @platform + else + flash[:error] = I18n.t("flash.platform.saved_error") + @platforms = Platform.all + render :action => :new + end end def freeze @@ -73,6 +77,21 @@ class PlatformsController < ApplicationController end protected + def get_paths + if params[:user_id] + @user = User.find params[:user_id] + @platforms_path = user_platforms_path @user + @new_platform_path = new_user_platform_path @user + elsif params[:group_id] + @group = Group.find params[:group_id] + @platforms_path = group_platforms_path @group + @new_platform_path = new_group_platform_path @group + else + @platforms_path = platforms_path + @new_platform_path = new_platform_path + end + end + def find_platform @platform = Platform.find params[:id] end diff --git a/app/models/platform.rb b/app/models/platform.rb index 6099d97ff..5eed3840e 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -1,6 +1,7 @@ #require 'lib/build_server.rb' class Platform < ActiveRecord::Base belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id' + belongs_to :owner, :polymorphic => true has_many :repositories, :dependent => :destroy has_many :products, :dependent => :destroy @@ -11,6 +12,7 @@ class Platform < ActiveRecord::Base validates :name, :presence => true, :uniqueness => true validates :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false + after_create :make_owner_rel # before_create :xml_rpc_create # before_destroy :xml_rpc_destroy # before_update :check_freezing @@ -34,6 +36,20 @@ class Platform < ActiveRecord::Base released? ? "#{self[:name]} #{I18n.t("layout.platforms.released_suffix")}" : self[:name] end + def roles_of(user) + objects.where(:object_id => user.id, :object_type => user.class).map {|rel| rel.role}.reject {|r| r.nil?} + end + + def add_role(user, role) + roles = objects.where(:object_id => user.id, :object_type => user.class).map {|rel| rel.role}.reject {|r| r.nil?} + unless roles.include? role + rel = Relation.create(:object_type => user.class.to_s, :object_id => user.id, + :target_type => self.class.to_s, :target_id => id) + rel.role = role + rel.save + end + end + protected def build_path(dir) @@ -54,6 +70,12 @@ class Platform < ActiveRecord::Base end end + def make_owner_rel + members << owner if owner.instance_of? User + groups << owner if owner.instance_of? Group + save + end + def xml_rpc_create return true # result = BuildServer.add_platform unixname, APP_CONFIG['root_path'] diff --git a/app/views/platforms/_form.html.haml b/app/views/platforms/_form.html.haml index 3cdecdc89..6152a8713 100644 --- a/app/views/platforms/_form.html.haml +++ b/app/views/platforms/_form.html.haml @@ -19,4 +19,4 @@ = image_tag("web-app-theme/icons/tick.png", :alt => t("layout.save")) = t("layout.save") %span.text_button_padding= t("layout.or") - = link_to t("layout.cancel"), platforms_path, :class => "text_button_padding link_button" + = link_to t("layout.cancel"), @platforms_path, :class => "text_button_padding link_button" diff --git a/app/views/platforms/_list.html.haml b/app/views/platforms/_list.html.haml index 1bd464eec..e9d8caf7f 100644 --- a/app/views/platforms/_list.html.haml +++ b/app/views/platforms/_list.html.haml @@ -1,28 +1,10 @@ -.block - .secondary-navigation - %ul.wat-cf - %li.first.active= link_to t("layout.platforms.list"), platforms_path - %li= link_to t("layout.platforms.new"), new_platform_path - .content - %h2.title - = t("layout.platforms.list_header") - .inner - = form_tag '#', :method => :get do#platform_repository_path(@platform, @repository), :method => :get do - .group - = label_tag :query, t("layout.search_by_name"), :class => :label - = text_field_tag :query - %button.search{:type => "submit"} - = t("layout.search") - %table.table - %tr - %th.first= t("activerecord.attributes.platform.name") - %th.last   - - @platforms.each do |platform| - %tr{:class => cycle("odd", "even")} - %td - = link_to platform.name, platform_path(platform) - %td.last - #{link_to t("layout.show"), platform_path(platform)} | #{link_to t("layout.delete"), platform_path(platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete")} - .actions-bar.wat-cf - .actions - = will_paginate @platforms, :param_name => :platform_page +%table.table + %tr + %th.first= t("activerecord.attributes.platform.name") + %th.last   + - @platforms.each do |platform| + %tr{:class => cycle("odd", "even")} + %td + = link_to platform.name, platform_path(platform) + %td.last + #{link_to t("layout.show"), platform_path(platform)} | #{link_to t("layout.delete"), platform_path(platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete")} diff --git a/app/views/platforms/_sidebar.html.haml b/app/views/platforms/_sidebar.html.haml index e69de29bb..dbe489981 100644 --- a/app/views/platforms/_sidebar.html.haml +++ b/app/views/platforms/_sidebar.html.haml @@ -0,0 +1,5 @@ +.block.notice + %h3= t("layout.groups.members") + .content + - @platform.members.uniq.each do |member| + %p= link_to member.name + " (#{@platform.roles_of(member).map{|r| r.name}.join(', ')})", user_path(member) diff --git a/app/views/platforms/index.html.haml b/app/views/platforms/index.html.haml index 4af4c9181..8c86683d4 100644 --- a/app/views/platforms/index.html.haml +++ b/app/views/platforms/index.html.haml @@ -1,4 +1,17 @@ -=render :partial => 'list', :object => @platforms +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.platforms.list"), platforms_path + %li= link_to t("layout.platforms.new"), new_platform_path + .content + %h2.title + = t("layout.platforms.list_header") + .inner + = render :partial => 'shared/search_form' + = render :partial => 'platforms/list', :object => @platforms + .actions-bar.wat-cf + .actions + = will_paginate @platforms, :param_name => :platform_page /.block / .secondary-navigation / %ul.wat-cf diff --git a/app/views/platforms/new.html.haml b/app/views/platforms/new.html.haml index 5f44e786a..a6fad7b32 100644 --- a/app/views/platforms/new.html.haml +++ b/app/views/platforms/new.html.haml @@ -1,11 +1,11 @@ .block .secondary-navigation %ul.wat-cf - %li.first= link_to "#{t("layout.platforms.list")}", platforms_path - %li.active= link_to "#{t("layout.platforms.new")}", new_platform_path + %li.first= link_to "#{t("layout.platforms.list")}", @platforms_path + %li.active= link_to "#{t("layout.platforms.new")}", @new_platform_path .content %h2.title = t("layout.platforms.new_header") .inner - = form_for :platform, :url => platforms_path, :html => { :class => :form } do |f| - = render :partial => "form", :locals => {:f => f} \ No newline at end of file + = form_for :platform, :url => @platforms_path, :html => { :class => :form } do |f| + = render :partial => "form", :locals => {:f => f} diff --git a/app/views/platforms/show.html.haml b/app/views/platforms/show.html.haml index c6b5c770c..3cd62b70a 100644 --- a/app/views/platforms/show.html.haml +++ b/app/views/platforms/show.html.haml @@ -29,6 +29,31 @@ \: = @platform.path + %p + %b + = t('layout.platforms.owner') + \: + = link_to @platform.owner.name, url_for(@platform.owner) + + %p + %b + = t('layout.platforms.visibility') + \: + = @platform.visibility + + %p + %b + = t('layout.platforms.platform_type') + \: + = @platform.platform_type + + %p + %b + = t('layout.platforms.distrib_type') + \: + = @platform.distrib_type + + .wat-cf -#= link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_platform_path(@platform), :class => "button" = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_path(@platform), :method => "delete", :class => "button", :confirm => t("layout.platforms.confirm_delete") @@ -83,5 +108,4 @@ #{link_to t("layout.show"), platform_product_path(@platform, product)} | #{link_to t("layout.delete"), platform_product_path(@platform, product), :method => :delete, :confirm => t("layout.products.confirm_delete")} #{(product.can_clone? ? "| #{link_to t("layout.products.clone"), clone_platform_product_path(@platform, product)}" : "").html_safe } .actions-bar.wat-cf .actions --#- content_for :sidebar do - +- content_for :sidebar, render(:partial => 'sidebar') From b4c199c1b8fea1db8c2f2e8c459f77fa8f498153 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Tue, 18 Oct 2011 19:00:06 +0400 Subject: [PATCH 15/19] Finished models. --- app/models/group.rb | 32 ++++++++++++++++++++++++++++++++ app/models/platform.rb | 23 +++++++++++++++++------ app/models/project.rb | 14 ++++++++++---- app/models/repository.rb | 19 ++++++++++++++----- app/models/user.rb | 34 +++++++++++++++++++++++++++++++++- 5 files changed, 106 insertions(+), 16 deletions(-) diff --git a/app/models/group.rb b/app/models/group.rb index 3866664f9..d8acb3774 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -2,8 +2,10 @@ class Group < ActiveRecord::Base validates :name, :uname, :owner_id, :presence => true validates :name, :uname, :uniqueness => true + validates :uname, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false belongs_to :owner, :class_name => 'User' + has_many :own_projects, :as => :owner, :class_name => 'Project' has_many :objects, :as => :target, :class_name => 'Relation' has_many :targets, :as => :object, :class_name => 'Relation' @@ -13,6 +15,9 @@ class Group < ActiveRecord::Base has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true + before_save :create_dir + after_destroy :remove_dir + def roles_of(user) objects.where(:object_id => user.id, :object_type => user.class).map {|rel| rel.role}.reject {|r| r.nil?} end @@ -26,4 +31,31 @@ class Group < ActiveRecord::Base rel.save end end + + def path + build_path(uname) + end + + protected + + def build_path(dir) + File.join(APP_CONFIG['root_path'], 'groups', dir) + end + + def create_dir + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} already exists" if exists + if new_record? + FileUtils.mkdir_p(path) + elsif uname_changed? + FileUtils.mv(build_path(uname_was), build_path(uname)) + end + end + + def remove_dir + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} didn't exists" unless exists + FileUtils.rm_rf(path) + end + end diff --git a/app/models/platform.rb b/app/models/platform.rb index 5eed3840e..ceca922f2 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -2,6 +2,7 @@ class Platform < ActiveRecord::Base belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id' belongs_to :owner, :polymorphic => true + has_many :repositories, :dependent => :destroy has_many :products, :dependent => :destroy @@ -10,9 +11,12 @@ class Platform < ActiveRecord::Base 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 + validates :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false - after_create :make_owner_rel + #after_create :make_owner_rel + before_save :create_directory + before_save :make_owner_rel + after_destroy :remove_directory # before_create :xml_rpc_create # before_destroy :xml_rpc_destroy # before_update :check_freezing @@ -53,7 +57,7 @@ class Platform < ActiveRecord::Base protected def build_path(dir) - File.join(APP_CONFIG['root_path'], dir) + File.join(APP_CONFIG['root_path'], 'platforms', dir) end def git_path(dir) @@ -70,10 +74,17 @@ class Platform < ActiveRecord::Base end end + def remove_directory + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} didn't exists" unless exists + FileUtils.rm_rf(path) + end + def make_owner_rel - members << owner if owner.instance_of? User - groups << owner if owner.instance_of? Group - save + unless members.include? owner + members << owner if owner.instance_of? User + groups << owner if owner.instance_of? Group + end end def xml_rpc_create diff --git a/app/models/project.rb b/app/models/project.rb index d6483450b..3d4936d8e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,16 +1,18 @@ class Project < ActiveRecord::Base belongs_to :owner, :polymorphic => true + has_many :build_lists, :dependent => :destroy has_many :project_to_repositories has_many :repositories, :through => :project_to_repositories - 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' + has_many :relations, :as => :target + has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User' + has_many :groups, :through => :relations, :source => :object, :source_type => 'Group' validates :name, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :allow_nil => false, :allow_blank => false - validates :unixname, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false + validates :unixname, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false +# validates :unixname, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false include Project::HasRepository @@ -22,6 +24,10 @@ class Project < ActiveRecord::Base # before_create :xml_rpc_create # before_destroy :xml_rpc_destroy + def members + collaborators + groups + end + # Redefining a method from Project::HasRepository module to reflect current situation def git_repo_path @git_repo_path ||= File.join(repository.platform.path, "projects", unixname + ".git") diff --git a/app/models/repository.rb b/app/models/repository.rb index 0b90d4c4d..0cbacfc3a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -15,7 +15,9 @@ class Repository < ActiveRecord::Base scope :recent, order("name ASC") - after_create :make_owner_rel + before_save :create_directory + before_save :make_owner_rel + after_destroy :remove_directory # before_create :xml_rpc_create # before_destroy :xml_rpc_destroy @@ -35,9 +37,10 @@ class Repository < ActiveRecord::Base protected def make_owner_rel - members << owner if owner.instance_of? User - groups << owner if owner.instance_of? Group - save + unless members.include? owner + members << owner if owner.instance_of? User + groups << owner if owner.instance_of? Group + end end def build_path(dir) @@ -54,7 +57,13 @@ class Repository < ActiveRecord::Base FileUtils.mv(build_path(unixname_was), buildpath(unixname)) end end - + + def remove_directory + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} didn't exists" unless exists + FileUtils.rm_rf(path) + end + def xml_rpc_create result = BuildServer.create_repo unixname, platform.unixname if result == BuildServer::SUCCESS diff --git a/app/models/user.rb b/app/models/user.rb index 9bdd8b36b..eec72175d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,6 +2,9 @@ require 'digest/md5' class User < ActiveRecord::Base has_many :targets, :as => :object, :class_name => 'Relation' + has_many :own_projects, :as => :owner, :class_name => 'Project' + has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group' + 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 => 'Platform', :autosave => true @@ -11,11 +14,20 @@ class User < ActiveRecord::Base devise :database_authenticatable, :recoverable, :rememberable, :validatable - attr_accessible :email, :password, :password_confirmation, :remember_me, :name + attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :uname + + validates :uname, :presence => true, :uniqueness => true, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false before_validation :generate_password, :on => :create after_create :send_notification_email + before_save :create_dir + after_destroy :remove_dir + + def path + build_path(uname) + end + protected def generate_password @@ -27,4 +39,24 @@ class User < ActiveRecord::Base def send_notification_email UserMailer.new_user_notification(self).deliver end + + def build_path(dir) + File.join(APP_CONFIG['root_path'], 'users', dir) + end + + def create_dir + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} already exists" if exists + if new_record? + FileUtils.mkdir_p(path) + elsif uname_changed? + FileUtils.mv(build_path(uname_was), build_path(uname)) + end + end + + def remove_dir + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} didn't exists" unless exists + FileUtils.rm_rf(path) + end end From f7ff11208709eedce383490835abdaf29b36dc36 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Tue, 18 Oct 2011 19:00:06 +0400 Subject: [PATCH 16/19] Finished models. --- app/models/group.rb | 32 +++++++++++++++++ app/models/platform.rb | 23 +++++++++---- app/models/project.rb | 14 +++++--- app/models/repository.rb | 19 ++++++++--- app/models/user.rb | 34 ++++++++++++++++++- .../20111018102655_add_uname_to_users.rb | 9 +++++ db/schema.rb | 3 +- 7 files changed, 117 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20111018102655_add_uname_to_users.rb diff --git a/app/models/group.rb b/app/models/group.rb index 3866664f9..d8acb3774 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -2,8 +2,10 @@ class Group < ActiveRecord::Base validates :name, :uname, :owner_id, :presence => true validates :name, :uname, :uniqueness => true + validates :uname, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false belongs_to :owner, :class_name => 'User' + has_many :own_projects, :as => :owner, :class_name => 'Project' has_many :objects, :as => :target, :class_name => 'Relation' has_many :targets, :as => :object, :class_name => 'Relation' @@ -13,6 +15,9 @@ class Group < ActiveRecord::Base has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true + before_save :create_dir + after_destroy :remove_dir + def roles_of(user) objects.where(:object_id => user.id, :object_type => user.class).map {|rel| rel.role}.reject {|r| r.nil?} end @@ -26,4 +31,31 @@ class Group < ActiveRecord::Base rel.save end end + + def path + build_path(uname) + end + + protected + + def build_path(dir) + File.join(APP_CONFIG['root_path'], 'groups', dir) + end + + def create_dir + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} already exists" if exists + if new_record? + FileUtils.mkdir_p(path) + elsif uname_changed? + FileUtils.mv(build_path(uname_was), build_path(uname)) + end + end + + def remove_dir + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} didn't exists" unless exists + FileUtils.rm_rf(path) + end + end diff --git a/app/models/platform.rb b/app/models/platform.rb index 5eed3840e..ceca922f2 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -2,6 +2,7 @@ class Platform < ActiveRecord::Base belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id' belongs_to :owner, :polymorphic => true + has_many :repositories, :dependent => :destroy has_many :products, :dependent => :destroy @@ -10,9 +11,12 @@ class Platform < ActiveRecord::Base 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 + validates :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false - after_create :make_owner_rel + #after_create :make_owner_rel + before_save :create_directory + before_save :make_owner_rel + after_destroy :remove_directory # before_create :xml_rpc_create # before_destroy :xml_rpc_destroy # before_update :check_freezing @@ -53,7 +57,7 @@ class Platform < ActiveRecord::Base protected def build_path(dir) - File.join(APP_CONFIG['root_path'], dir) + File.join(APP_CONFIG['root_path'], 'platforms', dir) end def git_path(dir) @@ -70,10 +74,17 @@ class Platform < ActiveRecord::Base end end + def remove_directory + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} didn't exists" unless exists + FileUtils.rm_rf(path) + end + def make_owner_rel - members << owner if owner.instance_of? User - groups << owner if owner.instance_of? Group - save + unless members.include? owner + members << owner if owner.instance_of? User + groups << owner if owner.instance_of? Group + end end def xml_rpc_create diff --git a/app/models/project.rb b/app/models/project.rb index d6483450b..3d4936d8e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,16 +1,18 @@ class Project < ActiveRecord::Base belongs_to :owner, :polymorphic => true + has_many :build_lists, :dependent => :destroy has_many :project_to_repositories has_many :repositories, :through => :project_to_repositories - 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' + has_many :relations, :as => :target + has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User' + has_many :groups, :through => :relations, :source => :object, :source_type => 'Group' validates :name, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :allow_nil => false, :allow_blank => false - validates :unixname, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false + validates :unixname, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false +# validates :unixname, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false include Project::HasRepository @@ -22,6 +24,10 @@ class Project < ActiveRecord::Base # before_create :xml_rpc_create # before_destroy :xml_rpc_destroy + def members + collaborators + groups + end + # Redefining a method from Project::HasRepository module to reflect current situation def git_repo_path @git_repo_path ||= File.join(repository.platform.path, "projects", unixname + ".git") diff --git a/app/models/repository.rb b/app/models/repository.rb index 0b90d4c4d..0cbacfc3a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -15,7 +15,9 @@ class Repository < ActiveRecord::Base scope :recent, order("name ASC") - after_create :make_owner_rel + before_save :create_directory + before_save :make_owner_rel + after_destroy :remove_directory # before_create :xml_rpc_create # before_destroy :xml_rpc_destroy @@ -35,9 +37,10 @@ class Repository < ActiveRecord::Base protected def make_owner_rel - members << owner if owner.instance_of? User - groups << owner if owner.instance_of? Group - save + unless members.include? owner + members << owner if owner.instance_of? User + groups << owner if owner.instance_of? Group + end end def build_path(dir) @@ -54,7 +57,13 @@ class Repository < ActiveRecord::Base FileUtils.mv(build_path(unixname_was), buildpath(unixname)) end end - + + def remove_directory + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} didn't exists" unless exists + FileUtils.rm_rf(path) + end + def xml_rpc_create result = BuildServer.create_repo unixname, platform.unixname if result == BuildServer::SUCCESS diff --git a/app/models/user.rb b/app/models/user.rb index 9bdd8b36b..eec72175d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,6 +2,9 @@ require 'digest/md5' class User < ActiveRecord::Base has_many :targets, :as => :object, :class_name => 'Relation' + has_many :own_projects, :as => :owner, :class_name => 'Project' + has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group' + 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 => 'Platform', :autosave => true @@ -11,11 +14,20 @@ class User < ActiveRecord::Base devise :database_authenticatable, :recoverable, :rememberable, :validatable - attr_accessible :email, :password, :password_confirmation, :remember_me, :name + attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :uname + + validates :uname, :presence => true, :uniqueness => true, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false before_validation :generate_password, :on => :create after_create :send_notification_email + before_save :create_dir + after_destroy :remove_dir + + def path + build_path(uname) + end + protected def generate_password @@ -27,4 +39,24 @@ class User < ActiveRecord::Base def send_notification_email UserMailer.new_user_notification(self).deliver end + + def build_path(dir) + File.join(APP_CONFIG['root_path'], 'users', dir) + end + + def create_dir + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} already exists" if exists + if new_record? + FileUtils.mkdir_p(path) + elsif uname_changed? + FileUtils.mv(build_path(uname_was), build_path(uname)) + end + end + + def remove_dir + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} didn't exists" unless exists + FileUtils.rm_rf(path) + end end diff --git a/db/migrate/20111018102655_add_uname_to_users.rb b/db/migrate/20111018102655_add_uname_to_users.rb new file mode 100644 index 000000000..7572a6139 --- /dev/null +++ b/db/migrate/20111018102655_add_uname_to_users.rb @@ -0,0 +1,9 @@ +class AddUnameToUsers < ActiveRecord::Migration + def self.up + add_column :users, :uname, :string + end + + def self.down + remove_column :users, :uname + end +end diff --git a/db/schema.rb b/db/schema.rb index f8e3e5745..4c9176aa5 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 => 20111016225240) do +ActiveRecord::Schema.define(:version => 20111018102655) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -196,6 +196,7 @@ ActiveRecord::Schema.define(:version => 20111016225240) do t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" + t.string "uname" end add_index "users", ["email"], :name => "index_users_on_email", :unique => true From e5438b29bc8fb42ed4dfb36f7a78fc22dfdc9d9f Mon Sep 17 00:00:00 2001 From: Toljio Date: Tue, 18 Oct 2011 22:31:59 +0400 Subject: [PATCH 17/19] change roles/rights --- app/controllers/application_controller.rb | 46 ++++++++++++++--- app/controllers/roles_controller.rb | 60 ++++++++++++++++++++++ app/models/permission.rb | 33 +++++++++++- app/models/right.rb | 2 - app/models/role.rb | 1 - app/views/roles/_form.html.haml | 15 ++++++ app/views/roles/_sidebar.html.haml | 0 app/views/roles/edit.html.haml | 12 +++++ app/views/roles/index.html.haml | 30 +++++++++++ app/views/roles/new.html.haml | 11 ++++ app/views/roles/show.html.haml | 38 ++++++++++++++ db/migrate/20111012222824_create_rights.rb | 14 ----- db/migrate/20111012223306_create_roles.rb | 2 - 13 files changed, 236 insertions(+), 28 deletions(-) create mode 100644 app/controllers/roles_controller.rb delete mode 100644 app/models/right.rb create mode 100644 app/views/roles/_form.html.haml create mode 100644 app/views/roles/_sidebar.html.haml create mode 100644 app/views/roles/edit.html.haml create mode 100644 app/views/roles/index.html.haml create mode 100644 app/views/roles/new.html.haml create mode 100644 app/views/roles/show.html.haml delete mode 100644 db/migrate/20111012222824_create_rights.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8b5af54af..f7372d2aa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,45 @@ +# coding: UTF-8 class ApplicationController < ActionController::Base protect_from_forgery layout :layout_by_resource - + private + def checkright(role_id) + @role=Role.find(role_id) + if @role.name.downcase!="admin" + @c = self.controller_name + @a = self.action_name + case @c + when "projects" + case @a + when "new", "show", "create" + @right=1,2 + when "build", "process_build" + @right=3 + end + when "repositories" + case @a + when "show" + @right=4 + when "add_project", "remove_project" + @right=5 + when "new", "create" + @right=6 + end + when "platforms" + case @a + when "edit", "update", "freeze", "unfreeze" + @right=7 + end + else return true + end + Permission.where(:role_id => @role.id, :right_id => @right).first + @ok=false if @permission.nil? + if not @ok + flash[:notice] = t('layout.not_access') + redirect_to(:back) + end + end + end protected def layout_by_resource if devise_controller? @@ -11,12 +49,6 @@ class ApplicationController < ActionController::Base end end - def get_acter - return User.find params[:user_id] if params[:user_id] - return Group.find params[:group_id] if params[:group_id] - return current_user - end - def authenticate_build_service! if request.remote_ip != APP_CONFIG['build_service_ip'] render :nothing => true, :status => 403 diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb new file mode 100644 index 000000000..2a6429bdb --- /dev/null +++ b/app/controllers/roles_controller.rb @@ -0,0 +1,60 @@ +class RolesController < ApplicationController + before_filter :find_role, :only => [:show, :edit, :update, :destroy] + + def index + @roles = Role.all + end + + def show + @permissions = Permission.where(:role_id => @role.id) + end + + def new + @role = Role.new + end + + def edit + end + + def create + @role = Role.new(params[:role]) + if @role.save + for right in params[:right][:id] + Permission.create(:role_id => @role.id, :right_id => right) + end + flash[:notice] = t('flash.role.saved') + redirect_to roles_path + else + flash[:error] = t('flash.role.save_error') + render :action => :new + end + end + + def update + if @role.update_attributes(params[:role]) + if params[:right][:id] + Permission.destroy_all(:role_id => @role.id) + for right in params[:right][:id] + Permission.create(:role_id => @role.id, :right_id => right) + end + end + flash[:notice] = t('flash.role.saved') + redirect_to roles_path + else + flash[:error] = t('flash.role.save_error') + render :action => :edit + end + end + + def destroy + @role.destroy + Permission.destroy_all(:role_id => params[:id]) + flash[:notice] = t("flash.role.destroyed") + redirect_to roles_path + end + + protected + def find_role + @role = Role.find(params[:id]) + end +end \ No newline at end of file diff --git a/app/models/permission.rb b/app/models/permission.rb index da2599966..5db19cfa5 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -1,4 +1,33 @@ class Permission < ActiveRecord::Base - belongs_to :right belongs_to :role -end + def name + Permission.right(self.right_id) + end + def self.get_rights_list + res=[] + for k in 1..8 + res << [Permission.right(k), k] + end + return res + end + def self.right(n) + case n + when 1 + "Проекты - Чтение" + when 2 + "Проекты - Чтение/Запись" + when 3 + "Проекты - Сборка" + when 4 + "Репозиторий - Просмотр" + when 5 + "Репозиторий - Изменение состава пакетов" + when 6 + "Платформа - Создание/Удаление репозиториев" + when 7 + "Платформа - Изменение параметров платформы" + when 8 + "Платформа - Сборка" + end + end +end \ No newline at end of file diff --git a/app/models/right.rb b/app/models/right.rb deleted file mode 100644 index 8289fc2e8..000000000 --- a/app/models/right.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Right < ActiveRecord::Base -end diff --git a/app/models/role.rb b/app/models/role.rb index cf9a70496..85e31b9da 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -1,5 +1,4 @@ class Role < ActiveRecord::Base has_many :permissions - has_many :rights, :through => :permissions has_many :relations end diff --git a/app/views/roles/_form.html.haml b/app/views/roles/_form.html.haml new file mode 100644 index 000000000..8710ea245 --- /dev/null +++ b/app/views/roles/_form.html.haml @@ -0,0 +1,15 @@ +.group + = f.label :name, t("activerecord.attributes.role.name"), :class => :label + = f.text_field :name, :class => 'text_field' +.group + %label.label Разрешения + - rights = Permission.get_rights_list + - rights_selected = Permission.where(:role_id => @role.id).map { |perm| perm.right_id } + = select_tag("right[id]", options_for_select(rights, rights_selected), :size => 10, :multiple => true) + +.group.navform.wat-cf + %button.button{:type => "submit"} + = image_tag("web-app-theme/icons/tick.png", :alt => t("layout.save")) + = t("layout.save") + %span.text_button_padding= t("layout.or") + = link_to t("layout.cancel"), roles_path, :class => "text_button_padding link_button" \ No newline at end of file diff --git a/app/views/roles/_sidebar.html.haml b/app/views/roles/_sidebar.html.haml new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/roles/edit.html.haml b/app/views/roles/edit.html.haml new file mode 100644 index 000000000..8f833ba6d --- /dev/null +++ b/app/views/roles/edit.html.haml @@ -0,0 +1,12 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first= link_to t("layout.roles.list"), roles_path + %li= link_to t("layout.roles.new"), new_role_path + %li.active= link_to t("layout.roles.edit"), edit_role_path + .content + %h2.title= t("layout.roles.edit_header") + .inner + = form_for @role, :url => role_path(@role), :html => { :class => :form } do |f| + = render :partial => "form", :locals => {:f => f} +- content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/roles/index.html.haml b/app/views/roles/index.html.haml new file mode 100644 index 000000000..3462e5071 --- /dev/null +++ b/app/views/roles/index.html.haml @@ -0,0 +1,30 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first.active= link_to t("layout.roles.list"), roles_path + %li= link_to t("layout.roles.new"), new_role_path + .content + %h2.title + = t("layout.roles.list_header") + .inner + -unless @roles.empty? + %table.table + %tr + %th.first ID + %th= t("activerecord.attributes.role.name") + %th.last   + - @roles.each do |role| + %tr{:class => cycle("odd", "even")} + %td + = role.id + %td + = link_to role.name, role_path(role) + %td.last + #{link_to t("layout.show"), role_path(role)} | #{link_to t("layout.edit"), edit_role_path(role)} | #{link_to t("layout.delete"), role_path(role), :method => :delete, :confirm => t("layout.roles.confirm_delete")} + .actions-bar.wat-cf + .actions + -else + .inner + %label.label Роли отсутствуют, + = link_to "создать новую роль", new_role_path +- content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/roles/new.html.haml b/app/views/roles/new.html.haml new file mode 100644 index 000000000..c433a39ed --- /dev/null +++ b/app/views/roles/new.html.haml @@ -0,0 +1,11 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first= link_to t("layout.roles.list"), roles_path + %li.active= link_to t("layout.roles.new"), new_role_path + .content + %h2.title= t("layout.roles.new_header") + .inner + = form_for :role, :url => roles_path, :html => { :class => :form } do |f| + = render :partial => "form", :locals => {:f => f} +- content_for :sidebar, render(:partial => 'sidebar') \ No newline at end of file diff --git a/app/views/roles/show.html.haml b/app/views/roles/show.html.haml new file mode 100644 index 000000000..6a98822b6 --- /dev/null +++ b/app/views/roles/show.html.haml @@ -0,0 +1,38 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first= link_to t("layout.roles.list"), roles_path + %li= link_to t("layout.roles.new"), new_role_path + %li.active= link_to t("layout.roles.show"), role_path + .content + .inner + %p + %b + Id + \: + = @role.id + %p + %b + = t("activerecord.attributes.role.name") + \: + = @role.name + %p + %b + = t("activerecord.models.permission") + \: + -unless @permissions.empty? + %table.table + %tr + %th.first ID + %th= t("activerecord.attributes.right.name") + - @permissions.each do |permission| + %tr{:class => cycle("odd", "even")} + %td + = permission.right_id + %td + = permission.name + .wat-cf + = link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_role_path(@role), :class => "button" + = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), role_path(@role), :method => "delete", :class => "button", :confirm => t("layout.users.confirm_delete") + +- content_for :sidebar, render(:partial => 'sidebar') diff --git a/db/migrate/20111012222824_create_rights.rb b/db/migrate/20111012222824_create_rights.rb deleted file mode 100644 index 37f5cfaaf..000000000 --- a/db/migrate/20111012222824_create_rights.rb +++ /dev/null @@ -1,14 +0,0 @@ -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/20111012223306_create_roles.rb b/db/migrate/20111012223306_create_roles.rb index 947201455..b5693219d 100644 --- a/db/migrate/20111012223306_create_roles.rb +++ b/db/migrate/20111012223306_create_roles.rb @@ -3,8 +3,6 @@ class CreateRoles < ActiveRecord::Migration create_table :roles do |t| t.integer :id t.string :name - t.string :to - t.string :on t.timestamps end From 7ef909afbbe99f64783e8658f2c802f19588450e Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 19 Oct 2011 17:14:53 +0400 Subject: [PATCH 18/19] Changed some models. --- app/models/platform.rb | 2 +- app/models/project.rb | 20 ++++++++++++++------ app/models/project_to_repository.rb | 28 ++++++++++++++++++++++++++++ app/models/repository.rb | 2 +- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/app/models/platform.rb b/app/models/platform.rb index ceca922f2..4a14012a7 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -81,7 +81,7 @@ class Platform < ActiveRecord::Base end def make_owner_rel - unless members.include? owner + unless members.include? owner or groups.include? owner members << owner if owner.instance_of? User groups << owner if owner.instance_of? Group end diff --git a/app/models/project.rb b/app/models/project.rb index 3d4936d8e..6bc6c6685 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -19,8 +19,9 @@ class Project < ActiveRecord::Base scope :recent, order("name ASC") scope :by_name, lambda { |name| {:conditions => ['name like ?', '%' + name + '%']} } - after_create :make_owner_rel - #before_create :create_directory, :create_git_repo + before_save :create_directory#, :create_git_repo + before_save :make_owner_rel + after_destroy :remove_directory # before_create :xml_rpc_create # before_destroy :xml_rpc_destroy @@ -56,13 +57,14 @@ class Project < ActiveRecord::Base protected def make_owner_rel - collaborators << owner if owner.instance_of? User - groups << owner if owner.instance_of? Group - save + unless groups.include? owner or collaborators.include? owner + collaborators << owner if owner.instance_of? User + groups << owner if owner.instance_of? Group + end end def build_path(dir) - File.join(repository.path, dir) + File.join(APP_CONFIG['root_path'], 'projects', dir) end def create_directory @@ -75,6 +77,12 @@ class Project < ActiveRecord::Base end end + def remove_directory + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} didn't exists" unless exists + FileUtils.rm_rf(path) + end + def xml_rpc_create result = BuildServer.create_project unixname, repository.platform.unixname, repository.unixname if result == BuildServer::SUCCESS diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb index e18381fd1..a0cc507d5 100644 --- a/app/models/project_to_repository.rb +++ b/app/models/project_to_repository.rb @@ -1,4 +1,32 @@ class ProjectToRepository < ActiveRecord::Base belongs_to :project belongs_to :repository + + before_save :create_link + after_destroy :remove_link + + def path + build_path(project.unixname) + end + + protected + + def build_path(dir) + File.join(repository.path, dir) + end + + def create_link + exists = File.exists?(path) && File.directory?(path) + raise "Symlink #{path} already exists" if exists + if new_record? + FileUtils.ln_s(project.path, path) + end + end + + def remove_link + exists = File.exists?(path) && File.directory?(path) + raise "Directory #{path} didn't exists" unless exists + FileUtils.rm_rf(path) + end + end diff --git a/app/models/repository.rb b/app/models/repository.rb index 0cbacfc3a..1ee8a3850 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -3,7 +3,7 @@ class Repository < ActiveRecord::Base belongs_to :owner, :polymorphic => true has_many :projects, :through => :project_to_repositories #, :dependent => :destroy - has_many :project_to_repositories + has_many :project_to_repositories, :validate => true has_many :objects, :as => :target, :class_name => 'Relation' has_many :members, :through => :objects, :source => :object, :source_type => 'User' From ee9af32fa6f74de9b699b84547c7b815f30fc218 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 19 Oct 2011 17:16:29 +0400 Subject: [PATCH 19/19] Adding projects to repositories. --- app/controllers/repositories_controller.rb | 58 ++++++++++++++++-- app/views/repositories/_proj_list.html.haml | 11 ++++ app/views/repositories/_proj_list1.html.haml | 10 ++++ app/views/repositories/index.html.haml | 4 +- .../repositories/projects_list.html.haml | 60 +++++++++++++++++++ app/views/repositories/show.html.haml | 50 ++++++++-------- config/initializers/ext.rb | 4 ++ config/locales/ru.yml | 5 ++ config/routes.rb | 7 ++- 9 files changed, 177 insertions(+), 32 deletions(-) create mode 100644 app/views/repositories/_proj_list.html.haml create mode 100644 app/views/repositories/_proj_list1.html.haml create mode 100644 app/views/repositories/projects_list.html.haml create mode 100644 config/initializers/ext.rb diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 07e5c6c03..dad3a6e0e 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -1,8 +1,8 @@ class RepositoriesController < ApplicationController before_filter :authenticate_user! -# before_filter :find_platform, :except => [:index, :new, :create] - before_filter :find_repository, :only => [:show, :destroy] - before_filter :get_paths, :only => [:new, :create] + #before_filter :find_platform, :except => [:index, :new, :create] + before_filter :find_repository, :only => [:show, :destroy, :add_project, :remove_project] + before_filter :get_paths, :only => [:show, :new, :create, :add_project, :remove_project] before_filter :find_platforms, :only => [:new, :create] def index @@ -11,9 +11,9 @@ class RepositoriesController < ApplicationController def show if params[:query] - @projects = @repository.projects.recent.by_name(params[:query]).paginate :page => params[:page], :per_page => 30 + @projects = @repository.projects.recent.by_name(params[:query]).paginate :page => params[:project_page], :per_page => 30 else - @projects = @repository.projects.recent.paginate :page => params[:page], :per_page => 30 + @projects = @repository.projects.recent.paginate :page => params[:project_page], :per_page => 30 end end @@ -40,6 +40,50 @@ class RepositoriesController < ApplicationController end end + def add_project + if params[:project_id] + @project = Project.find(params[:project_id]) + params[:project_id] = nil + unless @repository.projects.include? @project + @repository.projects << @project +# if @repository.save + flash[:notice] = t('flash.repository.project_added') + redirect_to platform_repository_path(@repository.platform, @repository) +# else +# flash[:error] = t('flash.repository.project_not_added') +# redirect_to url_for(:action => :add_project) +# end + else + flash[:error] = t('flash.repository.project_not_added') + redirect_to url_for(:action => :add_project) + end + else + @projects = (Project.all - @repository.projects).paginate(:page => params[:project_page]) + render 'projects_list' + end + end + + def remove_project + if params[:project_id] + @project = Project.find(params[:project_id]) + params[:project_id] = nil + if @repository.projects.include? @project + @repository.projects.delete @project +# if @repository.save + flash[:notice] = t('flash.repository.project_removed') + redirect_to platform_repository_path(@repository.platform, @repository) +# else +# flash[:error] = t('flash.repository.project_not_removed') +# redirect_to url_for(:action => :remove_project) +# end + else + redirect_to url_for(:action => :remove_project) + end + else + redirect_to platform_repository_path(@repository.platform, @repository) + end + end + protected def get_paths @@ -61,6 +105,10 @@ class RepositoriesController < ApplicationController end end + def find_platform + @platform = @repository.platform + end + def find_platforms @platforms = Platform.all end diff --git a/app/views/repositories/_proj_list.html.haml b/app/views/repositories/_proj_list.html.haml new file mode 100644 index 000000000..cb3745999 --- /dev/null +++ b/app/views/repositories/_proj_list.html.haml @@ -0,0 +1,11 @@ +%table.table + %tr + %th.first= t("activerecord.attributes.project.name") + %th.last   + - @projects.each do |project| + %tr{:class => cycle("odd", "even")} + %td + = link_to project.owner.name + '/' + project.name, project_path(project) + %td.last + #{link_to t("layout.show"), project_path(project)} | #{link_to t("layout.add"), url_for(:controller => :repositories, :action => :add_project, :project_id => project.id)} + diff --git a/app/views/repositories/_proj_list1.html.haml b/app/views/repositories/_proj_list1.html.haml new file mode 100644 index 000000000..c37d33bf7 --- /dev/null +++ b/app/views/repositories/_proj_list1.html.haml @@ -0,0 +1,10 @@ +%table.table + %tr + %th.first= t("activerecord.attributes.project.name") + %th.last   + - @projects.each do |project| + %tr{:class => cycle("odd", "even")} + %td + = link_to project.name, project_path(project) + %td.last + #{link_to t("layout.show"), project_path(project)} | #{link_to t("layout.delete"), url_for (:action => :remove_project, :project_id => project.id), :confirm => t("layout.projects.confirm_delete")} diff --git a/app/views/repositories/index.html.haml b/app/views/repositories/index.html.haml index 3ee0282ab..00a1677f9 100644 --- a/app/views/repositories/index.html.haml +++ b/app/views/repositories/index.html.haml @@ -2,10 +2,10 @@ .secondary-navigation %ul.wat-cf %li.first.active= link_to t("layout.repositories.list"), repositories_path - %li= link_to t("layout.platforms.new"), new_repository_path + %li= link_to t("layout.repositories.new"), new_repository_path .content %h2.title - = t("layout.platforms.list_header") + = t("layout.repositories.list_header") .inner = render :partial => 'shared/search_form' = render :partial => 'list', :object => @repositories diff --git a/app/views/repositories/projects_list.html.haml b/app/views/repositories/projects_list.html.haml new file mode 100644 index 000000000..ed5120d3c --- /dev/null +++ b/app/views/repositories/projects_list.html.haml @@ -0,0 +1,60 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first= link_to t("layout.repositories.list"), @repositories_path + "#repositories" + %li= link_to t("layout.repositories.new"), @new_repository_path + %li.active= link_to t("layout.repositories.show"), repository_path(@repository) + .content + .inner + %p + %b + = t("activerecord.attributes.repository.name") + \: + = @repository.name + %p + %b + = t("activerecord.attributes.repository.unixname") + \: + = @repository.unixname + %p + %b + = t("activerecord.attributes.repository.platform") + \: + = link_to @repository.platform.name, url_for(@repository.platform) + %p + %b + = t("activerecord.attributes.repository.owner") + \: + = link_to @repository.owner.name, url_for(@repository.owner) + %p + %b + = t("activerecord.attributes.repository.visibility") + \: + = @repository.visibility + %p + %b + = t("activerecord.attributes.repository.platform") + \: + = link_to @repository.platform.name, platform_path(@platform) + .wat-cf + = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") + +%a{ :name => "projects" } +.block + .secondary-navigation + %ul.wat-cf + %li.first= link_to t("layout.projects.list"), repository_path(@repository) + "#projects" + %li.active= link_to t("layout.projects.add"), url_for(:controller => :repositories, :action => :add_project) + .content + %h2.title + = t("layout.projects.list_header") + .inner + = render :partial => 'shared/search_form' + = render :partial => 'proj_list', :object => @projects + .actions-bar.wat-cf + .actions + = will_paginate @projects, :param_name => :project_page + + +-# content_for :sidebar, render(:partial => 'sidebar') + diff --git a/app/views/repositories/show.html.haml b/app/views/repositories/show.html.haml index 1237c8ab7..d96f8b62a 100644 --- a/app/views/repositories/show.html.haml +++ b/app/views/repositories/show.html.haml @@ -1,9 +1,9 @@ .block .secondary-navigation %ul.wat-cf - %li.first= link_to t("layout.repositories.list"), platform_path(@platform) + "#repositories" - %li= link_to t("layout.repositories.new"), new_platform_repository_path(@platform) - %li.active= link_to t("layout.repositories.show"), platform_repository_path(@platform, @repository) + %li.first= link_to t("layout.repositories.list"), @repositories_path + "#repositories" + %li= link_to t("layout.repositories.new"), @new_repository_path + %li.active= link_to t("layout.repositories.show"), repository_path(@repository) .content .inner %p @@ -16,42 +16,44 @@ = t("activerecord.attributes.repository.unixname") \: = @repository.unixname + %p + %b + = t("activerecord.attributes.repository.platform") + \: + = link_to @repository.platform.name, url_for(@repository.platform) + %p + %b + = t("activerecord.attributes.repository.owner") + \: + = link_to @repository.owner.name, url_for(@repository.owner) + %p + %b + = t("activerecord.attributes.repository.visibility") + \: + = @repository.visibility %p %b = t("activerecord.attributes.repository.platform") \: = link_to @repository.platform.name, platform_path(@platform) .wat-cf - = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_repository_path(@platform, @repository), :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") + = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") %a{ :name => "projects" } .block .secondary-navigation %ul.wat-cf - %li.first.active= link_to t("layout.projects.list"), platform_repository_path(@platform, @repository) + "#projects" - %li= link_to t("layout.projects.new"), new_project_path(@platform, @repository) + %li.first.active= link_to t("layout.projects.list"), repository_path(@repository) + "#projects" + %li= link_to t("layout.projects.add"), url_for(:controller => :repositories, :action => :add_project) .content %h2.title = t("layout.projects.list_header") .inner - = form_tag platform_repository_path(@platform, @repository), :method => :get do - .group - = label_tag :query, t("layout.search_by_name"), :class => :label - = text_field_tag :query - %button.search{:type => "submit"} - = t("layout.search") - %table.table - %tr - %th.first= t("activerecord.attributes.project.name") - %th.last   - - @projects.each do |project| - %tr{:class => cycle("odd", "even")} - %td - = link_to project.name, platform_repository_project_path(@platform, @repository, project) - %td.last - #{link_to t("layout.show"), platform_repository_project_path(@platform, @repository, project)} | #{link_to t("layout.delete"), platform_repository_project_path(@platform, @repository, project), :method => :delete, :confirm => t("layout.projects.confirm_delete")} + = render :partial => 'shared/search_form' + = render :partial => 'proj_list1', :object => @projects .actions-bar.wat-cf .actions - = will_paginate @projects + = will_paginate @projects, :param_name => :project_page -- content_for :sidebar, render(:partial => 'sidebar') + +-# content_for :sidebar, render(:partial => 'sidebar') diff --git a/config/initializers/ext.rb b/config/initializers/ext.rb new file mode 100644 index 000000000..26cb643b3 --- /dev/null +++ b/config/initializers/ext.rb @@ -0,0 +1,4 @@ +# Load extensions to existing classes. +Dir["lib/ext/**/*.rb"].each do |fn| + require File.expand_path( fn ) +end diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 40ffe378f..cde7e816e 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -104,6 +104,7 @@ ru: weekdays: Дни недели projects: + add: Добавить list: Список list_header: Проекты show: Проект @@ -208,6 +209,10 @@ ru: saved: Репозиторий успешно добавлен save_error: Не удалось добавить репозиторий destroyed: Репозиторий успешно удален + project_added: Проект добавлен к репозиторию + project_not_added: Не удалось добавить проект + project_removed: Проект удален из репозитория + project_not_removed: Не удалось удалить проект из репозитория product: saved: Продукт успешно сохранен diff --git a/config/routes.rb b/config/routes.rb index 54d8d0a3f..d969fa059 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -67,7 +67,12 @@ Rosa::Application.routes.draw do end end - resources :repositories + resources :repositories do + member do + get :add_project + get :remove_project + end + end resources :users, :groups do resources :platforms, :only => [:new, :create]