Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit89759cc

Browse files
committed
feat: add archive flag for comments
1 parent3cd6403 commit89759cc

File tree

17 files changed

+150
-24
lines changed

17 files changed

+150
-24
lines changed

‎lib/groupher_server/cms/cms.ex‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ defmodule GroupherServer.CMS do
153153
defdelegatemark_comment_solution(comment,user),to:CommentCurd
154154
defdelegateundo_mark_comment_solution(comment,user),to:CommentCurd
155155

156+
defdelegatearchive_comments(),to:CommentCurd
157+
156158
defdelegateupvote_comment(comment_id,user),to:CommentAction
157159
defdelegateundo_upvote_comment(comment_id,user),to:CommentAction
158160
defdelegatereply_comment(comment_id,args,user),to:CommentAction

‎lib/groupher_server/cms/delegates/comment_curd.ex‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
33
CURD and operations for article comments
44
"""
55
importEcto.Query,warn:false
6-
importHelper.Utils,only:[done:1,ensure:2]
6+
importHelper.Utils,only:[done:1,ensure:2,get_config:2]
77
importHelper.ErrorCode
88

99
importGroupherServer.CMS.Delegate.Helper,
@@ -31,6 +31,8 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
3131
@default_comment_metaEmbeds.CommentMeta.default_meta()
3232
@pinned_comment_limitComment.pinned_comment_limit()
3333

34+
@archive_thresholdget_config(:article,:archive_threshold)
35+
3436
@doc"""
3537
[timeline-mode] list paged article comments
3638
"""
@@ -171,6 +173,9 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
171173
notarticle_meta.is_comment_locked
172174
end
173175

176+
defupdate_comment(%{is_archived:true},_body),
177+
do:raise_error(:archived,"comment is archived, can not be edit or delete")
178+
174179
@doc"""
175180
update a comment for article like psot, job ...
176181
"""
@@ -247,6 +252,9 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
247252

248253
defbatch_update_question_flag(_),do:{:ok,:pass}
249254

255+
defdelete_comment(%{is_archived:true}),
256+
do:raise_error(:archived,"article is archived, can not be edit or delete")
257+
250258
@doc"delete article comment"
251259
defdelete_comment(%Comment{}=comment)do
252260
Multi.new()
@@ -322,6 +330,21 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
322330
end
323331
end
324332

333+
@doc"""
334+
archive comments
335+
called every day by scheuler job
336+
"""
337+
defarchive_comments()do
338+
now=Timex.now()|>DateTime.truncate(:second)
339+
threshold=@archive_threshold[:default]
340+
archive_threshold=Timex.shift(now,threshold)
341+
342+
Comment
343+
|>where([c],c.inserted_at<^archive_threshold)
344+
|>Repo.update_all(set:[is_archived:true,archived_at:now])
345+
|>done()
346+
end
347+
325348
defpdo_paged_comment(thread,article_id,filters,where_query,user)do
326349
%{page:page,size:size}=filters
327350
sort=Map.get(filters,:sort,:asc_inserted)

‎lib/groupher_server/cms/helper/macros.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ defmodule GroupherServer.CMS.Helper.Macros do
201201

202202
field(:active_at,:utc_datetime_usec)
203203

204-
field(:is_archived,:boolean,default:false)
204+
field(:is_archived,:boolean)
205205
field(:archived_at,:utc_datetime_usec)
206206

207207
# TODO:

‎lib/groupher_server/cms/models/comment.ex‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ defmodule GroupherServer.CMS.Model.Comment do
8383

8484
has_many(:upvotes,{"comments_upvotes",CommentUpvote})
8585

86+
field(:is_archived,:boolean,default:false)
87+
field(:archived_at,:utc_datetime)
88+
8689
article_belongs_to_fields()
8790
timestamps(type::utc_datetime)
8891
end

‎lib/groupher_server_web/schema/cms/cms_types.ex‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
342342
field(:is_for_question,:boolean)
343343
field(:is_solution,:boolean)
344344

345+
field(:is_archived,:boolean)
346+
field(:archived_at,:datetime)
347+
345348
timestamp_fields()
346349
end
347350

‎lib/helper/scheduler.ex‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ defmodule Helper.Scheduler do
33
cron-like job scheduler
44
"""
55
useQuantum.Scheduler,otp_app::groupher_server
6-
# alias Helper.Cache
6+
7+
importHelper.Utils,only:[get_config:2]
8+
aliasGroupherServer.CMS
9+
10+
@article_threadsget_config(:article,:threads)
711

