Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ config :groupher_server, :customization,
sidebar_communities_index: %{}

config :groupher_server, :article,
# NOTE: do not change unless you know what you are doing
article_threads: [:post, :job, :repo],
# NOTE: if you want to add/remove emotion, just edit the list below
# and migrate the field to table "articles_users_emotions"
supported_emotions: [
Expand Down
2 changes: 0 additions & 2 deletions lib/groupher_server/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ defmodule GroupherServer.Application do
@spec start(any, any) :: {:error, any} | {:ok, pid}
def start(_type, _args) do
import Supervisor.Spec
import Cachex.Spec

alias Helper.Cache

# Define workers and child supervisors to be supervised
Expand Down
6 changes: 4 additions & 2 deletions lib/groupher_server/cms/abuse_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ defmodule GroupherServer.CMS.AbuseReport do

use Ecto.Schema
use Accessible

import Ecto.Changeset
import Helper.Utils, only: [get_config: 2]
import GroupherServer.CMS.Helper.Macros
import GroupherServer.CMS.Helper.Utils, only: [articles_foreign_key_constraint: 1]

alias GroupherServer.{Accounts, CMS}
alias CMS.{ArticleComment, Embeds}

@article_threads CMS.Community.article_threads()
@article_threads get_config(:article, :article_threads)

# @required_fields ~w(article_comment_id user_id recived_user_id)a
@optional_fields ~w(article_comment_id account_id operate_user_id deal_with report_cases_count)a
Expand All @@ -31,7 +33,7 @@ defmodule GroupherServer.CMS.AbuseReport do

field(:deal_with, :string)

article_belongs_to()
article_belongs_to_fields()
timestamps(type: :utc_datetime)
end

Expand Down
6 changes: 4 additions & 2 deletions lib/groupher_server/cms/article_collect.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ defmodule GroupherServer.CMS.ArticleCollect do
alias __MODULE__

use Ecto.Schema

import Ecto.Changeset
import Helper.Utils, only: [get_config: 2]
import GroupherServer.CMS.Helper.Macros
import GroupherServer.CMS.Helper.Utils, only: [articles_foreign_key_constraint: 1]

alias GroupherServer.{Accounts, CMS}
alias Accounts.{User, CollectFolder}

@article_threads CMS.Community.article_threads()
@article_threads get_config(:article, :article_threads)

@required_fields ~w(user_id)a
@optional_fields ~w(thread)a
Expand All @@ -23,7 +25,7 @@ defmodule GroupherServer.CMS.ArticleCollect do
belongs_to(:user, User, foreign_key: :user_id)
embeds_many(:collect_folders, CollectFolder, on_replace: :delete)

article_belongs_to()
article_belongs_to_fields()
timestamps(type: :utc_datetime)
end

Expand Down
5 changes: 3 additions & 2 deletions lib/groupher_server/cms/article_comment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ defmodule GroupherServer.CMS.ArticleComment do
use Accessible

import Ecto.Changeset
import Helper.Utils, only: [get_config: 2]
import GroupherServer.CMS.Helper.Macros
import GroupherServer.CMS.Helper.Utils, only: [articles_foreign_key_constraint: 1]

alias GroupherServer.{Accounts, CMS}
alias CMS.{Embeds, ArticleCommentUpvote}

# alias Helper.HTML
@article_threads CMS.Community.article_threads()
@article_threads get_config(:article, :article_threads)

@required_fields ~w(body_html author_id)a
@optional_fields ~w(reply_to_id replies_count is_folded is_deleted floor is_article_author)a
Expand Down Expand Up @@ -77,7 +78,7 @@ defmodule GroupherServer.CMS.ArticleComment do

has_many(:upvotes, {"articles_comments_upvotes", ArticleCommentUpvote})

article_belongs_to()
article_belongs_to_fields()
timestamps(type: :utc_datetime)
end

Expand Down
5 changes: 3 additions & 2 deletions lib/groupher_server/cms/article_pinned_comment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ defmodule GroupherServer.CMS.ArticlePinnedComment do
use Accessible

import Ecto.Changeset
import Helper.Utils, only: [get_config: 2]
import GroupherServer.CMS.Helper.Macros
import GroupherServer.CMS.Helper.Utils, only: [articles_foreign_key_constraint: 1]

alias GroupherServer.CMS
alias CMS.ArticleComment

# alias Helper.HTML
@article_threads CMS.Community.article_threads()
@article_threads get_config(:article, :article_threads)

@required_fields ~w(article_comment_id)a
# @optional_fields ~w(post_id job_id repo_id)a
Expand All @@ -24,7 +25,7 @@ defmodule GroupherServer.CMS.ArticlePinnedComment do
schema "articles_pinned_comments" do
belongs_to(:article_comment, ArticleComment, foreign_key: :article_comment_id)

article_belongs_to()
article_belongs_to_fields()
timestamps(type: :utc_datetime)
end

Expand Down
6 changes: 4 additions & 2 deletions lib/groupher_server/cms/article_upvote.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ defmodule GroupherServer.CMS.ArticleUpvote do
alias __MODULE__

use Ecto.Schema

import Ecto.Changeset
import Helper.Utils, only: [get_config: 2]
import GroupherServer.CMS.Helper.Macros
import GroupherServer.CMS.Helper.Utils, only: [articles_foreign_key_constraint: 1]

alias GroupherServer.{Accounts, CMS}
alias Accounts.User

@article_threads CMS.Community.article_threads()
@article_threads get_config(:article, :article_threads)

@required_fields ~w(user_id)a
@optional_fields ~w(thread)a
Expand All @@ -22,7 +24,7 @@ defmodule GroupherServer.CMS.ArticleUpvote do
field(:thread, :string)
belongs_to(:user, User, foreign_key: :user_id)

article_belongs_to()
article_belongs_to_fields()
timestamps(type: :utc_datetime)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/groupher_server/cms/article_user_emotion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule GroupherServer.CMS.ArticleUserEmotion do
alias GroupherServer.{Accounts, CMS}

@supported_emotions get_config(:article, :supported_emotions)
@article_threads CMS.Community.article_threads()
@article_threads get_config(:article, :article_threads)

@required_fields ~w(user_id recived_user_id)a
@optional_fields Enum.map(@article_threads, &:"#{&1}_id") ++
Expand All @@ -41,7 +41,7 @@ defmodule GroupherServer.CMS.ArticleUserEmotion do
belongs_to(:user, Accounts.User, foreign_key: :user_id)

emotion_fields()
article_belongs_to()
article_belongs_to_fields()
timestamps(type: :utc_datetime)
end

Expand Down
31 changes: 2 additions & 29 deletions lib/groupher_server/cms/community.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@ defmodule GroupherServer.CMS.Community do

use Ecto.Schema
import Ecto.Changeset
import GroupherServer.CMS.Helper.Macros

alias GroupherServer.{Accounts, CMS}

alias CMS.{
Category,
Post,
Repo,
Job,
CommunityThread,
CommunitySubscriber,
CommunityEditor,
CommunityWiki,
CommunityCheatsheet
}

@article_threads [:post, :job, :repo]
@max_pinned_article_count_per_thread 2

@required_fields ~w(title desc user_id logo raw)a
# @required_fields ~w(title desc user_id)a
@optional_fields ~w(label geo_info index aka)a

def article_threads, do: @article_threads
def max_pinned_article_count_per_thread, do: @max_pinned_article_count_per_thread

schema "communities" do
Expand Down Expand Up @@ -59,30 +55,7 @@ defmodule GroupherServer.CMS.Community do
# on_replace: :delete
)

