-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Admin user can merge two articles from edit page #25
base: master
Are you sure you want to change the base?
Changes from all commits
2545f33
4066a16
5ce6473
c9a0a31
7a0ffc9
a70de61
f7c4e53
2be66f9
1237194
17ea51e
f06cb7f
28c6afd
cefa0da
cd60cf9
6fe20e9
69a6ad0
f258055
ea6edec
0c67b88
ac18cfd
9d6e3d0
e3dc9da
62d6644
3e1f859
b1b373b
faf1d35
c40e808
21fb60c
d297418
57d6c07
9a3a6a8
9888ccd
68be69d
3832e0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ config/mail.yml | |
*~ | ||
db/*.sqlite* | ||
db/schema.rb | ||
db/db_test | ||
db/db_development | ||
.*.swp | ||
.*.swo | ||
.DS_Store | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,10 +104,10 @@ def last_draft(article_id) | |
end | ||
|
||
def search_with_pagination(search_hash, paginate_hash) | ||
|
||
state = (search_hash[:state] and ["no_draft", "drafts", "published", "withdrawn", "pending"].include? search_hash[:state]) ? search_hash[:state] : 'no_draft' | ||
|
||
|
||
list_function = ["Article.#{state}"] + function_search_no_draft(search_hash) | ||
|
||
if search_hash[:category] and search_hash[:category].to_i > 0 | ||
|
@@ -416,6 +416,17 @@ def access_by?(user) | |
user.admin? || user_id == user.id | ||
end | ||
|
||
def merge_with(other_article_id) | ||
Article.find(other_article_id).comments.each do |comment| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a lot of method chaining going on here. Is there a better way to get the comments associated without iterating through each one? |
||
comment.article_id = self.id | ||
comment.save | ||
end | ||
merge_article = Article.find(other_article_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like this and line 420 are both doing the same |
||
self.body += " " + merge_article.body | ||
self.save | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Saving the article and destroying the old one could both have different types of errors. Consider using a transaction to ensure that their both or none happen. |
||
merge_article.destroy | ||
end | ||
|
||
protected | ||
|
||
def set_published_at | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
<% @page_heading = _('New article') %> | ||
|
||
<%= render "admin/shared/edit", { :form_type => "article", :form_action => { :action => "new", :id => @article.id , :class => ('autosave')} } %> | ||
|
||
<% if current_user.admin? && [email protected]? %> | ||
<h3>Merge Articles</h3> | ||
<%= form_tag :action=>"merge", :id => @article.id do %> | ||
<%= error_messages_for 'article' %> | ||
<label for="merge_with"><%= _("Article ID")%></label> | ||
<div class='input'> | ||
<%= text_field :merge_with, :merge_id %> | ||
</div> | ||
<%= submit_tag("Merge") %> | ||
<% end %> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Feature: Manage Categories | ||
As a blog administrator | ||
In order to share my thoughts with the world | ||
I want to be able to add categories to my blog | ||
|
||
Background: | ||
Given the blog is set up | ||
And I am logged into the admin panel | ||
|
||
Scenario: Successfully add categories | ||
Given I am on the new category page | ||
Then I should not see "fun" | ||
When I fill in "category_name" with "fun" | ||
And I fill in "category_keywords" with "friend, happy, song" | ||
And I fill in "category_permalink" with "something" | ||
And I fill in "category_description" with "cool beans" | ||
And I press "Save" | ||
Then I should be on the new category page | ||
And I should see "fun" | ||
And I should see "friend, happy, song" | ||
And I should see "something" | ||
And I should see "cool beans" | ||
And I should have 2 categories | ||
|
||
Scenario: Successfully edit categories | ||
Given I am on the edit category page | ||
Then I should see "general" | ||
When I fill in "category_name" with "fun" | ||
And I fill in "category_keywords" with "friend, happy, song" | ||
And I fill in "category_permalink" with "something" | ||
And I fill in "category_description" with "cool beans" | ||
And I press "Save" | ||
Then I should be on the new category page | ||
Then I should not see "general" | ||
And I should see "fun" | ||
And I should see "friend, happy, song" | ||
And I should see "something" | ||
And I should see "cool beans" | ||
And I should have 1 categories |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Feature: Merge Articles | ||
As a blog administrator | ||
In order to share my thoughts with the world | ||
I want to be able to merge similar articles on my blog | ||
|
||
Background: | ||
Given the blog is set up | ||
|
||
Scenario: Non-admin cannot merge articles | ||
Given I am logged in as a contributor | ||
And I am on the edit articles page | ||
Then I should not see "Merge Articles" | ||
|
||
Scenario: Admin can successfully merge articles | ||
Given I am logged into the admin panel | ||
And I have two similar articles titled Cats, Dogs | ||
And I am on the manage articles page | ||
Then I should see "Cats" | ||
And I should see "Dogs" | ||
When I follow "Edit" | ||
Then I should be on the edit articles page | ||
And I should see "Merge Articles" | ||
When I fill in "merge_with_merge_id" with "4" | ||
And I press "Merge" | ||
Then I should be on the manage articles page | ||
And I should not see "Dogs" | ||
And I should see "Cats" | ||
When I follow "Show" | ||
Then I should see "I love cats I love dogs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating these local variables first is nice, but if the user isn't an admin, they aren't needed to i would suggest moving them into the first conditional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point. I made the change.