Merge pull request #150 from houdiniproject/fix_issues_with_deleted_p2p_campaigns

Fix issues with deleted p2p campaigns
This commit is contained in:
Eric Schultz 2019-02-06 11:13:53 -06:00 committed by GitHub
commit 6e77a98bff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 5 deletions

View file

@ -150,9 +150,15 @@
</div>
</div>
<% else %>
<p>
Seems like you already have a campaign for that cause! <%= link_to "Click here to see it", @child_campaign.url %>.
</p>
<% if @child_campaign.deleted %>
<p>
Seems like you already have a campaign for that cause! <%= link_to "Click here to reactivate your campaign", "javascript:appl.undelete_p2p(\"/nonprofits/#{@child_campaign.nonprofit_id}/campaigns/#{@child_campaign.id}\")" %>
</p>
<% else %>
<p>
Seems like you already have a campaign for that cause! <%= link_to "Click here to see it", @child_campaign.url %>.
</p>
<% end %>
<% end %>
</li>

View file

@ -5,6 +5,19 @@ require('../../common/image_uploader')
var request = require("../../common/client")
appl.def('undelete_p2p', function (url){
appl.def('loading', true)
request.put(url + '/soft_delete', {delete: false}).end(function(err, resp) {
if (err) {
appl.def('loading', false)
}
else{
window.location = url
}
})
})
// setting up some default values
appl.def('is_signing_up', true)
.def('selected_result_index', -1)

View file

@ -21,7 +21,7 @@ class SlugP2pCampaignNamingAlgorithm < CopyNamingAlgorithm
def get_already_used_name_entities(base_name)
end_name = "\\_\\d{3}"
Campaign.where('slug SIMILAR TO ? AND nonprofit_id = ? AND (deleted IS NULL OR deleted = false)', base_name + end_name, nonprofit_id).select('slug')
Campaign.where('slug SIMILAR TO ? AND nonprofit_id = ?', base_name + end_name, nonprofit_id).select('slug')
end
end

View file

@ -24,7 +24,7 @@ describe SlugP2pCampaignNamingAlgorithm do
describe 'campaigns' do
let(:campaign) {force_create(:campaign, :slug => @name, nonprofit: nonprofit)}
let(:campaign) {force_create(:campaign, :slug => @name, nonprofit: nonprofit, deleted:true)}
let(:campaign2) {force_create(:campaign, :slug => @name2, nonprofit:nonprofit)}
let(:campaigns_at_max_copies) { (0..999).collect{|i|
force_create(:campaign, slug: "#{@copy_base}_#{"%03d" % i}", nonprofit:nonprofit)