增加帖子-组织栏目关联表

This commit is contained in:
ouyangxuhua 2015-12-22 15:48:41 +08:00
parent 188bb0c1a7
commit 2220e0b7cc
10 changed files with 64 additions and 3 deletions

View File

@ -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')

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,5 @@
class OrgSubfieldBoard < ActiveRecord::Base
belongs_to :org_subfield
belongs_to :board
# attr_accessible :title, :body
end

View File

@ -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'

View File

@ -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

View File

@ -0,0 +1,5 @@
class AddBoardTypeToOrgSubfieldBoards < ActiveRecord::Migration
def change
add_column :org_subfield_boards, :board_type, :string
end
end

View File

@ -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

View File

@ -0,0 +1,6 @@
FactoryGirl.define do
factory :org_subfield_board, :class => 'OrgSubfieldBoards' do
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe OrgSubfieldBoards, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end