Merge remote-tracking branch 'upstream/dev' into js/cleanup

This commit is contained in:
Brenda Wallace
2018-01-03 11:54:09 +13:00
20 changed files with 138 additions and 97 deletions

View File

@@ -174,15 +174,15 @@ GEM
faraday
multi_json
erubis (2.7.0)
excon (0.59.0)
excon (0.60.0)
execjs (2.7.0)
factory_bot (4.8.2)
activesupport (>= 3.0.0)
factory_bot_rails (4.8.2)
factory_bot (~> 4.8.2)
railties (>= 3.0.0)
faker (1.8.5)
i18n (~> 0.9.1)
faker (1.8.7)
i18n (>= 0.7)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.18)
@@ -238,7 +238,7 @@ GEM
rake (>= 10, < 13)
rubocop (>= 0.49.0)
sysexits (~> 1.1)
hashie (3.5.6)
hashie (3.5.7)
heroics (0.0.24)
erubis (~> 2.0)
excon
@@ -276,7 +276,7 @@ GEM
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
js-routes (1.4.2)
js-routes (1.4.3)
railties (>= 3.2)
sprockets-rails
json (2.1.0)
@@ -297,7 +297,7 @@ GEM
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
kgio (2.11.0)
kgio (2.11.1)
kramdown (1.16.2)
launchy (2.4.3)
addressable (~> 2.3)
@@ -329,7 +329,7 @@ GEM
multi_xml (0.6.0)
multipart-post (2.0.0)
nenv (0.3.0)
newrelic_rpm (4.6.0.338)
newrelic_rpm (4.7.1.340)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
notiffany (0.1.1)
@@ -366,7 +366,7 @@ GEM
cocaine (~> 0.5.5)
mime-types
mimemagic (~> 0.3.0)
parallel (1.12.0)
parallel (1.12.1)
parser (2.4.0.2)
ast (~> 2.3)
pg (0.21.0)
@@ -408,8 +408,8 @@ GEM
rails-assets-leaflet (>= 1.0.3)
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.8)
activesupport (>= 4.2.0.beta, < 5.0)
rails-dom-testing (1.0.9)
activesupport (>= 4.2.0, < 5.0)
nokogiri (~> 1.6)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
@@ -475,7 +475,7 @@ GEM
ruby_parser (3.10.1)
sexp_processor (~> 4.9)
rubyzip (1.2.1)
sass (3.5.3)
sass (3.5.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
@@ -528,7 +528,7 @@ GEM
uglifier (4.0.2)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.3.0)
unicorn (5.3.1)
unicorn (5.4.0)
kgio (~> 2.6)
raindrops (~> 0.7)
uniform_notifier (1.10.0)

View File

@@ -0,0 +1,14 @@
module Admin
class MembersController < ApplicationController
before_action :auth!
def index
@members = Member.order(:login_name).paginate(page: params[:page])
end
private
def auth!
authorize! :manage, :all
end
end
end

View File

@@ -1,21 +1,23 @@
class Admin::OrdersController < ApplicationController
def index
authorize! :manage, :all
respond_to do |format|
format.html # index.html.haml
end
end
def search
authorize! :manage, :all
@orders = Order.search(by: params[:search_by], for: params[:search_text])
if @orders.empty?
flash[:alert] = "Couldn't find order with #{params[:search_by]} = #{params[:search_text]}"
module Admin
class OrdersController < ApplicationController
def index
authorize! :manage, :all
respond_to do |format|
format.html # index.html.haml
end
end
respond_to do |format|
format.html # index.html.haml
def search
authorize! :manage, :all
@orders = Order.search(by: params[:search_by], for: params[:search_text])
if @orders.empty?
flash[:alert] = "Couldn't find order with #{params[:search_by]} = #{params[:search_text]}"
end
respond_to do |format|
format.html # index.html.haml
end
end
end
end

View File

@@ -18,6 +18,7 @@ class HarvestsController < ApplicationController
def show
@matching_plantings = matching_plantings if @harvest.owner == current_member
@photos = @harvest.photos.order(created_at: :desc).paginate(page: params[:page])
respond_with(@harvest)
end

View File

