notee 0.3.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/notee/application.js +40107 -38738
- data/app/controllers/notee/application_controller.rb +22 -2
- data/app/controllers/notee/categories_controller.rb +3 -4
- data/app/controllers/notee/comments_controller.rb +34 -11
- data/app/controllers/notee/images_controller.rb +3 -4
- data/app/controllers/notee/notees_controller.rb +2 -4
- data/app/controllers/notee/posts_controller.rb +10 -11
- data/app/controllers/notee/roles_controller.rb +27 -0
- data/app/controllers/notee/statuses_controller.rb +3 -5
- data/app/controllers/notee/tokens_controller.rb +1 -5
- data/app/controllers/notee/users_controller.rb +19 -12
- data/app/models/notee/application_record.rb +5 -0
- data/app/models/notee/category.rb +14 -4
- data/app/models/notee/comment.rb +1 -1
- data/app/models/notee/image.rb +12 -3
- data/app/models/notee/post.rb +28 -2
- data/app/models/notee/token.rb +15 -2
- data/app/models/notee/user.rb +71 -24
- data/app/views/notee/partials/_meta.html.erb +25 -0
- data/config/routes.rb +11 -9
- data/db/migrate/20160809145754_create_notee_users.rb +0 -1
- data/lib/notee/configuration.rb +15 -1
- data/lib/notee/helpers/notee_helper.rb +9 -0
- data/lib/notee/helpers/view_helper.rb +6 -1
- data/lib/notee/version.rb +1 -1
- data/lib/tasks/notee_tasks.rake +16 -0
- data/test/dummy/log/development.log +63 -0
- metadata +20 -8
- data/app/helpers/notee/categories_helper.rb +0 -4
- data/app/helpers/notee/comments_helper.rb +0 -4
- data/app/helpers/notee/images_helper.rb +0 -4
- data/app/helpers/notee/posts_helper.rb +0 -4
@@ -2,13 +2,33 @@ module Notee
|
|
2
2
|
class ApplicationController < ActionController::Base
|
3
3
|
before_action :restrict_access_json
|
4
4
|
|
5
|
+
def restrict_access_json
|
6
|
+
return redirect_to new_token_path unless confirm_exist_token
|
7
|
+
return redirect_to new_token_path unless confirm_expired_token
|
8
|
+
end
|
9
|
+
|
5
10
|
private
|
6
11
|
|
7
|
-
def
|
12
|
+
def confirm_exist_token
|
8
13
|
unless Token.exists?(access_token: session[:access_token])
|
9
|
-
|
14
|
+
session.delete(:access_token)
|
15
|
+
return false
|
10
16
|
end
|
17
|
+
|
18
|
+
true
|
11
19
|
end
|
12
20
|
|
21
|
+
def confirm_expired_token
|
22
|
+
token = Token.find_by(access_token: session[:access_token])
|
23
|
+
return false unless token
|
24
|
+
|
25
|
+
if Time.now > token.expires_at
|
26
|
+
token.destroy
|
27
|
+
session.delete(:access_token)
|
28
|
+
return false
|
29
|
+
end
|
30
|
+
|
31
|
+
true
|
32
|
+
end
|
13
33
|
end
|
14
34
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require_dependency
|
2
|
+
require_dependency 'notee/application_controller'
|
3
3
|
|
4
4
|
module Notee
|
5
5
|
class CategoriesController < ApplicationController
|
@@ -7,11 +7,11 @@ module Notee
|
|
7
7
|
|
8
8
|
def index
|
9
9
|
@categories = Category.all
|
10
|
-
render json: { status: 'success', categories: @categories}
|
10
|
+
render json: { status: 'success', categories: @categories }
|
11
11
|
end
|
12
12
|
|
13
13
|
def show
|
14
|
-
render json: { status: 'success', category: @category}
|
14
|
+
render json: { status: 'success', category: @category }
|
15
15
|
end
|
16
16
|
|
17
17
|
def create
|
@@ -54,6 +54,5 @@ module Notee
|
|
54
54
|
def set_category
|
55
55
|
@category = Category.find_by(id: params[:id])
|
56
56
|
end
|
57
|
-
|
58
57
|
end
|
59
58
|
end
|
@@ -1,29 +1,52 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency 'notee/application_controller'
|
2
2
|
|
3
3
|
module Notee
|
4
4
|
class CommentsController < ApplicationController
|
5
|
+
before_action :set_comment, only: [:update, :destroy]
|
6
|
+
|
7
|
+
def index
|
8
|
+
comments = Comment.all.order(updated_at: :desc)
|
9
|
+
render json: { status: 'success', comments: comments }
|
10
|
+
end
|
5
11
|
|
6
12
|
def show
|
7
|
-
@comments = Comment.where(post_id: params[:id])
|
8
|
-
render json: { status: 'success', comments: @comments}
|
13
|
+
@comments = Comment.where(post_id: params[:id])
|
14
|
+
render json: { status: 'success', comments: @comments }
|
9
15
|
end
|
10
16
|
|
11
|
-
# POST /comments
|
12
17
|
def create
|
13
18
|
@comment = Comment.new(comment_params)
|
14
|
-
|
15
19
|
if @comment.save
|
16
|
-
render json: { status: 'success'}
|
20
|
+
render json: { status: 'success' }
|
17
21
|
else
|
18
|
-
render json: { status: 'failed'}
|
22
|
+
render json: { status: 'failed' }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def update
|
27
|
+
respond_to do |format|
|
28
|
+
if @comment.update(post_params)
|
29
|
+
format.json { render json: @comment, status: 200 }
|
30
|
+
else
|
31
|
+
format.json { render json: @comment.errors, status: :unprocessable_entity }
|
32
|
+
end
|
19
33
|
end
|
20
34
|
end
|
21
35
|
|
36
|
+
def destroy
|
37
|
+
@comment.destroy
|
38
|
+
render json: { status: 'success' }
|
39
|
+
end
|
40
|
+
|
22
41
|
private
|
23
42
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
43
|
+
def set_comment
|
44
|
+
@comment = Comment.find_by(id: params[:id])
|
45
|
+
end
|
46
|
+
|
47
|
+
# Only allow a trusted parameter "white list" through.
|
48
|
+
def comment_params
|
49
|
+
params.require(:comment).permit(:post_id, :content, :name, :email)
|
50
|
+
end
|
28
51
|
end
|
29
52
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
|
2
|
-
require_dependency
|
2
|
+
require_dependency 'notee/application_controller'
|
3
3
|
|
4
4
|
module Notee
|
5
5
|
class ImagesController < ApplicationController
|
6
6
|
|
7
7
|
def index
|
8
8
|
@images = Image.all.order(updated_at: :desc)
|
9
|
-
render json: { status: 'success', images: @images}
|
9
|
+
render json: { status: 'success', images: @images }
|
10
10
|
end
|
11
11
|
|
12
12
|
def show
|
13
13
|
@image = Image.find_by(content: params[:search_txt].to_s) if params[:search_txt]
|
14
14
|
@image = Image.find_by(id: params[:search_txt].to_i) if params[:search_txt] && !@image
|
15
|
-
render json: { status: 'success', image: @image}
|
15
|
+
render json: { status: 'success', image: @image }
|
16
16
|
end
|
17
17
|
|
18
18
|
def create
|
@@ -44,6 +44,5 @@ module Notee
|
|
44
44
|
def image_params
|
45
45
|
params.require(:image).permit(:title, :content, :slug, :status, :image_id, :thumbnail_id, :published_at, :seo_keyword, :seo_description)
|
46
46
|
end
|
47
|
-
|
48
47
|
end
|
49
48
|
end
|
@@ -1,8 +1,7 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency 'notee/application_controller'
|
2
2
|
|
3
3
|
module Notee
|
4
4
|
class NoteesController < ApplicationController
|
5
|
-
|
6
5
|
# callbacks
|
7
6
|
skip_before_action :restrict_access_json, only: [:index]
|
8
7
|
before_action :restrict_access, only: [:index]
|
@@ -18,9 +17,8 @@ module Notee
|
|
18
17
|
# end
|
19
18
|
|
20
19
|
unless Token.exists?(access_token: session[:access_token])
|
21
|
-
redirect_to new_token_path
|
20
|
+
redirect_to new_token_path
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
@@ -1,15 +1,14 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency 'notee/application_controller'
|
2
2
|
|
3
3
|
module Notee
|
4
4
|
class PostsController < ApplicationController
|
5
|
-
|
6
5
|
# callbacks
|
7
6
|
before_action :set_post, only: [:show, :update, :destroy]
|
8
7
|
|
9
8
|
# GET /posts
|
10
9
|
def index
|
11
10
|
@posts = Post.all.order(updated_at: :desc)
|
12
|
-
render json: { status: 'success', posts: @posts}
|
11
|
+
render json: { status: 'success', posts: @posts }
|
13
12
|
end
|
14
13
|
|
15
14
|
# GET /posts/1
|
@@ -43,18 +42,18 @@ module Notee
|
|
43
42
|
# DELETE /posts/1
|
44
43
|
def destroy
|
45
44
|
@post.destroy
|
46
|
-
render json: { status: 'success'}
|
45
|
+
render json: { status: 'success' }
|
47
46
|
end
|
48
47
|
|
49
48
|
private
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def set_post
|
51
|
+
@post = Post.find_by(id: params[:id])
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
# Only allow a trusted parameter "white list" through.
|
55
|
+
def post_params
|
56
|
+
params.require(:post).permit(:title, :content, :slug, :status, :category_id, :thumbnail_id, :published_at, :seo_keyword, :seo_description, :secret_published_password)
|
57
|
+
end
|
59
58
|
end
|
60
59
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
require_dependency 'notee/application_controller'
|
3
|
+
|
4
|
+
module Notee
|
5
|
+
class RolesController < ApplicationController
|
6
|
+
def index
|
7
|
+
render json: { status: 'success', roles: User.roles }
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
user = find_user_by_access_token
|
12
|
+
|
13
|
+
if user
|
14
|
+
render json: { status: 'success', user: user }
|
15
|
+
else
|
16
|
+
render json: { status: 'failed' }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def find_user_by_access_token
|
23
|
+
token = Token.find_by(access_token: session[:access_token])
|
24
|
+
token.user
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,19 +1,17 @@
|
|
1
1
|
|
2
|
-
require_dependency
|
2
|
+
require_dependency 'notee/application_controller'
|
3
3
|
|
4
4
|
module Notee
|
5
5
|
class StatusesController < ApplicationController
|
6
|
-
|
7
6
|
def index
|
8
7
|
@statuses = Notee::STATUS
|
9
|
-
render json: { status: 'success', statuses: @statuses}
|
8
|
+
render json: { status: 'success', statuses: @statuses }
|
10
9
|
end
|
11
10
|
|
12
11
|
def show
|
13
12
|
statuses = Notee::STATUS
|
14
13
|
@status = statuses.key(params[:status].to_i)
|
15
|
-
render json: { status: 'success', name: @status}
|
14
|
+
render json: { status: 'success', name: @status }
|
16
15
|
end
|
17
|
-
|
18
16
|
end
|
19
17
|
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
|
2
|
-
require_dependency
|
2
|
+
require_dependency 'notee/application_controller'
|
3
3
|
|
4
4
|
module Notee
|
5
5
|
class TokensController < ApplicationController
|
6
6
|
skip_before_filter :restrict_access_json, only: [:new, :create]
|
7
7
|
|
8
|
-
# GET /tokens/new
|
9
8
|
def new
|
10
9
|
end
|
11
10
|
|
12
|
-
# POST /tokens
|
13
11
|
def create
|
14
12
|
if Notee.notee_id == params[:id] && Notee.notee_password == params[:password]
|
15
13
|
if token = Token.create!
|
@@ -27,11 +25,9 @@ module Notee
|
|
27
25
|
redirect_to root_path
|
28
26
|
end
|
29
27
|
|
30
|
-
# DELETE /tokens/1
|
31
28
|
def destroy
|
32
29
|
Token.find_by_access_token(session[:access_token]).destroy!
|
33
30
|
session.delete(:access_token)
|
34
31
|
end
|
35
|
-
|
36
32
|
end
|
37
33
|
end
|
@@ -1,25 +1,27 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
require_dependency 'notee/application_controller'
|
2
3
|
|
3
4
|
module Notee
|
4
5
|
class UsersController < ApplicationController
|
5
|
-
|
6
6
|
# callbacks
|
7
7
|
before_action :set_user, only: [:show, :update, :destroy]
|
8
|
+
before_action :convert_from_string_to_int, only: [:create, :update]
|
8
9
|
|
9
10
|
# GET /users
|
10
11
|
def index
|
11
12
|
@users = User.all.order(updated_at: :desc)
|
12
|
-
render json: { status: 'success', users: @users}
|
13
|
+
render json: { status: 'success', users: @users }
|
13
14
|
end
|
14
15
|
|
15
16
|
# GET /posts/1
|
16
17
|
def show
|
17
|
-
render json: { status: 'success', user: @user}
|
18
|
+
render json: { status: 'success', user: @user }
|
18
19
|
end
|
19
20
|
|
20
21
|
# POST /posts
|
21
22
|
def create
|
22
23
|
@user = User.new(user_params)
|
24
|
+
@user.file = user_params[:profile_img]
|
23
25
|
respond_to do |format|
|
24
26
|
if @user.save
|
25
27
|
format.json { render json: @user, status: 200 }
|
@@ -31,6 +33,7 @@ module Notee
|
|
31
33
|
|
32
34
|
# PATCH/PUT /posts/1
|
33
35
|
def update
|
36
|
+
@user.file = user_params[:profile_img]
|
34
37
|
respond_to do |format|
|
35
38
|
if @user.update(user_params)
|
36
39
|
format.json { render json: @user, status: 200 }
|
@@ -43,18 +46,22 @@ module Notee
|
|
43
46
|
# DELETE /posts/1
|
44
47
|
def destroy
|
45
48
|
@user.destroy
|
46
|
-
render json: { status: 'success'}
|
49
|
+
render json: { status: 'success' }
|
47
50
|
end
|
48
51
|
|
49
52
|
private
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
def set_user
|
55
|
+
@user = User.find_by(id: params[:id])
|
56
|
+
end
|
54
57
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
58
|
+
def convert_from_string_to_int
|
59
|
+
params[:user][:role] = params[:user][:role].to_i
|
60
|
+
end
|
61
|
+
|
62
|
+
# Only allow a trusted parameter "white list" through.
|
63
|
+
def user_params
|
64
|
+
params.require(:user).permit(:name, :email, :password, :password_confirm, :profile, :profile_img, :role)
|
65
|
+
end
|
59
66
|
end
|
60
67
|
end
|
@@ -1,13 +1,24 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: notee_categories
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# name :string default("category_name"), not null
|
7
|
+
# slug :string default("2016-19-26-54"), not null
|
8
|
+
# parent_id :integer
|
9
|
+
# status :integer default(0), not null
|
10
|
+
# created_at :datetime not null
|
11
|
+
# updated_at :datetime not null
|
12
|
+
#
|
13
|
+
|
1
14
|
module Notee
|
2
15
|
class Category < ActiveRecord::Base
|
3
|
-
|
4
16
|
# callbacks
|
5
17
|
before_save :set_slug
|
6
18
|
before_destroy :protect_default
|
7
19
|
|
8
20
|
# relations
|
9
|
-
has_many :children, class_name: Notee::Category, :
|
10
|
-
|
21
|
+
has_many :children, class_name: Notee::Category, foreign_key: 'parent_id', dependent: :destroy
|
11
22
|
|
12
23
|
private
|
13
24
|
|
@@ -18,6 +29,5 @@ module Notee
|
|
18
29
|
def protect_default
|
19
30
|
return false if self.id == 1
|
20
31
|
end
|
21
|
-
|
22
32
|
end
|
23
33
|
end
|
data/app/models/notee/comment.rb
CHANGED
data/app/models/notee/image.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: notee_images
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# content :string not null
|
7
|
+
# created_at :datetime not null
|
8
|
+
# updated_at :datetime not null
|
9
|
+
#
|
10
|
+
|
1
11
|
require 'securerandom'
|
2
12
|
|
3
13
|
module Notee
|
4
14
|
class Image < ActiveRecord::Base
|
5
|
-
|
6
15
|
# accessors
|
7
16
|
attr_accessor :file
|
8
17
|
|
@@ -11,13 +20,14 @@ module Notee
|
|
11
20
|
before_destroy :protect_default
|
12
21
|
|
13
22
|
private
|
23
|
+
|
14
24
|
def manage_image
|
15
25
|
return unless self.file
|
16
26
|
|
17
27
|
image_dir = Rails.root.to_s + "/public/notee"
|
18
28
|
FileUtils.mkdir_p(image_dir) unless FileTest.exist?(image_dir)
|
19
29
|
image_name = Time.now.strftime('%Y%m%d%H%M%S') + '--' + SecureRandom.uuid + '.jpg'
|
20
|
-
|
30
|
+
transaction do
|
21
31
|
open(image_dir + "/" + image_name, 'wb') do |output|
|
22
32
|
output.write(self.file.read)
|
23
33
|
end
|
@@ -28,6 +38,5 @@ module Notee
|
|
28
38
|
def protect_default
|
29
39
|
return false if self.id == 1
|
30
40
|
end
|
31
|
-
|
32
41
|
end
|
33
42
|
end
|