storytime 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc621908139c9c5e7f34b65fc9ba7dc1bf744814
4
- data.tar.gz: 874adcff7ad44354e9bcafbf9e9334b4fea439c6
3
+ metadata.gz: cf39a31891a15bcee7b10824400ad71d55dada8c
4
+ data.tar.gz: 6827ab5ce70be645b272de46062d7ceaf991f726
5
5
  SHA512:
6
- metadata.gz: f40b232bb112db2fe38d1ba962568976377bcee2b24ea5b67eac98545772d1f3b6359547d1adf0116dbc6142cad1a320c6b0bfbe84079c8bb0c8f044481d68ff
7
- data.tar.gz: cccace1f9505433a4f066c5265781f8ebd6801e7ab90d3c43e0b953d55955beb649bb572a668687ce9382b8d57c5ed4acc17f8e96e06e8e63380f31d0a933a28
6
+ metadata.gz: c3f251310c2b7af9a815b214d7b42df3b458756db96df5868a959c0b43c2ea5f676d5c87f666401014388d9809ba9fe97d00760f2847bc44877af6436f943061
7
+ data.tar.gz: 1cc0d64fee3ab5721d9a32c046a7f54cd211d7bee13de96d64c0da4ecee2f60643e227cffccf4e1155f34b631aa5d3ab9b5b163e4c0f07f582a68a5e95aaf315
@@ -8,6 +8,12 @@ class Storytime::ApplicationController < ApplicationController
8
8
 
9
9
  helper :all
10
10
 
11
+ if Storytime.user_class_symbol != :user
12
+ helper_method :authenticate_user!
13
+ helper_method :current_user
14
+ helper_method :user_signed_in?
15
+ end
16
+
11
17
  def setup
12
18
  url = if Storytime.user_class.count == 0
13
19
  main_app.new_user_registration_url
@@ -22,6 +28,20 @@ class Storytime::ApplicationController < ApplicationController
22
28
  redirect_to url
23
29
  end
24
30
 
31
+ if Storytime.user_class_symbol != :user
32
+ def authenticate_user!
33
+ send("authenticate_#{Storytime.user_class.to_s.downcase}!".to_sym)
34
+ end
35
+
36
+ def current_user
37
+ send("current_#{Storytime.user_class.to_s.downcase}".to_sym)
38
+ end
39
+
40
+ def user_signed_in?
41
+ send("#{Storytime.user_class.to_s.downcase}_signed_in?".to_sym)
42
+ end
43
+ end
44
+
25
45
  private
26
46
  def ensure_site
27
47
  redirect_to new_dashboard_site_url unless devise_controller? || @site = Storytime::Site.first
@@ -10,8 +10,10 @@ module Storytime
10
10
  respond_to :json, only: :destroy
11
11
 
12
12
  def create
13
- @comment = current_user.storytime_comments.new(comment_params)
13
+ @comment = Comment.new(comment_params)
14
+ @comment.user = current_user
14
15
  @comment.post = @post
16
+
15
17
  authorize @comment
16
18
  opts = { notice: I18n.t('flash.comments.create.success') } if @comment.save
17
19
  redirect_to @post, opts
@@ -31,7 +33,7 @@ module Storytime
31
33
  end
32
34
 
33
35
  def comment_params
34
- params.require(:comment).permit(*policy(@comment || current_user.storytime_comments.new).permitted_attributes)
36
+ params.require(:comment).permit(*policy(@comment || Comment.new).permitted_attributes)
35
37
  end
36
38
 
37
39
  end
@@ -17,7 +17,9 @@ module Storytime
17
17
  end
18
18
 
19
19
  def create
20
- @media = current_user.storytime_media.new(media_params)
20
+ @media = Media.new(media_params)
21
+ @media.user = current_user
22
+
21
23
  authorize @media
22
24
  @media.save
23
25
  respond_with :dashboard, @media do |format|
@@ -49,7 +49,7 @@ module Storytime
49
49
 
50
50
  private
51
51
  def user_params
52
- params.require(:user).permit(:email, :storytime_role_id, :storytime_name, :password, :password_confirmation)
52
+ params.require(Storytime.user_class_symbol).permit(:email, :storytime_role_id, :storytime_name, :password, :password_confirmation)
53
53
  end
54
54
 
55
55
  def load_user
@@ -24,7 +24,7 @@ module Storytime
24
24
  def show
25
25
  @post = if params[:preview]
26
26
  post = Post.find_preview(params[:id])
27
- post.content = post.autosave.content if post.autosave
27
+ # post.content = post.autosave.content if post.autosave
28
28
  post.preview = true
29
29
  post
30
30
  else
@@ -1,6 +1,6 @@
1
1
  module Storytime
2
2
  class Autosave < ActiveRecord::Base
3
- belongs_to Storytime.user_class_symbol
3
+ belongs_to :user, class_name: Storytime.user_class.to_s
4
4
  belongs_to :autosavable, polymorphic: true
5
5
 
6
6
  attr_accessor :draft_content
@@ -1,9 +1,9 @@
1
1
  module Storytime
2
2
  class Comment < ActiveRecord::Base
3
- belongs_to Storytime.user_class_symbol
3
+ belongs_to :user, class_name: Storytime.user_class.to_s
4
4
  belongs_to :post
5
5
 
6
- validates Storytime.user_class_symbol, presence: true
6
+ validates :user, presence: true
7
7
  validates :post_id, presence: true
8
8
 
9
9
  def commenter_name
@@ -1,6 +1,6 @@
1
1
  module Storytime
2
2
  class Media < ActiveRecord::Base
3
- belongs_to Storytime.user_class_symbol
3
+ belongs_to :user, class_name: Storytime.user_class.to_s
4
4
  has_many :posts # posts where this is the featured media
