Skip to content
Browse files

게시판 관리자를 위한 컨텐츠 ownership을 polymorphic으로 변경

  • Loading branch information...
1 parent 434b8a8 commit f3630c421fed4836228d209fd2ee5d25d68d3db6 @saltfactory saltfactory committed
Showing with 133 additions and 87 deletions.
  1. +12 −12 rails/sshb/Gemfile.lock
  2. +2 −0 rails/sshb/app/assets/javascripts/dashboard.js
  3. +2 −0 rails/sshb/app/assets/javascripts/users.js
  4. +3 −0 rails/sshb/app/assets/stylesheets/dashboard.scss
  5. +1 −0 rails/sshb/app/controllers/articles_controller.rb
  6. +2 −0 rails/sshb/app/controllers/dashboard_controller.rb
  7. +0 −4 rails/sshb/app/controllers/users/registrations_controller.rb
  8. +8 −0 rails/sshb/app/controllers/users_controller.rb
  9. +2 −0 rails/sshb/app/helpers/dashboard_helper.rb
  10. +2 −0 rails/sshb/app/helpers/users_helper.rb
  11. +4 −1 rails/sshb/app/models/board.rb
  12. +0 −5 rails/sshb/app/models/boards_owner.rb
  13. +4 −0 rails/sshb/app/models/ownership.rb
  14. +4 −2 rails/sshb/app/models/user.rb
  15. 0 rails/sshb/app/views/dashboard/index.html.erb
  16. +3 −20 rails/sshb/app/views/{home → layouts}/_header.html.erb
  17. +1 −1 rails/sshb/app/views/layouts/application.html.erb
  18. +1 −4 rails/sshb/app/views/users/registrations/show.html.erb
  19. 0 rails/sshb/app/views/users/show.html.erb
  20. +13 −1 rails/sshb/config/environments/development.rb
  21. +1 −0 rails/sshb/config/initializers/devise.rb
  22. +9 −5 rails/sshb/config/routes.rb
  23. +0 −10 rails/sshb/db/migrate/20160107011130_create_boards_owners.rb
  24. +9 −0 rails/sshb/db/migrate/20160118141512_create_ownerships.rb
  25. +8 −9 rails/sshb/db/schema.rb
  26. +16 −6 rails/sshb/db/seeds.rb
  27. +7 −0 rails/sshb/test/controllers/dashboard_controller_test.rb
  28. +7 −0 rails/sshb/test/controllers/users_controller_test.rb
  29. +0 −6 rails/sshb/test/fixtures/boards_owners.yml
  30. +11 −0 rails/sshb/test/fixtures/ownerships.yml
  31. +1 −1 rails/sshb/test/models/{boards_owner_test.rb → ownership_test.rb}