many_to_many(
:posts,
Post,
join_through: "communities_posts",
join_keys: [community_id: :id, post_id: :id]
)

many_to_many(
:repos,
Repo,
join_through: "communities_repos",
join_keys: [community_id: :id, repo_id: :id]
)

many_to_many(
:jobs,
Job,
join_through: "communities_jobs",
join_keys: [community_id: :id, job_id: :id]
)

# posts_managers
# jobs_managers
# tuts_managers
community_article_fields()
#
# posts_block_list ...
timestamps(type: :utc_datetime)
Expand Down
4 changes: 2 additions & 2 deletions lib/groupher_server/cms/delegates/abuse_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
CURD and operations for article comments
"""
import Ecto.Query, warn: false
import Helper.Utils, only: [done: 1, strip_struct: 1]
import Helper.Utils, only: [done: 1, strip_struct: 1, get_config: 2]

import GroupherServer.CMS.Helper.Matcher2
import ShortMaps
Expand All @@ -17,9 +17,9 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do

alias Ecto.Multi

@article_threads get_config(:article, :article_threads)
@report_threshold_for_fold ArticleComment.report_threshold_for_fold()

@article_threads Community.article_threads()
@export_author_keys [:id, :login, :nickname, :avatar]
@export_article_keys [:id, :title, :digest, :upvotes_count, :views]
@export_report_keys [
Expand Down
5 changes: 3 additions & 2 deletions lib/groupher_server/cms/delegates/article_comment_action.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do
CURD and operations for article comments
"""
import Ecto.Query, warn: false
import Helper.Utils, only: [done: 1, strip_struct: 1]
import Helper.Utils, only: [done: 1, strip_struct: 1, get_config: 2]
import Helper.ErrorCode

import GroupherServer.CMS.Delegate.ArticleComment,
Expand All @@ -30,7 +30,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do

alias Ecto.Multi

@article_threads Community.article_threads()
@article_threads get_config(:article, :article_threads)

@max_parent_replies_count ArticleComment.max_parent_replies_count()
@pinned_comment_limit ArticleComment.pinned_comment_limit()

Expand Down
2 changes: 0 additions & 2 deletions lib/groupher_server/cms/embeds/article_meta.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ defmodule GroupherServer.CMS.Embeds.ArticleMeta do
use Accessible
import Ecto.Changeset

alias GroupherServer.CMS

@optional_fields ~w(is_edited is_comment_locked upvoted_user_ids collected_user_ids viewed_user_ids reported_user_ids reported_count)a

@default_meta %{
Expand Down
Loading