5
5
 
6
6
  mount_uploader :file, MediaUploader
@@ -6,7 +6,7 @@ module Storytime
6
6
  extend FriendlyId
7
7
  friendly_id :slug_candidates, use: [:history]
8
8
 
9
- belongs_to Storytime.user_class_symbol
9
+ belongs_to :user, class_name: Storytime.user_class.to_s
10
10
  belongs_to :featured_media, class_name: "Media"
11
11
  belongs_to :secondary_media, class_name: "Media"
12
12
 
@@ -1,6 +1,6 @@
1
1
  module Storytime
2
2
  class Version < ActiveRecord::Base
3
- belongs_to Storytime.user_class_symbol
3
+ belongs_to :user, class_name: Storytime.user_class.to_s
4
4
  belongs_to :versionable, polymorphic: true
5
5
  end
6
6
  end
@@ -27,7 +27,7 @@
27
27
  <% end %>
28
28
 
29
29
  <% if Pundit.policy(current_user, Storytime.user_class).index? %>
30
- <li <%= active_nav_item_class("users") %>><%= link_to "Users", storytime.url_for([:dashboard, Storytime.user_class]) %></li>
30
+ <li <%= active_nav_item_class("users") %>><%= link_to "Users", storytime.url_for([:dashboard, :users]) %></li>
31
31
  <% end %>
32
32
 
33
33
  <% if Pundit.policy(current_user, Storytime::Site).edit? %>
@@ -43,7 +43,7 @@
43
43
  </a>
44
44
  <ul class="dropdown-menu">
45
45
  <li><%= link_to "My Account", storytime.edit_dashboard_user_path(current_user) %></li>
46
- <li><%= link_to "Sign Out", main_app.destroy_user_session_path, method: :delete %></li>
46
+ <li><%= link_to "Sign Out", main_app.send("destroy_#{Storytime.user_class_underscore}_session_path"), method: :delete %></li>
47
47
  </ul>
48
48
  </li>
49
49
  </ul>
@@ -1,11 +1,11 @@
1
- <tr id="user_<%= user.id %>">
1
+ <tr id="<%= Storytime.user_class_underscore %>_<%= user.id %>">
2
2
  <td><%= user.email %></td>
3
3
  <td><%= user.storytime_name %></td>
4
4
  <td><%= user.storytime_role.name.humanize if user.storytime_role %></td>
5
5
  <td class='right'>
6
6
  <div class="btn-group">
7
- <%= link_to t('dashboard.users.edit_user_button'), edit_polymorphic_url([:dashboard, user]), class: "btn btn-xs btn-default" %>
8
- <%= delete_resource_link user, polymorphic_url([:dashboard, user]) unless user == current_user %>
7
+ <%= link_to t('dashboard.users.edit_user_button'), url_for(:controller => 'dashboard/users', :action => 'edit', :id => user.id), class: "btn btn-xs btn-default" %>
8
+ <%= delete_resource_link user, dashboard_user_url(user) unless user == current_user %>
9
9
  </div>
10
10
  </td>
11
11
  </tr>
@@ -1,7 +1,7 @@
1
1
  <div class="container">
2
2
  <h2><%= t('dashboard.users.edit_user_header') %></h2>
3
3
 
4
- <%= simple_form_for [:dashboard, @user] do |f| %>
4
+ <%= simple_form_for @user, :url => dashboard_user_path do |f| %>
5
5
  <%= f.input :email %>
6
6
  <%= f.input :storytime_name %>
7
7
  <%= f.association :storytime_role, include_blank: true, label_method: :label %>
@@ -1,6 +1,7 @@
1
1
  <div class="container">
2
2
  <h2>New User</h2>
3
- <%= simple_form_for [:dashboard, @user] do |f| %>
3
+
4
+ <%= simple_form_for @user, :url => dashboard_users_path, :method => :post do |f| %>
4
5
  <%= f.input :email %>
5
6
  <%= f.association :storytime_role, include_blank: false, label_method: :label %>
6
7
  <%= f.input :password %>
data/config/routes.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  resources :snippets, except: [:show]
11
11
  resources :media, except: [:show, :edit, :update]
12
12
  resources :imports, only: [:new, :create]
13
- resources :users
13
+ resources :users, path: Storytime.user_class_underscore.pluralize
14
14
  resources :roles do
15
15
  collection do
16
16
  patch :update_multiple
@@ -6,6 +6,7 @@ module Storytime
6
6
  module ClassMethods
7
7
  def storytime_user
8
8
  belongs_to :storytime_role, class_name: "Storytime::Role"
9
+
9
10
  has_many :storytime_posts, class_name: "Storytime::Post"
10
11
  has_many :storytime_pages, class_name: "Storytime::Page"
11
12
  has_many :storytime_media, class_name: "Storytime::Media"
@@ -13,6 +14,10 @@ module Storytime
13
14
  has_many :storytime_comments, class_name: "Storytime::Comment"
14
15
 
15
16
  class_eval <<-EOS
17
+ def self.policy_class
18
+ UserPolicy
19
+ end
20
+
16
21
  def storytime_user?
17
22
  !storytime_role.nil?
18
23
  end
@@ -1,3 +1,3 @@
1
1
  module Storytime
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
data/lib/storytime.rb CHANGED
@@ -51,6 +51,10 @@ module Storytime
51
51
  @@user_class.constantize
52
52
  end
53
53
 
54
+ def user_class_underscore
55
+ @@user_class.to_s.underscore
56
+ end
57
+
54
58
  def user_class_symbol
55
59
  @@user_class.underscore.to_sym
56
60
  end
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storytime
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Roesch, David Van Der Beek, Brandon Robins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-24 00:00:00.000000000 Z
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails