Skip to content

Commit

Permalink
Merge pull request #2118 from geeksforsocialchange/2108-site_admin-ac…
Browse files Browse the repository at this point in the history
…cess--clean

site_admin access
  • Loading branch information
aaaaargZombies authored Nov 2, 2023
2 parents 4342362 + 0755569 commit 0704a01
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 38 deletions.
10 changes: 5 additions & 5 deletions app/policies/site_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def destroy?
end

def permitted_attributes
attrs = %i[id name place_name is_published tagline description
badge_zoom_level hero_image hero_image_credit hero_text]
attrs = %i[id name place_name logo footer_logo is_published tagline description
badge_zoom_level hero_image hero_image_credit hero_text theme ]
.push(sites_neighbourhoods_attributes: %i[_destroy id neighbourhood_id relation_type],
sites_neighbourhood_attributes: %i[_destroy id neighbourhood_id relation_type],
tag_ids: [])
sites_neighbourhood_attributes: %i[_destroy id neighbourhood_id relation_type])

root_attrs = %i[slug domain logo footer_logo theme site_admin_id]
root_attrs = %i[slug domain site_admin_id tags sites_neighbourhoods]
.push(tag_ids: [])

return root_attrs + attrs if user.root?

Expand Down
78 changes: 55 additions & 23 deletions app/views/admin/sites/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@
<%= f.input :tagline %>
<div class="row">
<div class="col-md-6">
<%= f.input :domain if policy(@site).permitted_attributes.include? :domain %>
<% if policy(@site).permitted_attributes.include? :domain %>
<%= f.input :domain %>
<% else %>
<%= f.input :domain, disabled: true %>
<% end %>
</div>
<div class="col-md-6">
<%= f.input :slug if policy(@site).permitted_attributes.include? :slug %>
<% if policy(@site).permitted_attributes.include? :slug %>
<%= f.input :slug %>
<% else %>
<%= f.input :slug, disabled: true %>
<% end %>
</div>
</div>
<%= f.input :hero_text, hint: 'Large text for the banner with image on the homepage, up to 120 characters', input_html: { rows: 5 } %>
Expand All @@ -22,6 +30,8 @@

<% if policy(@site).permitted_attributes.include? :site_admin_id %>
<%= f.association(:site_admin, label_method: :admin_name, input_html: { data: { controller: 'select2' } }) %>
<% else %>
<p><strong>Admin</strong>: <%= @site.site_admin %></p>
<% end %>


Expand All @@ -43,9 +53,9 @@
<div style="background-color: #5b4e46; padding: 1rem">
<%= image_tag f.object.footer_logo.url, class: 'card-img-top' if f.object.footer_logo.url %>
</div>
<% end %>
</div>
</div>
<% end %>

<%= f.input :hero_image, hint: image_uploader_hint(@site.hero_image) %>
<p><em>Header images should be 2260x700</em></p>
Expand Down Expand Up @@ -93,7 +103,8 @@
</div>
<div class="col-md-6">
<h3>Neighbourhood information display</h3>
<p class="font-weight-light">What level of geographical zoom should PlaceCal display on partners and events?</p>
<p class="font-weight-light">What level of geographical zoom should PlaceCal display in the small badge next to partners and events? eg. Hulme / Manchester</p>

<%= f.input :badge_zoom_level,
as: :radio_buttons,
label_method: ->(val){ Site.badge_zoom_level_label(val) } %>
Expand All @@ -104,29 +115,50 @@
<h3>Other neighbourhoods to include</h3>
<p class="font-weight-light">Information from these neighbourhoods will also be displayed on this site</p>

<div class="sites_neighbourhoods">
<%= f.simple_fields_for :sites_neighbourhoods do |neighbourhood| %>
<%= render 'sites_neighbourhood_fields', :f => neighbourhood %>
<% end %>
<div class="links">
<%= link_to_add_association 'Add neighbourhood', f, :sites_neighbourhoods, class: "btn btn-primary btn-sm" %>
<% if policy(@site).permitted_attributes.include? :sites_neighbourhoods %>
<div class="sites_neighbourhoods">
<%= f.simple_fields_for :sites_neighbourhoods do |neighbourhood| %>
<%= render 'sites_neighbourhood_fields', :f => neighbourhood %>
<% end %>
<div class="links">
<%= link_to_add_association 'Add neighbourhood', f, :sites_neighbourhoods, class: "btn btn-primary btn-sm" %>
</div>
<br></br>
</div>
<br></br>
</div>
<% else %>
<div class="sites_neighbourhoods">
<ul>
<% @site.sites_neighbourhoods.each do |neighbourhood| %>
<% if neighbourhood.relation_type != 'Primary' %>
<li><%= neighbourhood.name %></li>
<% end %>
<% end %>
</ul>
<br></br>
</div>
<% end %>

<h2>Tags</h2>
<h2>Partnerships</h2>

<div class="row">
<div class="col-md-6">
<p class="font-weight-light">Only show partners with these tags</p>
<%= f.association :tags,
label: false,
collection: options_for_tags,
input_html: { class: 'form-check', data: { controller: "select2" } } %>
<div class="row">
<div class="col-md-6">
<p class="font-weight-light">(If selected) Only show partners which are members of these Partnerships</p>
<% if policy(@site).permitted_attributes.include? :tags %>
<%= f.association :tags,
label: false,
collection: options_for_tags,
input_html: { class: 'form-check', data: { controller: "select2" } } %>
<% else %>
<%= f.association :tags,
disabled: true,
label: false,
collection: options_for_tags,
input_html: { class: 'form-check', data: { controller: "select2" } } %>
<% end %>
</div>
</div>
</div>
<br>
<br>
<br>
<br>


<%= f.button :submit, class: "btn btn-primary btn-lg" %>
Expand Down
15 changes: 5 additions & 10 deletions test/integration/admin/sites_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,16 @@ class AdminSitesIntegrationTest < ActionDispatch::IntegrationTest
assert_select 'label', 'Name *'
assert_select 'label', 'Place name'
assert_select 'label', 'Tagline'
assert_select 'label', text: 'Domain *', count: 0
assert_select 'label', text: 'Slug *', count: 0
assert_select 'label', text: 'Domain *', count: 1
assert_select 'label', text: 'Slug *', count: 1
assert_select 'label', 'Description'
assert_select 'label', text: 'Site admin', count: 0

assert_select 'label', text: 'Theme', count: 0
assert_select 'label', text: 'Logo', count: 0
assert_select 'label', text: 'Footer logo', count: 0
assert_select 'label', text: 'Theme', count: 1
assert_select 'label', text: 'Logo', count: 1
assert_select 'label', text: 'Footer logo', count: 1
assert_select 'label', 'Hero image'
assert_select 'label', 'Hero image credit'

# See just neighbourhoods they admin
cocoon_select_template = assert_select('.add_fields').first['data-association-insertion-template']
neighbourhoods_shown = cocoon_select_template.scan(/(option value=)/).size
assert_equal(2, neighbourhoods_shown)
end

test 'site tags show up and display their type' do
Expand Down

0 comments on commit 0704a01

Please sign in to comment.