souls 0.24.2 → 0.24.6
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/exe/souls +12 -1
- data/lib/souls.rb +54 -0
- data/lib/souls/init.rb +37 -16
- data/lib/souls/version.rb +1 -1
- metadata +16 -191
- data/.gitignore +0 -15
- data/.irbrc +0 -3
- data/.rspec +0 -3
- data/.rubocop.yml +0 -152
- data/.ruby-version +0 -1
- data/.travis.yml +0 -6
- data/Gemfile +0 -13
- data/Gemfile.lock +0 -98
- data/Rakefile +0 -23
- data/Steepfile +0 -8
- data/apps/api/.env.sample +0 -7
- data/apps/api/.gitignore +0 -32
- data/apps/api/.irbrc +0 -4
- data/apps/api/.rspec +0 -3
- data/apps/api/.rubocop.yml +0 -132
- data/apps/api/.ruby-version +0 -1
- data/apps/api/CODE_OF_CONDUCT.md +0 -74
- data/apps/api/Dockerfile +0 -16
- data/apps/api/Dockerfile.dev +0 -17
- data/apps/api/Gemfile +0 -50
- data/apps/api/Gemfile.lock +0 -412
- data/apps/api/LICENSE.txt +0 -67
- data/apps/api/Procfile +0 -2
- data/apps/api/Procfile.dev +0 -2
- data/apps/api/README.md +0 -37
- data/apps/api/Rakefile +0 -5
- data/apps/api/app.rb +0 -114
- data/apps/api/app/engines/notification_engine.rb +0 -5
- data/apps/api/app/graphql/mutations/.keep +0 -0
- data/apps/api/app/graphql/mutations/base/article/create_article.rb +0 -30
- data/apps/api/app/graphql/mutations/base/article/delete_article.rb +0 -17
- data/apps/api/app/graphql/mutations/base/article/destroy_delete_article.rb +0 -17
- data/apps/api/app/graphql/mutations/base/article/update_article.rb +0 -30
- data/apps/api/app/graphql/mutations/base/article_category/create_article_category.rb +0 -21
- data/apps/api/app/graphql/mutations/base/article_category/delete_article_category.rb +0 -17
- data/apps/api/app/graphql/mutations/base/article_category/destroy_delete_article_category.rb +0 -17
- data/apps/api/app/graphql/mutations/base/article_category/update_article_category.rb +0 -21
- data/apps/api/app/graphql/mutations/base/user/create_user.rb +0 -31
- data/apps/api/app/graphql/mutations/base/user/delete_user.rb +0 -17
- data/apps/api/app/graphql/mutations/base/user/destroy_delete_user.rb +0 -17
- data/apps/api/app/graphql/mutations/base/user/update_user.rb +0 -31
- data/apps/api/app/graphql/mutations/base_mutation.rb +0 -65
- data/apps/api/app/graphql/mutations/managers/user_manager/add_user_role.rb +0 -22
- data/apps/api/app/graphql/mutations/managers/user_manager/remove_user_role.rb +0 -22
- data/apps/api/app/graphql/mutations/managers/user_manager/sign_in_user.rb +0 -45
- data/apps/api/app/graphql/queries/article.rb +0 -13
- data/apps/api/app/graphql/queries/article_categories.rb +0 -11
- data/apps/api/app/graphql/queries/article_category.rb +0 -13
- data/apps/api/app/graphql/queries/articles.rb +0 -11
- data/apps/api/app/graphql/queries/base_query.rb +0 -12
- data/apps/api/app/graphql/queries/me.rb +0 -11
- data/apps/api/app/graphql/queries/user.rb +0 -13
- data/apps/api/app/graphql/queries/users.rb +0 -11
- data/apps/api/app/graphql/resolvers/article_category_search.rb +0 -41
- data/apps/api/app/graphql/resolvers/article_search.rb +0 -57
- data/apps/api/app/graphql/resolvers/base.rb +0 -17
- data/apps/api/app/graphql/resolvers/user_search.rb +0 -63
- data/apps/api/app/graphql/souls_api_schema.rb +0 -43
- data/apps/api/app/graphql/types/.keep +0 -0
- data/apps/api/app/graphql/types/article_category_type.rb +0 -12
- data/apps/api/app/graphql/types/article_type.rb +0 -30
- data/apps/api/app/graphql/types/base/base_argument.rb +0 -4
- data/apps/api/app/graphql/types/base/base_enum.rb +0 -4
- data/apps/api/app/graphql/types/base/base_field.rb +0 -5
- data/apps/api/app/graphql/types/base/base_input_object.rb +0 -5
- data/apps/api/app/graphql/types/base/base_interface.rb +0 -7
- data/apps/api/app/graphql/types/base/base_object.rb +0 -6
- data/apps/api/app/graphql/types/base/base_scalar.rb +0 -4
- data/apps/api/app/graphql/types/base/base_union.rb +0 -4
- data/apps/api/app/graphql/types/base/mutation_type.rb +0 -26
- data/apps/api/app/graphql/types/base/query_type.rb +0 -18
- data/apps/api/app/graphql/types/connections/article_category_connection.rb +0 -3
- data/apps/api/app/graphql/types/connections/article_connection.rb +0 -3
- data/apps/api/app/graphql/types/connections/base_connection.rb +0 -14
- data/apps/api/app/graphql/types/connections/user_connection.rb +0 -3
- data/apps/api/app/graphql/types/edges/article_category_edge.rb +0 -5
- data/apps/api/app/graphql/types/edges/article_edge.rb +0 -5
- data/apps/api/app/graphql/types/edges/base_edge.rb +0 -4
- data/apps/api/app/graphql/types/edges/user_edge.rb +0 -5
- data/apps/api/app/graphql/types/user_type.rb +0 -24
- data/apps/api/app/models/article.rb +0 -4
- data/apps/api/app/models/article_category.rb +0 -3
- data/apps/api/app/models/user.rb +0 -19
- data/apps/api/app/policies/application_policy.rb +0 -40
- data/apps/api/app/policies/article_category_policy.rb +0 -31
- data/apps/api/app/policies/article_policy.rb +0 -31
- data/apps/api/app/policies/user_policy.rb +0 -35
- data/apps/api/app/utils/association_loader.rb +0 -50
- data/apps/api/app/utils/fire_store.rb +0 -9
- data/apps/api/app/utils/firebase_id_token.rb +0 -4
- data/apps/api/app/utils/json_web_token.rb +0 -13
- data/apps/api/app/utils/record_loader.rb +0 -10
- data/apps/api/app/utils/souls_helper.rb +0 -18
- data/apps/api/cloudbuild.yml +0 -32
- data/apps/api/config.ru +0 -17
- data/apps/api/config/database.yml +0 -33
- data/apps/api/config/souls.rb +0 -10
- data/apps/api/constants/areas.rb +0 -71
- data/apps/api/constants/column_name_ja.rb +0 -27
- data/apps/api/db/migrate/20200006095538_create_users.rb +0 -30
- data/apps/api/db/migrate/20200712180236_create_article_categories.rb +0 -12
- data/apps/api/db/migrate/20200714215521_create_articles.rb +0 -22
- data/apps/api/db/schema.rb +0 -78
- data/apps/api/db/seeds.rb +0 -44
- data/apps/api/github/workflows/delivery.yml +0 -81
- data/apps/api/log/.keep +0 -0
- data/apps/api/spec/factories/article_categories.rb +0 -9
- data/apps/api/spec/factories/articles.rb +0 -17
- data/apps/api/spec/factories/users.rb +0 -23
- data/apps/api/spec/models/article_category_spec.rb +0 -7
- data/apps/api/spec/models/article_spec.rb +0 -7
- data/apps/api/spec/models/user_spec.rb +0 -7
- data/apps/api/spec/mutations/base/article_category_spec.rb +0 -46
- data/apps/api/spec/mutations/base/article_spec.rb +0 -70
- data/apps/api/spec/mutations/base/user_spec.rb +0 -76
- data/apps/api/spec/policies/article_category_policy_spec.rb +0 -24
- data/apps/api/spec/policies/article_policy_spec.rb +0 -24
- data/apps/api/spec/policies/user_policy_spec.rb +0 -24
- data/apps/api/spec/queries/article_category_spec.rb +0 -39
- data/apps/api/spec/queries/article_spec.rb +0 -53
- data/apps/api/spec/queries/user_spec.rb +0 -59
- data/apps/api/spec/resolvers/article_category_search_spec.rb +0 -54
- data/apps/api/spec/resolvers/article_search_spec.rb +0 -68
- data/apps/api/spec/resolvers/user_search_spec.rb +0 -74
- data/apps/api/spec/spec_helper.rb +0 -110
- data/apps/api/tmp/.keep +0 -0
- data/apps/worker/.env.sample +0 -9
- data/apps/worker/.gitignore +0 -32
- data/apps/worker/.irbrc +0 -4
- data/apps/worker/.rspec +0 -3
- data/apps/worker/.rubocop.yml +0 -132
- data/apps/worker/.ruby-version +0 -1
- data/apps/worker/CODE_OF_CONDUCT.md +0 -74
- data/apps/worker/Dockerfile +0 -16
- data/apps/worker/Dockerfile.dev +0 -17
- data/apps/worker/Gemfile +0 -49
- data/apps/worker/Gemfile.lock +0 -396
- data/apps/worker/LICENSE.txt +0 -67
- data/apps/worker/Procfile +0 -1
- data/apps/worker/Procfile.dev +0 -1
- data/apps/worker/README.md +0 -37
- data/apps/worker/Rakefile +0 -5
- data/apps/worker/app.rb +0 -101
- data/apps/worker/app/engines/notification_engine.rb +0 -5
- data/apps/worker/app/graphql/mutations/.keep +0 -0
- data/apps/worker/app/graphql/mutations/base_mutation.rb +0 -16
- data/apps/worker/app/graphql/mutations/workers/send_user_mail_job.rb +0 -31
- data/apps/worker/app/graphql/souls_api_schema.rb +0 -43
- data/apps/worker/app/graphql/types/.keep +0 -0
- data/apps/worker/app/graphql/types/base/base_argument.rb +0 -4
- data/apps/worker/app/graphql/types/base/base_enum.rb +0 -4
- data/apps/worker/app/graphql/types/base/base_field.rb +0 -5
- data/apps/worker/app/graphql/types/base/base_input_object.rb +0 -5
- data/apps/worker/app/graphql/types/base/base_interface.rb +0 -7
- data/apps/worker/app/graphql/types/base/base_object.rb +0 -5
- data/apps/worker/app/graphql/types/base/base_scalar.rb +0 -4
- data/apps/worker/app/graphql/types/base/base_union.rb +0 -4
- data/apps/worker/app/graphql/types/base/mutation_type.rb +0 -12
- data/apps/worker/app/graphql/types/base/query_type.rb +0 -6
- data/apps/worker/app/models/article.rb +0 -4
- data/apps/worker/app/models/article_category.rb +0 -3
- data/apps/worker/app/models/user.rb +0 -19
- data/apps/worker/app/utils/fire_store.rb +0 -9
- data/apps/worker/app/utils/souls_helper.rb +0 -96
- data/apps/worker/cloudbuild.yml +0 -32
- data/apps/worker/config.ru +0 -17
- data/apps/worker/config/database.yml +0 -33
- data/apps/worker/config/souls.rb +0 -10
- data/apps/worker/db/migrate/20200006095538_create_users.rb +0 -30
- data/apps/worker/db/migrate/20200712180236_create_article_categories.rb +0 -12
- data/apps/worker/db/migrate/20200714215521_create_articles.rb +0 -22
- data/apps/worker/db/schema.rb +0 -78
- data/apps/worker/db/seeds.rb +0 -44
- data/apps/worker/github/workflows/delivery.yml +0 -81
- data/apps/worker/log/.keep +0 -0
- data/apps/worker/spec/factories/article_categories.rb +0 -9
- data/apps/worker/spec/factories/articles.rb +0 -17
- data/apps/worker/spec/factories/users.rb +0 -23
- data/apps/worker/spec/models/article_category_spec.rb +0 -7
- data/apps/worker/spec/models/article_spec.rb +0 -7
- data/apps/worker/spec/models/user_spec.rb +0 -7
- data/apps/worker/spec/spec_helper.rb +0 -110
- data/apps/worker/tmp/.keep +0 -0
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/config/souls.rb +0 -9
- data/db/schema.rb +0 -67
- data/rbs/init.rbs +0 -2
- data/souls.gemspec +0 -34
@@ -1,63 +0,0 @@
|
|
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
|
@@ -1,43 +0,0 @@
|
|
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
|
@@ -1,12 +0,0 @@
|
|
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
|
@@ -1,30 +0,0 @@
|
|
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
|
@@ -1,26 +0,0 @@
|
|
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
|
@@ -1,18 +0,0 @@
|
|
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
|
@@ -1,14 +0,0 @@
|
|
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
|
@@ -1,24 +0,0 @@
|
|
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
|
data/apps/api/app/models/user.rb
DELETED
@@ -1,19 +0,0 @@
|
|
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
|
@@ -1,40 +0,0 @@
|
|
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
|
@@ -1,31 +0,0 @@
|
|
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
|