This repository was archived by the owner on Nov 8, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork20
feat(works-thread): basic workflow#414
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
12 commits Select commitHold shift + click to select a range
3661262
chore: remove warning
mydearxym2e3b9ce
chore(works): create migrate tables
mydearxymd4f67f0
chore(works): basic setup & test
mydearxym59e6f8b
chore(works): missing type
mydearxymd6157ad
chore(works): missing schema
mydearxym823b7f3
chore(works): plural issue
mydearxym3e5047c
chore(works): plural issue
mydearxym0afb2c9
chore(works): tests
mydearxym4e0aa9f
chore(works): pural issue
mydearxymf50cfc6
chore(works): meta thread fix
mydearxym29b6eac
chore(works): adjust article_queries macros
mydearxym9bdf37f
chore(works): fix test
mydearxymFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
5 changes: 3 additions & 2 deletionsconfig/config.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionlib/groupher_server/cms/delegates/hooks/cite.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionlib/groupher_server/cms/delegates/hooks/mention.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionslib/groupher_server/cms/helper/macros.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletionslib/groupher_server/cms/models/works.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
defmodule GroupherServer.CMS.Model.Works do | ||
@moduledoc false | ||
alias __MODULE__ | ||
use Ecto.Schema | ||
use Accessible | ||
import Ecto.Changeset | ||
import GroupherServer.CMS.Helper.Macros | ||
alias GroupherServer.CMS | ||
alias CMS.Model.Embeds | ||
@timestamps_opts [type: :utc_datetime_usec] | ||
@required_fields ~w(title digest)a | ||
@article_cast_fields general_article_cast_fields() | ||
@optional_fields @article_cast_fields | ||
@type t :: %Works{} | ||
schema "cms_works" do | ||
article_tags_field(:works) | ||
article_communities_field(:works) | ||
general_article_fields(:works) | ||
end | ||
@doc false | ||
def changeset(%Works{} = works, attrs) do | ||
works | ||
|> cast(attrs, @optional_fields ++ @required_fields) | ||
|> validate_required(@required_fields) | ||
|> cast_embed(:meta, required: false, with: &Embeds.ArticleMeta.changeset/2) | ||
|> generl_changeset | ||
end | ||
@doc false | ||
def update_changeset(%Works{} = works, attrs) do | ||
works | ||
|> cast(attrs, @optional_fields ++ @required_fields) | ||
|> generl_changeset | ||
end | ||
defp generl_changeset(changeset) do | ||
changeset | ||
|> validate_length(:title, min: 3, max: 50) | ||
|> cast_embed(:emotions, with: &Embeds.ArticleEmotion.changeset/2) | ||
end | ||
end |
47 changes: 47 additions & 0 deletionslib/groupher_server/cms/models/works_document.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
defmodule GroupherServer.CMS.Model.WorksDocument do | ||
@moduledoc """ | ||
mainly for full-text search | ||
""" | ||
alias __MODULE__ | ||
use Ecto.Schema | ||
use Accessible | ||
import Ecto.Changeset | ||
import Helper.Utils, only: [get_config: 2] | ||
alias GroupherServer.CMS | ||
alias CMS.Model.Works | ||
@timestamps_opts [type: :utc_datetime_usec] | ||
@max_body_length get_config(:article, :max_length) | ||
@min_body_length get_config(:article, :min_length) | ||
@required_fields ~w(body body_html works_id)a | ||
@optional_fields [] | ||
@type t :: %WorksDocument{} | ||
schema "works_documents" do | ||
belongs_to(:works, Works, foreign_key: :works_id) | ||
field(:body, :string) | ||
field(:body_html, :string) | ||
field(:toc, :map) | ||
end | ||
@doc false | ||
def changeset(%WorksDocument{} = works, attrs) do | ||
works | ||
|> cast(attrs, @optional_fields ++ @required_fields) | ||
|> validate_required(@required_fields) | ||
|> validate_length(:body, min: @min_body_length, max: @max_body_length) | ||
end | ||
@doc false | ||
def update_changeset(%WorksDocument{} = works, attrs) do | ||
works | ||
|> cast(attrs, @optional_fields ++ @required_fields) | ||
|> validate_length(:body, min: @min_body_length, max: @max_body_length) | ||
end | ||
end |
4 changes: 2 additions & 2 deletionslib/groupher_server_web/schema/Helper/objects.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
42 changes: 23 additions & 19 deletionslib/groupher_server_web/schema/Helper/queries.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletionslib/groupher_server_web/schema/cms/cms_metrics.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletionslib/groupher_server_web/schema/cms/cms_queries.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletionslib/groupher_server_web/schema/cms/cms_types.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletionslib/groupher_server_web/schema/cms/mutations/blog.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletionslib/groupher_server_web/schema/cms/mutations/works.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
defmodule GroupherServerWeb.Schema.CMS.Mutations.Works do | ||
@moduledoc """ | ||
CMS mutations for works | ||
""" | ||
use Helper.GqlSchemaSuite | ||
import GroupherServerWeb.Schema.Helper.Mutations | ||
object :cms_works_mutations do | ||
@desc "create a works" | ||
field :create_works, :works do | ||
arg(:title, non_null(:string)) | ||
arg(:body, non_null(:string)) | ||
arg(:digest, non_null(:string)) | ||
arg(:community_id, non_null(:id)) | ||
arg(:thread, :thread, default_value: :works) | ||
arg(:article_tags, list_of(:id)) | ||
middleware(M.Authorize, :login) | ||
middleware(M.PublishThrottle) | ||
resolve(&R.CMS.create_article/3) | ||
middleware(M.Statistics.MakeContribute, for: [:user, :community]) | ||
end | ||
@desc "update a cms/works" | ||
field :update_works, :works do | ||
arg(:id, non_null(:id)) | ||
arg(:title, :string) | ||
arg(:body, :string) | ||
arg(:digest, :string) | ||
arg(:article_tags, list_of(:id)) | ||
# ... | ||
middleware(M.Authorize, :login) | ||
middleware(M.PassportLoader, source: :works) | ||
middleware(M.Passport, claim: "owner;cms->c?->works.edit") | ||
resolve(&R.CMS.update_article/3) | ||
end | ||
############# | ||
article_upvote_mutation(:works) | ||
article_pin_mutation(:works) | ||
article_mark_delete_mutation(:works) | ||
article_delete_mutation(:works) | ||
article_emotion_mutation(:works) | ||
article_report_mutation(:works) | ||
article_sink_mutation(:works) | ||
article_lock_comment_mutation(:works) | ||
############# | ||
end | ||
end |
6 changes: 6 additions & 0 deletionslib/helper/utils/utils.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.