@@ -31,6 +31,7 @@ class PlantingsController < ApplicationController
@planting = Planting.includes(:owner, :crop, :garden, :photos)
.friendly
.find(params[:id])
@photos = @planting.photos.order(created_at: :desc).includes(:owner).paginate(page: params[:page])
respond_with @planting
end

View File

@@ -1,7 +1,13 @@
class Ability
include CanCan::Ability
def initialize(member) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def initialize(member)
anon_abilities(member)
member_abilities(member) if member.present?
admin_abilities(member) if member.present? && member.role?(:admin)
end
def anon_abilities(_member)
# See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
# everyone can do these things, even non-logged in
@@ -35,7 +41,9 @@ class Ability
can :read, AlternateName do |an|
an.crop.approved?
end
end
def member_abilities(member) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
return unless member
# members can see even rejected or pending crops if they requested it
@@ -126,7 +134,9 @@ class Ability
can :destroy, Follow
cannot :destroy, Follow, followed_id: member.id # can't unfollow yourself
end
def admin_abilities(member)
return unless member.role? :admin
can :read, :all

View File

@@ -2,16 +2,28 @@
%h2 Manage
%ul#admin_links
%li= link_to "Account types", account_types_path
%li= link_to "Alternate names", alternate_names_path
%li= link_to "Scientific names", scientific_names_path
%li= link_to "Products", products_path
%li= link_to "Roles", roles_path
%li= link_to "Forums", forums_path
%li= link_to "Newsletter subscribers", admin_newsletter_path
%li= link_to "CMS", comfy_admin_cms_path
.row
.col-md-4
%h2 Site admin
%ul#site_admin
%li= link_to "Account types", account_types_path
%li= link_to "Products", products_path
%li= link_to "Roles", roles_path
%li= link_to "Forums", forums_path
%li= link_to "CMS", comfy_admin_cms_path
%h2 Orders
.col-md-4
%h2 Crop data admin
%ul
%li= link_to "Alternate names", alternate_names_path
%li= link_to "Scientific names", scientific_names_path
.col-md-4
%h2 Member admin
%ul
%li= link_to "Newsletter subscribers", admin_newsletter_path
%li= link_to "Members", admin_members_path
= render "admin/orders/searchform"
.row
.col-md-12
%h2 Orders
= render "admin/orders/searchform"

View File

@@ -0,0 +1,15 @@
.pagination
= page_entries_info @members
= will_paginate @members
%table.table.table-striped
%tr
%th Name
%th Email
%th
%th
- @members.each do |member|
%tr
%td= ember.login_name
%td= member.email

View File

@@ -48,15 +48,4 @@
:growstuff_markdown
#{ @harvest.description != "" ? strip_tags(@harvest.description) : "No description given." }
- if !@harvest.photos.empty? || (can?(:edit, @harvest) && can?(:create, Photo))
%h2 Pictures
%ul.thumbnails
- @harvest.photos.each do |p|
.col-md-2.six-across
= render partial: 'photos/thumbnail', locals: { photo: p }
- if can?(:create, Photo) && can?(:edit, @harvest)
.col-md-2
.thumbnail{ style: 'height: 220px' }
%p{ style: 'text-align: center; padding-top: 50px' }
= link_to "Add photo", new_photo_path(type: "harvest", id: @harvest.id), class: 'btn btn-primary'
= render 'photos/item_photos', item: @harvest, type: 'harvest', photos: @photos

View File

@@ -0,0 +1,16 @@
- if photos.size.positive? || (can?(:edit, item) && can?(:create, Photo))
%h2 Photos
- if photos.size.positive?
.row
.pagination
= page_entries_info photos
= will_paginate photos
.row
- photos.each do |photo|
.col-md-2.six-across= render 'photos/thumbnail', photo: photo
- if can?(:create, Photo) && can?(:edit, item)
.col-md-2
.thumbnail
= link_to new_photo_path(type: type, id: item.id), class: 'btn btn-primary' do
%span.glyphicon.glyphicon-camera{ title: "Add photo" }
Add photo

View File

