forked from publify/publify
-
Notifications
You must be signed in to change notification settings - Fork 19
Created merge article feature for admins #33
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
Open
Dreedle
wants to merge
28
commits into
Ada-C4:master
Choose a base branch
from
Dreedle:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
7591abd
Addin gpry
Dreedle 7bc474e
Cucumber test for viewing new category page seems to work. Adding con…
Dreedle ee9127b
Fleshing out edit action in admin categories controller to be analogo…
Dreedle 8500d5e
Wrote rspec and cucumber tests that fail when the original bug is pre…
Dreedle d50917d
Removing pry require
Dreedle 6620396
Able to create and edit categories
Dreedle 7bfec19
Merge branch 'createcat'
Dreedle cc0b3f8
Adding cucumber tests for creating and editing categories
Dreedle a086d02
Adding cuke stubbed tests for merge article feature. Able to log in a…
Dreedle 541bb51
Mapping edit article path for cucumber test
Dreedle cca8085
Adding content creation to blog setup in cuke tests
Dreedle df4466e
Changing content creation to article creation in cuke tests
Dreedle 80bdce7
Improving cuke test for edit category
Dreedle 7fa43e8
Improving create category cuke test
Dreedle 44c15ea
Adding cuke tests for editing articles (authorization)
Dreedle 838d007
Removing edit articles from paths.rb
Dreedle 33eb38d
Red cuke test for article merging as admin vs not admin
Dreedle 6fd7d63
Moving merge article feature tests conerning authorization to their o…
Dreedle 3218a8b
Stubbing out cuke tests for merge_article.feature
Dreedle 088d55e
Specs for merge article feature (red) are complete
Dreedle f65e97e
Adding html for merge article form
Dreedle 1c341fc
Adding better errors and binding of caller
Dreedle 45abe42
Merge article is present for admin but not non-admin (cuke tests pass)
Dreedle 77c3b04
Cuke test passing for feature not accessible when article is new
Dreedle 4545acb
Trying to get green on cuke test for succesful merge
Dreedle 096c9e6
Improved cuke tests for merge, though no test for author merge yet. T…
Dreedle cd29d3b
Cuke test passing for combining article text
Dreedle 7b4dbc5
Adding conditional to admin new content view to make rspecs pass
Dreedle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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 |
|---|---|---|
|
|
@@ -71,6 +71,17 @@ def initialize(*args) | |
| end | ||
| end | ||
|
|
||
| def merge_with(other_article_id) | ||
| other_article = Article.find(other_article_id) | ||
| Article.transaction do | ||
|
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. Yes! Definitely a transaction is good here. I think you can also use |
||
| old_body = self.body | ||
| self.body = "#{old_body} <p>\r\n\t #{other_article.body} </p>\r\n" | ||
| self.comments << other_article.comments | ||
| self.save! | ||
| other_article.delete | ||
| end | ||
| end | ||
|
|
||
| def set_permalink | ||
| return if self.state == 'draft' | ||
| self.permalink = self.title.to_permalink if self.permalink.nil? or self.permalink.empty? | ||
|
|
@@ -95,6 +106,7 @@ def has_child? | |
| include Article::States | ||
|
|
||
| class << self | ||
|
|
||
| def last_draft(article_id) | ||
| article = Article.find(article_id) | ||
| while article.has_child? | ||
|
|
@@ -104,10 +116,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 | ||
|
|
||
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
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
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
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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| <% @page_heading = _('New article') %> | ||
|
|
||
| <%= render "admin/shared/edit", { :form_type => "article", :form_action => { :action => "new", :id => @article.id , :class => ('autosave')} } %> | ||
|
|
||
| <% if @current_user && @current_user.admin? && @article.id %> | ||
| <%= render "admin/shared/merge" %> | ||
| <% end %> |
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,17 @@ | ||
|
|
||
| <div class='editor-left'> | ||
| <%= form_for @article, url: {controller: "admin/content", action: "merge", id: @article.id }, | ||
| :html => { :class => "form" } do |f| %> | ||
| <h3><%= _("Merge Articles") %></h3> | ||
| <div class='class'> | ||
| <span> | ||
| Article ID | ||
| <%= text_field "other_article_id", "other_article_id", {:autocomplete => 'off', :style => 'width: 30%; margin-left: 10px'} %> | ||
| </span> | ||
| <div style="padding-top:10px"> | ||
|
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. Can you use a class here instead of inline style? |
||
| <%= f.submit "Merge", :class => 'btn' %> | ||
| </div> | ||
| </div> | ||
|
|
||
| <% end %> | ||
| </div> | ||
Binary file not shown.
Binary file not shown.
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,23 @@ | ||
| Feature: Create Categories | ||
| As an admin | ||
| In order to organize my blog posts into categories | ||
| I want to create a category | ||
|
|
||
| Background: | ||
| Given the blog is set up | ||
| And I am logged into the admin panel | ||
|
|
||
| Scenario: New category page shown | ||
| Given I am on the new category page | ||
| Then I should see "Categories" | ||
|
|
||
| Scenario: Successfully create category | ||
| Given I am on the new category page | ||
| When I fill in "category_name" with "Foobar" | ||
| And I fill in "category_keywords" with "Lorem Ipsum" | ||
| And I fill in "category_description" with "Lorem Ipsum" | ||
| And I press "Save" | ||
| Then I should be on the new category page | ||
| And I should see "Category was successfully saved." | ||
| And I should see "Foobar" | ||
| And I should see "Lorem Ipsum" |
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,29 @@ | ||
| Feature: Edit Articles | ||
| As a blog publisher or admin | ||
| In order to provide the best articles possible | ||
| I want to be able to edit articles | ||
|
|
||
| Background: | ||
| Given the blog is set up | ||
|
|
||
| Scenario: Successfully edit articles that belong to publisher | ||
| Given I am logged in as a blog publisher | ||
| Given the following article record | ||
| | title | body | published | user_id | | ||
| | "publisher article" | "hi here it is" | true | 2 | | ||
|
|
||
| And I am on the articles page | ||
| Then I should see "publisher article" | ||
| When I follow "Edit" | ||
| Then I should see "Publish settings" | ||
|
|
||
| Scenario: As publisher, cannot edit articles that do not belong to you. | ||
| Given I am logged in as a blog publisher | ||
| Given the following article record | ||
| | title | body | published | user_id | | ||
| | "admin article" | "hi here's another" | true | 1 | | ||
|
|
||
| And I am on the articles page | ||
| Then I should see "admin article" | ||
| When I follow "Edit" | ||
| Then I should see "Error, you are not allowed to perform this action" |
Oops, something went wrong.
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.
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.
Thought: Does the params[:action] in this
elsifas well as the one below change the conditional, or could you just use params[:id]