812
@doc"""
913
clear all the cache in Cachex
@@ -17,6 +21,10 @@ defmodule Helper.Scheduler do
1721
archive articles and comments based on config
1822
"""
1923
defarchive_artiments()do
20-
# TODO
24+
Enum.map(@article_threads,&CMS.archive_articles(&1))
25+
end
26+
27+
defarthive_comments()do
28+
CMS.archive_comments()
2129
end
2230
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmoduleGroupherServer.Repo.Migrations.AddArchiveFieldsToCommentsdo
2+
useEcto.Migration
3+
4+
defchangedo
5+
altertable(:comments)do
6+
add(:is_archived,:boolean,default:false)
7+
add(:archived_at,:utc_datetime)
8+
end
9+
end
10+
end

‎test/groupher_server/cms/articles/blog_archive_test.exs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ defmodule GroupherServer.Test.CMS.BlogArchive do
2727
end
2828

2929
describe"[cms blog archive]"do
30-
@tag:wip
3130
test"can archive blogs",~m(blog_long_ago)ado
3231
{:ok,_}=CMS.archive_articles(:blog)
3332

@@ -41,7 +40,6 @@ defmodule GroupherServer.Test.CMS.BlogArchive do
4140
assertarchived_blog.id==blog_long_ago.id
4241
end
4342

44-
@tag:wip
4543
test"can not edit archived blog"do
4644
{:ok,_}=CMS.archive_articles(:blog)
4745

@@ -55,7 +53,6 @@ defmodule GroupherServer.Test.CMS.BlogArchive do
5553
assertreason|>is_error?(:archived)
5654
end
5755

58-
@tag:wip
5956
test"can not delete archived blog"do
6057
{:ok,_}=CMS.archive_articles(:blog)
6158

‎test/groupher_server/cms/articles/job_archive_test.exs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ defmodule GroupherServer.Test.CMS.JobArchive do
2727
end
2828

2929
describe"[cms job archive]"do
30-
@tag:wip
3130
test"can archive jobs",~m(job_long_ago)ado
3231
{:ok,_}=CMS.archive_articles(:job)
3332

@@ -41,7 +40,6 @@ defmodule GroupherServer.Test.CMS.JobArchive do
4140
assertarchived_job.id==job_long_ago.id
4241
end
4342

44-
@tag:wip
4543
test"can not edit archived job"do
4644
{:ok,_}=CMS.archive_articles(:job)
4745

@@ -55,7 +53,6 @@ defmodule GroupherServer.Test.CMS.JobArchive do
5553
assertreason|>is_error?(:archived)
5654
end
5755

58-
@tag:wip
5956
test"can not delete archived job"do
6057
{:ok,_}=CMS.archive_articles(:job)
6158

‎test/groupher_server/cms/articles/meetup_archive_test.exs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ defmodule GroupherServer.Test.CMS.MeetupArchive do
2727
end
2828

2929
describe"[cms meetup archive]"do
30-
@tag:wip
3130
test"can archive meetups",~m(meetup_long_ago)ado
3231
{:ok,_}=CMS.archive_articles(:meetup)
3332

@@ -41,7 +40,6 @@ defmodule GroupherServer.Test.CMS.MeetupArchive do
4140
assertarchived_meetup.id==meetup_long_ago.id
4241
end
4342

44-
@tag:wip
4543
test"can not edit archived meetup"do
4644
{:ok,_}=CMS.archive_articles(:meetup)
4745

@@ -55,7 +53,6 @@ defmodule GroupherServer.Test.CMS.MeetupArchive do
5553
assertreason|>is_error?(:archived)
5654
end
5755

58-
@tag:wip
5956
test"can not delete archived meetup"do
6057
{:ok,_}=CMS.archive_articles(:meetup)
6158

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp