souls 0.24.0 → 0.24.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile.lock +1 -1
- data/api_v0.0.1.tar.gz +0 -0
- data/apps/api/.env.sample +7 -0
- data/apps/api/.gitignore +32 -0
- data/apps/api/.irbrc +1 -0
- data/apps/api/.rspec +3 -0
- data/apps/api/.rubocop.yml +132 -0
- data/apps/api/.ruby-version +1 -0
- data/apps/api/CODE_OF_CONDUCT.md +74 -0
- data/apps/api/Dockerfile +16 -0
- data/apps/api/Dockerfile.dev +17 -0
- data/apps/api/Gemfile +50 -0
- data/apps/api/Gemfile.lock +412 -0
- data/apps/api/LICENSE.txt +67 -0
- data/apps/api/Procfile +2 -0
- data/apps/api/Procfile.dev +2 -0
- data/apps/api/README.md +37 -0
- data/apps/api/Rakefile +5 -0
- data/apps/api/app.rb +114 -0
- data/apps/api/app/engines/notification_engine.rb +5 -0
- data/apps/api/app/graphql/mutations/.keep +0 -0
- data/apps/api/app/graphql/mutations/base/article/create_article.rb +30 -0
- data/apps/api/app/graphql/mutations/base/article/delete_article.rb +17 -0
- data/apps/api/app/graphql/mutations/base/article/destroy_delete_article.rb +17 -0
- data/apps/api/app/graphql/mutations/base/article/update_article.rb +30 -0
- data/apps/api/app/graphql/mutations/base/article_category/create_article_category.rb +21 -0
- data/apps/api/app/graphql/mutations/base/article_category/delete_article_category.rb +17 -0
- data/apps/api/app/graphql/mutations/base/article_category/destroy_delete_article_category.rb +17 -0
- data/apps/api/app/graphql/mutations/base/article_category/update_article_category.rb +21 -0
- data/apps/api/app/graphql/mutations/base/user/create_user.rb +31 -0
- data/apps/api/app/graphql/mutations/base/user/delete_user.rb +17 -0
- data/apps/api/app/graphql/mutations/base/user/destroy_delete_user.rb +17 -0
- data/apps/api/app/graphql/mutations/base/user/update_user.rb +31 -0
- data/apps/api/app/graphql/mutations/base_mutation.rb +65 -0
- data/apps/api/app/graphql/mutations/managers/user_manager/add_user_role.rb +22 -0
- data/apps/api/app/graphql/mutations/managers/user_manager/remove_user_role.rb +22 -0
- data/apps/api/app/graphql/mutations/managers/user_manager/sign_in_user.rb +45 -0
- data/apps/api/app/graphql/queries/article.rb +13 -0
- data/apps/api/app/graphql/queries/article_categories.rb +11 -0
- data/apps/api/app/graphql/queries/article_category.rb +13 -0
- data/apps/api/app/graphql/queries/articles.rb +11 -0
- data/apps/api/app/graphql/queries/base_query.rb +12 -0
- data/apps/api/app/graphql/queries/me.rb +11 -0
- data/apps/api/app/graphql/queries/user.rb +13 -0
- data/apps/api/app/graphql/queries/users.rb +11 -0
- data/apps/api/app/graphql/resolvers/article_category_search.rb +41 -0
- data/apps/api/app/graphql/resolvers/article_search.rb +57 -0
- data/apps/api/app/graphql/resolvers/base.rb +17 -0
- data/apps/api/app/graphql/resolvers/user_search.rb +63 -0
- data/apps/api/app/graphql/souls_api_schema.rb +43 -0
- data/apps/api/app/graphql/types/.keep +0 -0
- data/apps/api/app/graphql/types/article_category_type.rb +12 -0
- data/apps/api/app/graphql/types/article_type.rb +30 -0
- data/apps/api/app/graphql/types/base/base_argument.rb +4 -0
- data/apps/api/app/graphql/types/base/base_enum.rb +4 -0
- data/apps/api/app/graphql/types/base/base_field.rb +5 -0
- data/apps/api/app/graphql/types/base/base_input_object.rb +5 -0
- data/apps/api/app/graphql/types/base/base_interface.rb +7 -0
- data/apps/api/app/graphql/types/base/base_object.rb +6 -0
- data/apps/api/app/graphql/types/base/base_scalar.rb +4 -0
- data/apps/api/app/graphql/types/base/base_union.rb +4 -0
- data/apps/api/app/graphql/types/base/mutation_type.rb +26 -0
- data/apps/api/app/graphql/types/base/query_type.rb +18 -0
- data/apps/api/app/graphql/types/connections/article_category_connection.rb +3 -0
- data/apps/api/app/graphql/types/connections/article_connection.rb +3 -0
- data/apps/api/app/graphql/types/connections/base_connection.rb +14 -0
- data/apps/api/app/graphql/types/connections/user_connection.rb +3 -0
- data/apps/api/app/graphql/types/edges/article_category_edge.rb +5 -0
- data/apps/api/app/graphql/types/edges/article_edge.rb +5 -0
- data/apps/api/app/graphql/types/edges/base_edge.rb +4 -0
- data/apps/api/app/graphql/types/edges/user_edge.rb +5 -0
- data/apps/api/app/graphql/types/user_type.rb +24 -0
- data/apps/api/app/models/article.rb +4 -0
- data/apps/api/app/models/article_category.rb +3 -0
- data/apps/api/app/models/user.rb +19 -0
- data/apps/api/app/policies/application_policy.rb +40 -0
- data/apps/api/app/policies/article_category_policy.rb +31 -0
- data/apps/api/app/policies/article_policy.rb +31 -0
- data/apps/api/app/policies/user_policy.rb +35 -0
- data/apps/api/app/utils/association_loader.rb +50 -0
- data/apps/api/app/utils/fire_store.rb +9 -0
- data/apps/api/app/utils/firebase_id_token.rb +4 -0
- data/apps/api/app/utils/json_web_token.rb +13 -0
- data/apps/api/app/utils/record_loader.rb +10 -0
- data/apps/api/app/utils/souls_helper.rb +18 -0
- data/apps/api/cloudbuild.yml +32 -0
- data/apps/api/config.ru +17 -0
- data/apps/api/config/database.yml +33 -0
- data/apps/api/config/souls.rb +10 -0
- data/apps/api/constants/areas.rb +71 -0
- data/apps/api/constants/column_name_ja.rb +27 -0
- data/apps/api/db/migrate/20200006095538_create_users.rb +30 -0
- data/apps/api/db/migrate/20200712180236_create_article_categories.rb +12 -0
- data/apps/api/db/migrate/20200714215521_create_articles.rb +22 -0
- data/apps/api/db/schema.rb +78 -0
- data/apps/api/db/seeds.rb +44 -0
- data/apps/api/github/workflows/delivery.yml +81 -0
- data/apps/api/log/.keep +0 -0
- data/apps/api/spec/factories/article_categories.rb +9 -0
- data/apps/api/spec/factories/articles.rb +17 -0
- data/apps/api/spec/factories/users.rb +23 -0
- data/apps/api/spec/models/article_category_spec.rb +7 -0
- data/apps/api/spec/models/article_spec.rb +7 -0
- data/apps/api/spec/models/user_spec.rb +7 -0
- data/apps/api/spec/mutations/base/article_category_spec.rb +46 -0
- data/apps/api/spec/mutations/base/article_spec.rb +70 -0
- data/apps/api/spec/mutations/base/user_spec.rb +76 -0
- data/apps/api/spec/policies/article_category_policy_spec.rb +25 -0
- data/apps/api/spec/policies/article_policy_spec.rb +25 -0
- data/apps/api/spec/policies/user_policy_spec.rb +5 -0
- data/apps/api/spec/queries/article_category_spec.rb +39 -0
- data/apps/api/spec/queries/article_spec.rb +53 -0
- data/apps/api/spec/queries/user_spec.rb +59 -0
- data/apps/api/spec/resolvers/article_category_search_spec.rb +54 -0
- data/apps/api/spec/resolvers/article_search_spec.rb +68 -0
- data/apps/api/spec/resolvers/user_search_spec.rb +74 -0
- data/apps/api/spec/spec_helper.rb +110 -0
- data/apps/api/tmp/.keep +0 -0
- data/apps/worker/.env.sample +9 -0
- data/apps/worker/.gitignore +32 -0
- data/apps/worker/.irbrc +1 -0
- data/apps/worker/.rspec +3 -0
- data/apps/worker/.rubocop.yml +132 -0
- data/apps/worker/.ruby-version +1 -0
- data/apps/worker/CODE_OF_CONDUCT.md +74 -0
- data/apps/worker/Dockerfile +16 -0
- data/apps/worker/Dockerfile.dev +17 -0
- data/apps/worker/Gemfile +49 -0
- data/apps/worker/Gemfile.lock +396 -0
- data/apps/worker/LICENSE.txt +67 -0
- data/apps/worker/Procfile +1 -0
- data/apps/worker/Procfile.dev +1 -0
- data/apps/worker/README.md +37 -0
- data/apps/worker/Rakefile +5 -0
- data/apps/worker/app.rb +101 -0
- data/apps/worker/app/engines/notification_engine.rb +5 -0
- data/apps/worker/app/graphql/mutations/.keep +0 -0
- data/apps/worker/app/graphql/mutations/base_mutation.rb +16 -0
- data/apps/worker/app/graphql/mutations/workers/send_user_mail_job.rb +31 -0
- data/apps/worker/app/graphql/souls_api_schema.rb +43 -0
- data/apps/worker/app/graphql/types/.keep +0 -0
- data/apps/worker/app/graphql/types/base/base_argument.rb +4 -0
- data/apps/worker/app/graphql/types/base/base_enum.rb +4 -0
- data/apps/worker/app/graphql/types/base/base_field.rb +5 -0
- data/apps/worker/app/graphql/types/base/base_input_object.rb +5 -0
- data/apps/worker/app/graphql/types/base/base_interface.rb +7 -0
- data/apps/worker/app/graphql/types/base/base_object.rb +5 -0
- data/apps/worker/app/graphql/types/base/base_scalar.rb +4 -0
- data/apps/worker/app/graphql/types/base/base_union.rb +4 -0
- data/apps/worker/app/graphql/types/base/mutation_type.rb +12 -0
- data/apps/worker/app/graphql/types/base/query_type.rb +6 -0
- data/apps/worker/app/models/article.rb +4 -0
- data/apps/worker/app/models/article_category.rb +3 -0
- data/apps/worker/app/models/user.rb +19 -0
- data/apps/worker/app/utils/fire_store.rb +9 -0
- data/apps/worker/app/utils/souls_helper.rb +96 -0
- data/apps/worker/cloudbuild.yml +32 -0
- data/apps/worker/config.ru +17 -0
- data/apps/worker/config/database.yml +33 -0
- data/apps/worker/config/souls.rb +10 -0
- data/apps/worker/db/migrate/20200006095538_create_users.rb +30 -0
- data/apps/worker/db/migrate/20200712180236_create_article_categories.rb +12 -0
- data/apps/worker/db/migrate/20200714215521_create_articles.rb +22 -0
- data/apps/worker/db/schema.rb +78 -0
- data/apps/worker/db/seeds.rb +44 -0
- data/apps/worker/github/workflows/delivery.yml +81 -0
- data/apps/worker/log/.keep +0 -0
- data/apps/worker/spec/factories/article_categories.rb +9 -0
- data/apps/worker/spec/factories/articles.rb +17 -0
- data/apps/worker/spec/factories/users.rb +23 -0
- data/apps/worker/spec/models/article_category_spec.rb +7 -0
- data/apps/worker/spec/models/article_spec.rb +7 -0
- data/apps/worker/spec/models/user_spec.rb +7 -0
- data/apps/worker/spec/spec_helper.rb +110 -0
- data/apps/worker/tmp/.keep +0 -0
- data/exe/souls +0 -2
- data/lib/souls.rb +0 -18
- data/lib/souls/init.rb +1 -1
- data/lib/souls/version.rb +1 -1
- data/souls_api2.tar.gz +0 -0
- metadata +176 -1
@@ -0,0 +1,63 @@
|
|
1
|
+
module Resolvers
|
2
|
+
class UserSearch < Base
|
3
|
+
include SearchObject.module(:graphql)
|
4
|
+
scope { ::User.all }
|
5
|
+
type Types::UserType.connection_type, null: false
|
6
|
+
description "Search User"
|
7
|
+
|
8
|
+
class UserFilter < ::Types::BaseInputObject
|
9
|
+
argument :OR, [self], required: false
|
10
|
+
argument :birthday, String, required: false
|
11
|
+
argument :email, String, required: false
|
12
|
+
argument :end_date, String, required: false
|
13
|
+
argument :first_name, String, required: false
|
14
|
+
argument :first_name_kana, String, required: false
|
15
|
+
argument :first_name_kanji, String, required: false
|
16
|
+
argument :icon_url, String, required: false
|
17
|
+
argument :is_deleted, Boolean, required: false
|
18
|
+
argument :last_name, String, required: false
|
19
|
+
argument :last_name_kana, String, required: false
|
20
|
+
argument :last_name_kanji, String, required: false
|
21
|
+
argument :screen_name, String, required: false
|
22
|
+
argument :start_date, String, required: false
|
23
|
+
argument :tel, String, required: false
|
24
|
+
argument :uid, String, required: false
|
25
|
+
argument :username, String, required: false
|
26
|
+
end
|
27
|
+
|
28
|
+
option :filter, type: UserFilter, with: :apply_filter
|
29
|
+
option :first, type: types.Int, with: :apply_first
|
30
|
+
option :skip, type: types.Int, with: :apply_skip
|
31
|
+
|
32
|
+
def apply_filter(scope, value)
|
33
|
+
branches = normalize_filters(value).inject { |acc, elem| acc.or(elem) }
|
34
|
+
scope.merge(branches)
|
35
|
+
end
|
36
|
+
|
37
|
+
def normalize_filters(value, branches = [])
|
38
|
+
scope = ::User.all
|
39
|
+
scope = scope.where(uid: value[:uid]) if value[:uid]
|
40
|
+
scope = scope.where(username: value[:username]) if value[:username]
|
41
|
+
scope = scope.where(screen_name: value[:screen_name]) if value[:screen_name]
|
42
|
+
scope = scope.where(last_name: value[:last_name]) if value[:last_name]
|
43
|
+
scope = scope.where(first_name: value[:first_name]) if value[:first_name]
|
44
|
+
scope = scope.where(last_name_kanji: value[:last_name_kanji]) if value[:last_name_kanji]
|
45
|
+
scope = scope.where(first_name_kanji: value[:first_name_kanji]) if value[:first_name_kanji]
|
46
|
+
scope = scope.where(last_name_kana: value[:last_name_kana]) if value[:last_name_kana]
|
47
|
+
scope = scope.where(first_name_kana: value[:first_name_kana]) if value[:first_name_kana]
|
48
|
+
scope = scope.where(email: value[:email]) if value[:email]
|
49
|
+
scope = scope.where(tel: value[:tel]) if value[:tel]
|
50
|
+
scope = scope.where(icon_url: value[:icon_url]) if value[:icon_url]
|
51
|
+
scope = scope.where(birthday: value[:birthday]) if value[:birthday]
|
52
|
+
scope = scope.where(is_deleted: value[:is_deleted]) unless value[:is_deleted].nil?
|
53
|
+
scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
|
54
|
+
scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
|
55
|
+
|
56
|
+
branches << scope
|
57
|
+
|
58
|
+
value[:OR].inject(branches) { |acc, elem| normalize_filters(elem, acc) } if value[:OR].present?
|
59
|
+
|
60
|
+
branches
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class SoulsApiSchema < GraphQL::Schema
|
2
|
+
default_max_page_size 100
|
3
|
+
mutation(Types::MutationType)
|
4
|
+
query(Types::QueryType)
|
5
|
+
use GraphQL::Batch
|
6
|
+
|
7
|
+
def self.id_from_object(object, _type_definition, _query_ctx)
|
8
|
+
# Call your application"s UUID method here
|
9
|
+
# It should return a string
|
10
|
+
to_global_id(object.class.name, object.id)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.object_from_id(id, _query_ctx)
|
14
|
+
class_name, item_id = from_global_id(id)
|
15
|
+
|
16
|
+
# "Post" => Post.find(item_id)
|
17
|
+
Object.const_get(class_name).find(item_id)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.resolve_type(_type, obj, _ctx)
|
21
|
+
case obj
|
22
|
+
when Article
|
23
|
+
Types::ArticleType
|
24
|
+
when User
|
25
|
+
Types::UserType
|
26
|
+
when ArticleCategory
|
27
|
+
Types::ArticleCategoryType
|
28
|
+
when JobConsole
|
29
|
+
Types::JobConsoleType
|
30
|
+
else
|
31
|
+
GraphQL::ExecutionError.new("Unexpected object: #{obj}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.to_global_id(class_name, item_id)
|
36
|
+
Base64.strict_encode64("#{class_name}:#{item_id}")
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.from_global_id(global_id)
|
40
|
+
token = Base64.decode64(global_id)
|
41
|
+
token.split(":")
|
42
|
+
end
|
43
|
+
end
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Types
|
2
|
+
class ArticleCategoryType < BaseObject
|
3
|
+
implements GraphQL::Types::Relay::Node
|
4
|
+
|
5
|
+
global_id_field :id
|
6
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
7
|
+
field :is_deleted, Boolean, null: true
|
8
|
+
field :name, String, null: true
|
9
|
+
field :tags, [String], null: true
|
10
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Types
|
2
|
+
class ArticleType < BaseObject
|
3
|
+
implements GraphQL::Types::Relay::Node
|
4
|
+
|
5
|
+
global_id_field :id
|
6
|
+
field :article_category, Types::ArticleCategoryType, null: false
|
7
|
+
field :body, String, null: true
|
8
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
9
|
+
field :is_deleted, Boolean, null: true
|
10
|
+
field :is_public, Boolean, null: true
|
11
|
+
field :just_created, Boolean, null: true
|
12
|
+
field :public_date, GraphQL::Types::ISO8601DateTime, null: true
|
13
|
+
field :slag, String, null: true
|
14
|
+
field :tags, [String], null: true
|
15
|
+
field :thumnail_url, String, null: true
|
16
|
+
field :title, String, null: true
|
17
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
18
|
+
field :user, Types::UserType, null: false
|
19
|
+
|
20
|
+
unless ENV["RACK_ENV"] == "test"
|
21
|
+
def user
|
22
|
+
RecordLoader.for(User).load(object.user_id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def article_category
|
26
|
+
RecordLoader.for(ArticleCategory).load(object.article_category_id)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Types
|
2
|
+
class MutationType < Types::BaseObject
|
3
|
+
SoulsHelper.get_tables.each do |t|
|
4
|
+
%w[create update delete destroy_delete].each do |a|
|
5
|
+
field "#{a}_#{t.singularize.underscore}".to_sym,
|
6
|
+
mutation: Object.const_get(
|
7
|
+
"Mutations::Base::#{t.singularize.camelize}::#{a.camelize}#{t.singularize.camelize}"
|
8
|
+
)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
managers =
|
13
|
+
Dir["./app/graphql/mutations/managers/*_manager/*.rb"].map do |file|
|
14
|
+
{
|
15
|
+
class: file.match(%r{managers/(.+?)_manager})[1],
|
16
|
+
name: file.match(%r{/([^/]+)/?$})[1].gsub(".rb", "")
|
17
|
+
}
|
18
|
+
end
|
19
|
+
managers.each do |file|
|
20
|
+
field file[:name].underscore.to_s.to_sym,
|
21
|
+
mutation: Object.const_get(
|
22
|
+
"Mutations::Managers::#{file[:class].singularize.camelize}Manager::#{file[:name].singularize.camelize}"
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Types
|
2
|
+
class QueryType < Types::BaseObject
|
3
|
+
add_field(GraphQL::Types::Relay::NodeField)
|
4
|
+
add_field(GraphQL::Types::Relay::NodesField)
|
5
|
+
SoulsHelper.get_tables.each do |t|
|
6
|
+
field t.singularize.underscore.to_s.to_sym, resolver: Object.const_get("Queries::#{t.singularize.camelize}")
|
7
|
+
field "#{t.singularize.underscore}_search".to_sym,
|
8
|
+
resolver: Object.const_get("Resolvers::#{t.singularize.camelize}Search")
|
9
|
+
field t.pluralize.underscore.to_s.to_sym,
|
10
|
+
Object.const_get("Types::#{t.singularize.camelize}Type").connection_type,
|
11
|
+
null: true
|
12
|
+
define_method t do
|
13
|
+
Object.const_get(t.singularize.camelize.to_s).all.order(id: :desc)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
field :me, resolver: Queries::Me
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Types
|
2
|
+
class BaseConnection < GraphQL::Types::Relay::BaseConnection
|
3
|
+
field :total_count, Integer, null: false
|
4
|
+
field :total_pages, Integer, null: false
|
5
|
+
|
6
|
+
def total_count
|
7
|
+
object.items.size
|
8
|
+
end
|
9
|
+
|
10
|
+
def total_pages
|
11
|
+
total_count / object.max_page_size + 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Types
|
2
|
+
class UserType < BaseObject
|
3
|
+
implements GraphQL::Types::Relay::Node
|
4
|
+
|
5
|
+
global_id_field :id
|
6
|
+
field :birthday, String, null: true
|
7
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
8
|
+
field :email, String, null: true
|
9
|
+
field :first_name, String, null: true
|
10
|
+
field :first_name_kana, String, null: true
|
11
|
+
field :first_name_kanji, String, null: true
|
12
|
+
field :icon_url, String, null: true
|
13
|
+
field :last_name, String, null: true
|
14
|
+
field :last_name_kana, String, null: true
|
15
|
+
field :last_name_kanji, String, null: true
|
16
|
+
field :roles, String, null: true
|
17
|
+
field :roles_mask, Integer, null: true
|
18
|
+
field :screen_name, String, null: true
|
19
|
+
field :tel, String, null: true
|
20
|
+
field :uid, String, null: true
|
21
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
22
|
+
field :username, String, null: true
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
include RoleModel
|
3
|
+
has_many :article
|
4
|
+
|
5
|
+
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
6
|
+
private_constant :VALID_EMAIL_REGEX
|
7
|
+
validates :email, presence: true, uniqueness: true, format: { with: VALID_EMAIL_REGEX }
|
8
|
+
|
9
|
+
roles :normal, :user, :admin, :master
|
10
|
+
|
11
|
+
before_create :assign_initial_roles
|
12
|
+
|
13
|
+
# Scope
|
14
|
+
default_scope -> { order(created_at: :desc) }
|
15
|
+
|
16
|
+
def assign_initial_roles
|
17
|
+
roles << [:normal]
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class ApplicationPolicy
|
2
|
+
attr_reader :user, :record
|
3
|
+
|
4
|
+
def initialize(user, record)
|
5
|
+
@user = user
|
6
|
+
@record = record
|
7
|
+
end
|
8
|
+
|
9
|
+
def index?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def show?
|
14
|
+
scope.where(id: record.id).exists?
|
15
|
+
end
|
16
|
+
|
17
|
+
def create?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def new?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def update?
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
def edit?
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy?
|
34
|
+
@user.master?
|
35
|
+
end
|
36
|
+
|
37
|
+
def scope
|
38
|
+
Pundit.policy_scope!(user, record.class)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class ArticleCategoryPolicy < ApplicationPolicy
|
2
|
+
def show?
|
3
|
+
true
|
4
|
+
end
|
5
|
+
|
6
|
+
def index?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def create?
|
11
|
+
user_permissions?
|
12
|
+
end
|
13
|
+
|
14
|
+
def update?
|
15
|
+
user_permissions?
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete?
|
19
|
+
admin_permissions?
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def user_permissions?
|
25
|
+
@user.master? or @user.admin? or @user.user?
|
26
|
+
end
|
27
|
+
|
28
|
+
def admin_permissions?
|
29
|
+
@user.master? or @user.admin?
|
30
|
+
end
|
31
|
+
end
|