@@ -83,15 +83,4 @@
:growstuff_markdown
#{ @planting.description != "" ? strip_tags(@planting.description) : "No description given." }
- if !@planting.photos.empty? || (can?(:edit, @planting) && can?(:create, Photo))
%h2 Photos
.row
- @planting.photos.includes(:owner).each do |p|
.col-md-2.six-across
= render partial: 'photos/thumbnail', locals: { photo: p }
- if can?(:create, Photo) && can?(:edit, @planting)
.col-md-2
.thumbnail{ style: 'height: 220px' }
%p{ style: 'text-align: center; padding-top: 50px' }
= link_to "Add photo", new_photo_path(type: "planting", id: @planting.id), class: 'btn btn-primary'
= render 'photos/item_photos', item: @planting, type: 'planting', photos: @photos

View File

@@ -1,18 +1,19 @@
= form_for @role do |f|
- if @role.errors.any?
#error_explanation
%h2
= pluralize(@role.errors.size, "error")
prohibited this role from being saved:
%ul
- @role.errors.full_messages.each do |msg|
%li= msg
.row
- if @role.errors.any?
#error_explanation
%h2
= pluralize(@role.errors.size, "error")
prohibited this role from being saved:
%ul
- @role.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :name
= f.text_field :name
.col-md2= f.label :name
.col-md10= f.text_field :name
.field
= f.label :description
= f.text_area :description
.col-md2= f.label :description
.col-md10= f.text_area :description
.actions
= f.submit 'Save'
= f.submit 'Save', class: 'btn btn-default'

View File

@@ -2,6 +2,4 @@
= render 'form'
= link_to 'Show', @role
\|
= link_to 'Back', roles_path

View File

@@ -3,17 +3,16 @@
- if can? :create, Role
%p= link_to 'New Role', new_role_path, class: 'btn btn-primary'
%table
%table.table.table-striped
%tr
%th Name
%th Description
%th
%th
%th
- @roles.each do |role|
%tr
%td= link_to role.name, role
%td= role.name
%td= role.description
- if can? :edit, role
%td= link_to 'Edit', edit_role_path(role), class: 'btn btn-default btn-xs'

View File

@@ -76,15 +76,4 @@
= link_to "purchase seeds via Ebay",
crop_ebay_seeds_url(@seed.crop), target: "_blank", rel: "noopener noreferrer"
- if @photos.size.positive?
.row
.pagination
= page_entries_info @photos
= will_paginate @photos
.row
- @photos.each do |p|
.col-md-2.six-across
= render 'photos/thumbnail', photo: p
- if can?(:create, Photo) && can?(:edit, @seed)
.col-md-2
= link_to "Add photo", new_photo_path(type: "seed", id: @seed.id), class: 'btn btn-primary'
= render 'photos/item_photos', item: @seed, type: 'seed', photos: @photos

View File

@@ -90,6 +90,9 @@ Growstuff::Application.routes.draw do
get '/shop/:action' => 'shop#:action'
comfy_route :cms_admin, path: '/admin/cms'
namespace :admin do
resources :members
end
get '/admin/orders' => 'admin/orders#index'
get '/admin/orders/:action' => 'admin/orders#:action'
get '/admin' => 'admin#index'

View File

@@ -13,7 +13,7 @@ feature "forums", js: true do
visit root_path
click_link "Admin"
expect(current_path).to eq admin_path
within 'ul#admin_links' do
within 'ul#site_admin' do
click_link "Forums"
end
expect(current_path).to eq forums_path
@@ -25,7 +25,7 @@ feature "forums", js: true do
click_link member.login_name
click_link "Admin"
expect(current_path).to eq admin_path
within 'ul#admin_links' do
within 'ul#site_admin' do
click_link "Forums"
end
expect(current_path).to eq forums_path

View File

@@ -6,6 +6,7 @@ describe "harvests/show" do
before do
controller.stub(:current_user) { nil }
assign(:harvest, harvest)
assign(:photos, harvest.photos.paginate(page: 1))
render
end

View File

@@ -12,6 +12,7 @@ describe "plantings/show" do
before(:each) do
assign(:planting, planting)
assign(:photos, planting.photos.paginate(page: 1))
controller.stub(:current_user) { member }
end

View File

@@ -5,7 +5,7 @@ describe "seeds/show" do
controller.stub(:current_user) { nil }
@seed = FactoryBot.create(:seed)
assign(:seed, @seed)
assign(:photos, @seed.photos)
assign(:photos, @seed.photos.paginate(page: 1))
end
it "renders attributes in <p>" do