diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 0c3236d4e..291593fc5 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -18,8 +18,8 @@ class BoardsController < ApplicationController layout 'base_projects'#by young default_search_scope :messages - before_filter :find_project_by_project_id, :find_board_if_available - before_filter :authorize, :except => [:new, :show, :create, :index] + before_filter :find_project_by_project_id, :find_board_if_available, :except => [:join_to_org_subfields] + before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields] accept_rss_auth :index, :show @@ -225,6 +225,16 @@ class BoardsController < ApplicationController redirect_to_settings_in_projects end + def join_to_org_subfields + if params[:id] + @board = Board.find(params[:id]) + @org_subfield_ids = params[:org_subfield_ids] + @org_subfield_ids.each do |id| + OrgSubfieldBoard.create(:org_subfield_id => id.to_i, :board_id => params[:id].to_i) + end + end + end + private def redirect_to_settings_in_projects redirect_to settings_project_url(@project, :tab => 'boards') diff --git a/app/models/board.rb b/app/models/board.rb index 67d59e599..ba1fae30a 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -19,6 +19,8 @@ class Board < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project,:touch => true belongs_to :course,:touch=>true + has_many :org_subfield_boards + has_many :org_subfields, :class_name => "OrgSubfield", :through => :org_subfield_boards has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC" has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC" belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index f95bb3eba..062226e0e 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -2,6 +2,8 @@ class OrgSubfield < ActiveRecord::Base belongs_to :organization, :foreign_key => :organization_id has_many :org_document_comments, :dependent => :destroy has_many :files + has_many :org_subfield_boards + has_many :boards, :through => :org_subfield_boards acts_as_attachable def project diff --git a/app/models/org_subfield_board.rb b/app/models/org_subfield_board.rb new file mode 100644 index 000000000..ac820e319 --- /dev/null +++ b/app/models/org_subfield_board.rb @@ -0,0 +1,5 @@ +class OrgSubfieldBoard < ActiveRecord::Base + belongs_to :org_subfield + belongs_to :board + # attr_accessible :title, :body +end diff --git a/config/routes.rb b/config/routes.rb index 4121639c0..da04f63f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -406,6 +406,7 @@ RedmineApp::Application.routes.draw do # boards match 'boards/:board_id/topics/new', :to => 'messages#new', :via => [:get, :post], :as => 'new_board_message' + match 'boards/:id/join_to_org_subfields', :to => 'boards#join_to_org_subfields' get 'boards/:board_id/topics/:id', :to => 'messages#show', :as => 'board_message' match 'boards/:board_id/topics/quote/:id', :to => 'messages#quote', :via => [:get, :post] get 'boards/:board_id/topics/:id/edit', :to => 'messages#edit' diff --git a/db/migrate/20151221023622_create_org_subfield_boards.rb b/db/migrate/20151221023622_create_org_subfield_boards.rb new file mode 100644 index 000000000..06f6f2f17 --- /dev/null +++ b/db/migrate/20151221023622_create_org_subfield_boards.rb @@ -0,0 +1,13 @@ +class CreateTableOrgSubfieldBoards < ActiveRecord::Migration + def up + create_table :org_subfield_boards do |t| + t.integer :org_subfield_id + t.integer :board_id + t.timestamps + end + end + + def down + drop_table :org_subfield_boards + end +end diff --git a/db/migrate/20151222072758_add_board_type_to_org_subfield_boards.rb b/db/migrate/20151222072758_add_board_type_to_org_subfield_boards.rb new file mode 100644 index 000000000..d53f9952f --- /dev/null +++ b/db/migrate/20151222072758_add_board_type_to_org_subfield_boards.rb @@ -0,0 +1,5 @@ +class AddBoardTypeToOrgSubfieldBoards < ActiveRecord::Migration + def change + add_column :org_subfield_boards, :board_type, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 8e946c493..f2c61ac5f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151218110033) do +ActiveRecord::Schema.define(:version => 20151222072758) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1196,6 +1196,14 @@ ActiveRecord::Schema.define(:version => 20151218110033) do t.datetime "created_at" end + create_table "org_subfield_boards", :force => true do |t| + t.integer "org_subfield_id" + t.integer "board_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "board_type" + end + create_table "org_subfields", :force => true do |t| t.integer "organization_id" t.integer "priority" @@ -1634,6 +1642,10 @@ ActiveRecord::Schema.define(:version => 20151218110033) do t.string "extra" end + create_table "temp", :id => false, :force => true do |t| + t.integer "id", :default => 0, :null => false + end + create_table "time_entries", :force => true do |t| t.integer "project_id", :null => false t.integer "user_id", :null => false diff --git a/spec/factories/org_subfield_boards.rb b/spec/factories/org_subfield_boards.rb new file mode 100644 index 000000000..0af4bc0d3 --- /dev/null +++ b/spec/factories/org_subfield_boards.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :org_subfield_board, :class => 'OrgSubfieldBoards' do + + end + +end diff --git a/spec/models/org_subfield_boards_spec.rb b/spec/models/org_subfield_boards_spec.rb new file mode 100644 index 000000000..9a011c015 --- /dev/null +++ b/spec/models/org_subfield_boards_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe OrgSubfieldBoards, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end