Skip to content

Commit

Permalink
Bug fix - User limit to their own campaigns (gitcoinco#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Berry authored May 20, 2020
1 parent 5881679 commit 1396f53
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ lib/tasks/impressions.rake
.vscode
stats.json
*.tmp
*.log
12 changes: 12 additions & 0 deletions app/controllers/demos_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class DemosController < ApplicationController
before_action :load_campaigns

layout "demo"
helper_method :position
ABSOLUTE = ["bottom-bar", "top-bar", "smart-bar", "sticky-box"]
Expand Down Expand Up @@ -29,4 +31,14 @@ def campaign
def demo_params
params.permit(:template, :theme, :campaign_id)
end

def load_campaigns
@campaigns = if authorized_user&.can_admin_system?
Campaign.all.order(name: :asc)
elsif current_user&.campaigns
current_user.campaigns.order(name: :asc)
else
[]
end
end
end
44 changes: 23 additions & 21 deletions app/views/demos/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@
</script>
<% end %>
<%= tag.div(id: "codefund") if position&.inquiry&.absolute? %>
<div class="row p-4" data-controller="ad-demo">
<%= form_with url: demo_path, method: :put, html: {data: {target: "ad-demo.form"}, class: "w-100"} do |form| %>
<div class="col-md-6 offset-md-3 mb-md-2">
<label class="form-label select" for="ad_demo_template">Template:</label>
<%= form.collection_select(:template, ENUMS::AD_TEMPLATES.values, :to_s, :to_s, {selected: @template}, {
class: "form-control custom-select", id: "ad_demo_template",
data: {action: "change->ad-demo#update", controller: "select", target: "ad-demo.templateSelect"}}) %>
</div>
<div class="col-md-6 offset-md-3 mb-md-2">
<label class="form-label select" for="ad_demo_theme">Theme:</label>
<%= form.collection_select(:theme, ENUMS::AD_THEMES.values, :to_s, :to_s, {selected: @theme}, {
class: "form-control custom-select", id: "ad_demo_theme",
data: {action: "change->ad-demo#update", controller: "select", target: "ad-demo.themeSelect"}}) %>
</div>
<% if current_user && current_user.campaigns.present? %>
<div class="col-md-6 offset-md-3">
<label class="form-label select" for="ad_demo_theme">Campaign:</label>
<%= form.collection_select(:campaign_id, current_user.campaigns, :id, :to_s, {selected: @campaign_id}, {
class: "form-control custom-select", id: "ad_demo_campaign_id",
data: {action: "change->ad-demo#update", controller: "select", target: "ad-demo.campaignIdSelect"}}) %>
<div class="container p-4" data-controller="ad-demo">
<%= form_with url: demo_path, method: :put, html: {data: {target: "ad-demo.form"}} do |form| %>
<div class="row">
<div class="col-sm">
<label class="form-label select" for="ad_demo_template">Template:</label>
<%= form.collection_select(:template, ENUMS::AD_TEMPLATES.values, :to_s, :to_s, {selected: @template}, {
class: "form-control custom-select", id: "ad_demo_template",
data: {action: "change->ad-demo#update", controller: "select", target: "ad-demo.templateSelect"}}) %>
</div>
<% end %>
<div class="col-sm">
<label class="form-label select" for="ad_demo_theme">Theme:</label>
<%= form.collection_select(:theme, ENUMS::AD_THEMES.values, :to_s, :to_s, {selected: @theme}, {
class: "form-control custom-select", id: "ad_demo_theme",
data: {action: "change->ad-demo#update", controller: "select", target: "ad-demo.themeSelect"}}) %>
</div>
<% if @campaigns.present? %>
<div class="col-sm">
<label class="form-label select" for="ad_demo_theme">Campaign:</label>
<%= form.collection_select(:campaign_id, @campaigns, :id, :to_s, {selected: @campaign_id}, {
class: "form-control custom-select", id: "ad_demo_campaign_id",
data: {action: "change->ad-demo#update", controller: "select", target: "ad-demo.campaignIdSelect"}}) %>
</div>
<% end %>
</div>
<% end %>
</div>
<div class="<%= @theme.inquiry.dark? ? "bg-dark text-white" : "bg-white" %> vw-100 pt-4">
Expand Down
2 changes: 1 addition & 1 deletion bin/copy_production_db_to_local
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source .env
export RAILS_ENV=development

bundle exec rails db:migrate db:drop db:create
bundle exec rails db:drop db:create
./bin/heroku_pg_dump_production_replica
pg_restore -U ${PG_USERNAME:-postgres} --verbose --clean --no-acl --no-owner -h ${PG_HOST:-localhost} -p ${PG_PORT:-5432} -d code_fund_ads_development tmp/production-shallow.dump
bundle exec rails db:migrate
Expand Down

0 comments on commit 1396f53

Please sign in to comment.