View
24 rails/sshb/Gemfile.lock
@@ -37,7 +37,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
- autoprefixer-rails (6.2.3)
+ autoprefixer-rails (6.3.0)
execjs
json
bcrypt (3.1.10)
@@ -50,7 +50,7 @@ GEM
byebug (8.2.1)
climate_control (0.0.3)
activesupport (>= 3.0)
- cocaine (0.5.7)
+ cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
@@ -61,7 +61,7 @@ GEM
coffee-script-source (1.10.0)
concurrent-ruby (1.0.0)
debug_inspector (0.0.2)
- devise (3.5.2)
+ devise (3.5.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
@@ -78,7 +78,7 @@ GEM
jbuilder (2.4.0)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
- jquery-rails (4.0.5)
+ jquery-rails (4.1.0)
rails-dom-testing (~> 1.0)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
@@ -98,13 +98,13 @@ GEM
nokogiri (1.6.7.1)
mini_portile2 (~> 2.0.0.rc2)
orm_adapter (0.5.0)
- paperclip (4.3.1)
+ paperclip (4.3.2)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
cocaine (~> 0.5.5)
mime-types
mimemagic (= 0.3.0)
- paperclip-storage-ftp (1.2.6)
+ paperclip-storage-ftp (1.2.7)
paperclip
rack (1.6.4)
rack-test (0.6.3)
@@ -133,12 +133,12 @@ GEM
activesupport (= 4.2.5)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
- rake (10.4.2)
+ rake (10.5.0)
rdoc (4.2.1)
json (~> 1.4)
- responders (2.1.0)
- railties (>= 4.2.0, < 5)
- sass (3.4.20)
+ responders (2.1.1)
+ railties (>= 4.2.0, < 5.1)
+ sass (3.4.21)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
@@ -148,7 +148,7 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
- spring (1.6.1)
+ spring (1.6.2)
sprockets (3.5.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
@@ -167,7 +167,7 @@ GEM
uglifier (2.7.2)
execjs (>= 0.3.0)
json (>= 1.8.0)
- warden (1.2.3)
+ warden (1.2.4)
rack (>= 1.0)
web-console (2.2.1)
activemodel (>= 4.0)
View
2 rails/sshb/app/assets/javascripts/dashboard.js
@@ -0,0 +1,2 @@
+// Place all the behaviors and hooks related to the matching controller here.
+// All this logic will automatically be available in application.js.
View
2 rails/sshb/app/assets/javascripts/users.js
@@ -0,0 +1,2 @@
+// Place all the behaviors and hooks related to the matching controller here.
+// All this logic will automatically be available in application.js.
View
3 rails/sshb/app/assets/stylesheets/dashboard.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the dashboard controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
1 rails/sshb/app/controllers/articles_controller.rb
@@ -2,6 +2,7 @@ class ArticlesController < ApplicationController
before_action :set_article, only: [:show, :edit, :update, :destroy]
before_action :set_board, only: [:index, :new, :edit, :create]
+ before_action :authenticate_user!, except: [:index, :show]
# GET /articles
# GET /articles.json
View
2 rails/sshb/app/controllers/dashboard_controller.rb
@@ -0,0 +1,2 @@
+class DashboardController < ApplicationController
+end
View
4 rails/sshb/app/controllers/users/registrations_controller.rb
@@ -2,10 +2,6 @@ class Users::RegistrationsController < Devise::RegistrationsController
# before_filter :configure_sign_up_params, only: [:create]
# before_filter :configure_account_update_params, only: [:update]
- def show
- @user = current_user
- end
-
# GET /resource/sign_up
# def new
# super
View
8 rails/sshb/app/controllers/users_controller.rb
@@ -0,0 +1,8 @@
+class UsersController < ApplicationController
+
+ before_action :authenticate_user!
+
+ def show
+ @user = current_user
+ end
+end
View
2 rails/sshb/app/helpers/dashboard_helper.rb
@@ -0,0 +1,2 @@
+module DashboardHelper
+end
View
2 rails/sshb/app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
View
5 rails/sshb/app/models/board.rb
@@ -1,5 +1,8 @@
class Board < ActiveRecord::Base
- has_many :boards_owners, autosave: true, dependent: :destroy
+
+ has_many :owners, through: :ownerships, source: :user
+ has_many :ownerships, as: :ownerable
+
has_many :articles
# accepts_nested_attributes_for :boards_owners,
# allow_destroy: true,
View
5 rails/sshb/app/models/boards_owner.rb
@@ -1,5 +0,0 @@
-class BoardsOwner < ActiveRecord::Base
- belongs_to :board
- belongs_to :user
- belongs_to :role
-end
View
4 rails/sshb/app/models/ownership.rb
@@ -0,0 +1,4 @@
+class Ownership < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :ownerable, polymorphic: true
+end
View
6 rails/sshb/app/models/user.rb
@@ -6,14 +6,16 @@ class User < ActiveRecord::Base
has_many :attachments, as: :owner
has_many :photos, as: :attachable
- has_one :photo, as: :attachable
+
# has_many :avatars, through: :attachments, source: :attachable, source_type: 'User'
# has_and_belongs_to_many :boards
# has_many :boadrs, through: :boards_owners
- has_many :boards_owners
+ has_many :boards, through: :ownerships, source: :ownerable, source_type: "Board"
+ has_many :ownerships
+
before_create :set_default_role
View
0 rails/sshb/app/views/dashboard/index.html.erb
No changes.
View
23 rails/sshb/app/views/home/_header.html.erb → ...s/sshb/app/views/layouts/_header.html.erb
@@ -10,32 +10,15 @@
<a class="navbar-brand" href="#">성산한빛교회</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
- <!--<ul class="nav navbar-nav">-->
- <!--<li class="active"><a href="#">Home</a></li>-->
- <!--<li><a href="#">About</a></li>-->
- <!--<li><a href="#">Contact</a></li>-->
- <!--<li class="dropdown">-->
- <!--<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown-->
- <!--<span class="caret"></span></a>-->
- <!--<ul class="dropdown-menu">-->
- <!--<li><a href="#">Action</a></li>-->
- <!--<li><a href="#">Another action</a></li>-->
- <!--<li><a href="#">Something else here</a></li>-->
- <!--<li role="separator" class="divider"></li>-->
- <!--<li class="dropdown-header">Nav header</li>-->
- <!--<li><a href="#">Separated link</a></li>-->
- <!--<li><a href="#">One more separated link</a></li>-->
- <!--</ul>-->
- <!--</li>-->
- <!--</ul>-->
<ul class="nav navbar-nav navbar-right">
<li class="active">
<%= link_to "", root_path %>
</li>
<li><%= link_to "교회소개", page_about_path %></li>
- <li><%= link_to "교회소식", '/boards/notice' %></li>
+ <li><%= link_to "설교말씀", '/boards/sermons' %></li>
+ <li><%= link_to "교회소식", '/boards/informs' %></li>
<% if user_signed_in? %>
- <li><%= link_to "내 정보", user_root_path %></li>
+ <li><%= link_to "내 정보", profile_path %></li>
<li><%= link_to "로그아웃", destroy_user_session_path, method: :delete %></li>
<% else %>
<li><%= link_to "로그인", new_user_session_path %></li>
View
2 rails/sshb/app/views/layouts/application.html.erb
@@ -21,7 +21,7 @@
<body>
-<%= render "home/header" %>
+<%= render "layouts/header" %>
<div class="container">
<%= yield %>
</div>
View
5 rails/sshb/app/views/users/registrations/show.html.erb
@@ -1,12 +1,9 @@
<div class="profile">
<p class="text-center">
- <%= image_tag resource.avatar, size: "100", class: ["img-circle", "img-responsive"] %>
+ <%= image_tag resource, size: "100", class: ["img-circle", "img-responsive"] %>
</p>
</div>
-
-
-
<p>
이메일(아이디) : <%= resource.email %>
</p>
View
0 rails/sshb/app/views/users/show.html.erb
No changes.
View
14 rails/sshb/config/environments/development.rb
@@ -1,5 +1,7 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
+ secrets_file = Rails.root.join('config', 'secrets.yml')
+ SECRETS = YAML::load_file(secrets_file)[Rails.env] rescue {}
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
@@ -15,7 +17,17 @@
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
- config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
+ config.action_mailer.default_url_options = {:host => 'localhost:3000'}
+ config.action_mailer.delivery_method = :smtp
+ config.action_mailer.default :charset => "utf-8"
+ config.action_mailer.smtp_settings = {
+ :address => 'smtp.gmail.com',
+ :port => 587,
+ :authentication => :login,
+ :enable_startssl_auto => true,
+ :user_name => SECRETS['smtp_username'],
+ :password => SECRETS['smtp_password']
+ }
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
View
1 rails/sshb/config/initializers/devise.rb
@@ -8,6 +8,7 @@
# by default. You can change it below and use your own secret key.
# config.secret_key = '6d615fc4a29b7ed3b3ea5650d389a7dab78b9ef9d39819f4859b98930e8c0f30c43ca7504a84fcb3e4b9311e66fa71ff4a8676999dd257122b2a18e6a31462bc'
+
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class
View
14 rails/sshb/config/routes.rb
@@ -3,7 +3,7 @@
get 'page/welcome'
get 'page/about'
- devise_for :users
+
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
@@ -11,15 +11,19 @@
# root 'welcome#index'
root 'home#index'
+ get '/dashboard' => 'dashboard#index'
+
# match 'user/show' => 'users#show', via: 'get'
# devise_for :users, controllers: {
# sessions: 'users/sessions'
# }
+ devise_for :users
+ # devise_scope :user do
+ # get 'users/profile', :to => 'users#show', :as => :user_root
+ # end
- as :user do
- get 'users/profile', :to => 'users/registrations#show', :as => :user_root
- end
-
+ get '/profile' => 'users#show', as: "profile"
+ resources :users
resources :attachments
View
10 rails/sshb/db/migrate/20160107011130_create_boards_owners.rb
@@ -1,10 +0,0 @@
-class CreateBoardsOwners < ActiveRecord::Migration
- def change
- create_table :boards_owners do |t|
- t.belongs_to :board, index: true
- t.belongs_to :role, index: true
- t.belongs_to :user, index: true
- t.timestamps null: false
- end
- end
-end
View
9 rails/sshb/db/migrate/20160118141512_create_ownerships.rb
@@ -0,0 +1,9 @@
+class CreateOwnerships < ActiveRecord::Migration
+ def change
+ create_table :ownerships do |t|
+ t.references :user, index: true, foreign_key: true
+ t.references :ownerable, polymorphic: true, index: true
+ t.timestamps null: false
+ end
+ end
+end
View
17 rails/sshb/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20160108063459) do
+ActiveRecord::Schema.define(version: 20160118141512) do
create_table "articles", force: :cascade do |t|
t.string "subject"
@@ -61,17 +61,16 @@
t.datetime "updated_at", null: false
end
- create_table "boards_owners", force: :cascade do |t|
- t.integer "board_id"
- t.integer "role_id"
+ create_table "ownerships", force: :cascade do |t|
t.integer "user_id"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.integer "ownerable_id"
+ t.string "ownerable_type"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
- add_index "boards_owners", ["board_id"], name: "index_boards_owners_on_board_id"
- add_index "boards_owners", ["role_id"], name: "index_boards_owners_on_role_id"
- add_index "boards_owners", ["user_id"], name: "index_boards_owners_on_user_id"
+ add_index "ownerships", ["ownerable_type", "ownerable_id"], name: "index_ownerships_on_ownerable_type_and_ownerable_id"
+ add_index "ownerships", ["user_id"], name: "index_ownerships_on_user_id"
create_table "roles", force: :cascade do |t|
t.string "name"
View
22 rails/sshb/db/seeds.rb
@@ -24,10 +24,20 @@
user.avatar = "http://blog.saltfactory.net/assets/images/profile.jpeg"
end
-['noticeboard'].each do |name|
- Board.find_or_create_by({name: name, uuid: SecureRandom.uuid, slug: "notice" })
+['sermons', 'informs'].each do |name|
+ Board.find_or_create_by({name: name}) do |board|
+ board.uuid = SecureRandom.uuid
+ board.slug = name
+ board.owners << User.first
+ end
+end
+#
+# # BoardsOwner.find_or_create_by({user: User.first, board: Board.first, role: Role.find_by_name("admin")})
+#
+#
+Article.find_or_create_by({id: 1}) do |article|
+ article.author = User.first
+ article.board = Board.find_by_slug("informs")
+ article.subject = "test"
+ article.content = "test"
end
-
-
-BoardsOwner.find_or_create_by({user: User.first, board: Board.first, role: Role.find_by_name("admin")})
-
View
7 rails/sshb/test/controllers/dashboard_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class DashboardControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
7 rails/sshb/test/controllers/users_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class UsersControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
6 rails/sshb/test/fixtures/boards_owners.yml
@@ -1,6 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
-
-one:
- board_id: 1
- user_id: 1
- role_id: 4
View
11 rails/sshb/test/fixtures/ownerships.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ user_id:
+ ownerable_id:
+ ownerable_type: Ownerable
+
+two:
+ user_id:
+ ownerable_id:
+ ownerable_type: Ownerable
View
2 rails/sshb/test/models/boards_owner_test.rb → rails/sshb/test/models/ownership_test.rb
@@ -1,6 +1,6 @@
require 'test_helper'
-class BoardsOwnerTest < ActiveSupport::TestCase
+class OwnershipTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end

0 comments on commit f3630c4

Please sign in to comment.
Something went wrong with that request. Please try again.