From 3400b50af9b6250f47a6b90ac9a5e32350051d9b Mon Sep 17 00:00:00 2001 From: James Kiesel Date: Wed, 13 Feb 2019 23:21:24 +1300 Subject: [PATCH 01/12] Add recommendations for Events and Organizations --- app/admin/dashboard.rb | 3 ++ app/admin/event.rb | 9 ++++ app/admin/membership.rb | 35 ++++++++++++++ app/admin/organization.rb | 4 ++ app/controllers/events_controller.rb | 46 +++++++++++++++++++ app/controllers/organizations_controller.rb | 13 ++++++ app/controllers/users_controller.rb | 6 +++ app/models/camp.rb | 2 +- app/models/event.rb | 16 +++++++ app/models/membership.rb | 5 +- app/models/organization.rb | 5 ++ app/models/user.rb | 6 ++- app/views/camps/_dont_miss_out.erb | 14 ++++++ app/views/camps/_list.html.erb | 8 ++++ app/views/events/index.html.erb | 13 ++++++ app/views/events/show.html.erb | 19 ++++++++ app/views/organizations/show.html.erb | 9 ++++ app/views/shared/_header.html.erb | 17 ++++++- config/initializers/initial_event.rb | 23 ++++++++++ config/initializers/lockdown.rb | 1 + config/routes.rb | 15 ++++-- db/migrate/20190211174823_add_events.rb | 21 +++++++++ .../20190213093958_add_event_to_camps.rb | 5 ++ db/schema.rb | 29 ++++++++++-- 24 files changed, 311 insertions(+), 13 deletions(-) create mode 100644 app/admin/event.rb create mode 100644 app/admin/membership.rb create mode 100644 app/admin/organization.rb create mode 100644 app/controllers/events_controller.rb create mode 100644 app/controllers/organizations_controller.rb create mode 100644 app/models/event.rb create mode 100644 app/models/organization.rb create mode 100644 app/views/events/index.html.erb create mode 100644 app/views/events/show.html.erb create mode 100644 app/views/organizations/show.html.erb create mode 100644 config/initializers/initial_event.rb create mode 100644 db/migrate/20190211174823_add_events.rb create mode 100644 db/migrate/20190213093958_add_event_to_camps.rb diff --git a/app/admin/dashboard.rb b/app/admin/dashboard.rb index 71c2662d..f03d5689 100644 --- a/app/admin/dashboard.rb +++ b/app/admin/dashboard.rb @@ -2,6 +2,9 @@ menu priority: 1, label: proc{ I18n.t("active_admin.dashboard") } + # TODO: Adding some information about events and organizations would likely + # be a welcome addition to this dashboard + content title: proc{ I18n.t("active_admin.dashboard") } do default_coins = 10 diff --git a/app/admin/event.rb b/app/admin/event.rb new file mode 100644 index 00000000..6f571c26 --- /dev/null +++ b/app/admin/event.rb @@ -0,0 +1,9 @@ +ActiveAdmin.register Event do + actions :index, :show, :new, :create, :edit, :update, :destroy + permit_params :organization_id, :name, :submission_deadline, :safety_deadline, :starts_at, :ends_at + + # TODO: + # the default ActiveAdmin format for entering dates is ridiculously painful. + # putting a datepicker in here of some kind will make this thing so much better. + # https://github.com/activeadmin/activeadmin/wiki/Combine-datetime-picker-with-activeadmin +end diff --git a/app/admin/membership.rb b/app/admin/membership.rb new file mode 100644 index 00000000..c0ee7105 --- /dev/null +++ b/app/admin/membership.rb @@ -0,0 +1,35 @@ +ActiveAdmin.register Membership do + actions :index, :show, :new, :create, :edit, :update + permit_params :user_id, :collective_id, :collective_type + + # TODO: currently this doesn't quite work to create memberships the way we'd like + # A first pass solution might be to have a dropdown of users by email + # and a dropdown of all Camps and Organizations combined, so that you can choose + # who to put in what collective. + + # SUPER ROUGH mockup might be: + # New Membership + # -------------- + + # User + # ---- + # Hugi (hugi@borderlands.se) + # Kristoffer (kris@borderlands.se) + + # Collective + # ---------- + # West World (organization) + # East World (organization) + # Sea Snugs (camp) + # Health + Safety wizards (camp) + + # You should be able to find a way to modify the display_name of a model in the ActiveAdmin docs + + # ALTERNATIVELY: you could create two dashboards here, + # (maybe admin/camp_memberships.rb and admin/organization_memberships.rb) + # one for adding people to organizations, and another for adding them to camps. + + # A THIRD OPTION: Skip being able to add Camp memberships here + # (that works in the app anyway), and simply make this form + # able to add memberships to organizations +end diff --git a/app/admin/organization.rb b/app/admin/organization.rb new file mode 100644 index 00000000..435988b1 --- /dev/null +++ b/app/admin/organization.rb @@ -0,0 +1,4 @@ +ActiveAdmin.register Organization do + actions :index, :show, :new, :create, :edit, :update, :destroy + permit_params :name +end diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb new file mode 100644 index 00000000..569a7111 --- /dev/null +++ b/app/controllers/events_controller.rb @@ -0,0 +1,46 @@ +class EventsController < ApplicationController + before_action :set_current_id, only: :current + before_action :set_past_events, only: :past + before_action :set_future_events, only: :future + + def show + # TODO: We should provide an option on the events#show page to view + # all past or future events, which will allow users to navigate to + # events which are not the current one + @event = Event.find(params[:id]) + end + + def current + @event = Event.current + render :show + end + + def future + @events = Event.future + render :index + end + + def past + @events = Event.past + render :index + end + + private + + def set_current_id + raise "No events created!" unless Event.current + params[:id] = Event.current.id + end + + def is_current? + @event.id == Event.current.id + end + + def set_past_events + @events = Event.past + end + + def set_future_events + @events = Event.future + end +end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb new file mode 100644 index 00000000..367179b9 --- /dev/null +++ b/app/controllers/organizations_controller.rb @@ -0,0 +1,13 @@ +class OrganizationsController < ApplicationController + def show + # TODO: More than likely you'll want to create a view of an organization, + # which displays the name of the org and perhaps lists the events they've done + # That goes here! + + # This will likely eventually look like an 'About the organization' page, which + # is visible to the public and provides additional info about the org to anyone + # who signs up + + @organization = Organization.find(params[:id]) + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c3a77751..86b39354 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,6 +4,12 @@ class UsersController < ApplicationController def me @grants = Grant.where(user_id: current_user.id).find_each @my_dreams = current_user.created_camps + # TODO: There's a possible regression here where this list may now display + # Organization memberships as well. + # I've written a relation which may be able to replace it cleanly in user.rb#18, + # so you could start off with seeing if something like the following works: + + # @memberships = current_user.collaborators.distinct.pluck(:email) - Array(current_user.email) @memberships = current_user.created_camps.joins(:memberships).joins(:users) .where('users.id != ?', current_user.id).select('users.email') diff --git a/app/models/camp.rb b/app/models/camp.rb index 38898687..84ccdd1a 100644 --- a/app/models/camp.rb +++ b/app/models/camp.rb @@ -9,7 +9,7 @@ def validate(record) class Camp < ActiveRecord::Base belongs_to :creator, class_name: 'User', foreign_key: 'user_id' - has_many :memberships, dependent: :destroy + has_many :memberships, as: :collective, dependent: :destroy has_many :users, through: :memberships has_many :images #, :dependent => :destroy has_many :grants diff --git a/app/models/event.rb b/app/models/event.rb new file mode 100644 index 00000000..378b2346 --- /dev/null +++ b/app/models/event.rb @@ -0,0 +1,16 @@ +class Event < ActiveRecord::Base + belongs_to :organization + has_many :grants + has_many :camps + + def self.current + # TODO: make sure this actually works! + # The intent here is to return the event in the database which is + # a) starting soonest + # b) not over yet + where('ends_at > ?', Time.current).order(starts_at: :asc).first + end + + scope :past, -> { where('ends_at < ?', Time.current) } + scope :future, -> { where('starts_at > ?', Time.current) } +end diff --git a/app/models/membership.rb b/app/models/membership.rb index 30528cc3..98572eb8 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -1,4 +1,7 @@ class Membership < ActiveRecord::Base - belongs_to :camp + belongs_to :collective, polymorphic: true belongs_to :user + + scope :for_camp, -> { where(collective_type: :Camp) } + scope :for_organization, -> { where(collective_type: :Organization) } end diff --git a/app/models/organization.rb b/app/models/organization.rb new file mode 100644 index 00000000..0d63303b --- /dev/null +++ b/app/models/organization.rb @@ -0,0 +1,5 @@ +class Organization < ActiveRecord::Base + has_many :events + has_many :memberships, as: :collective, dependent: :destroy + has_many :users, through: :memberships +end diff --git a/app/models/user.rb b/app/models/user.rb index c8cfd8f1..bb46eb35 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,8 +10,12 @@ class User < ActiveRecord::Base has_many :tickets has_many :memberships - has_many :camps, through: :memberships + has_many :camps, through: :memberships, source: :collective, source_type: :Camp + has_many :organizations, through: :memberships, source: :collective, source_type: :Organization has_many :created_camps, class_name: :Camp + # TODO: see if this works to replace the query in users_controller.rb#me + has_many :collaborator_memberships, through: :created_camps, source: :memberships + has_many :collaborators, through: :collaborator_memberships, source: :user schema_validations whitelist: [:id, :created_at, :updated_at, :encrypted_password] diff --git a/app/views/camps/_dont_miss_out.erb b/app/views/camps/_dont_miss_out.erb index f471e08e..c7930d81 100644 --- a/app/views/camps/_dont_miss_out.erb +++ b/app/views/camps/_dont_miss_out.erb @@ -1,3 +1,17 @@ + +<%# render partial: 'camps/dont_miss_out', locals: { camp: camp, action: :submission_deadline } %> + + +<%# + t(:'dont_miss_out.banner', { + time: distance_of_time_in_words(Time.now, camp.send(action)), + action: t(:"dont_miss_out.actions.#{action}") + }) +%> + <% lockdown_info = Lockdown.instance.next(except) if lockdown_info.present? diff --git a/app/views/camps/_list.html.erb b/app/views/camps/_list.html.erb index 2b4e1472..6cdd4886 100644 --- a/app/views/camps/_list.html.erb +++ b/app/views/camps/_list.html.erb @@ -1,5 +1,13 @@
+ + <%=t :sort_by%>: <%= filterrific_sorting_link(@filterrific, :updated_at) %> diff --git a/app/views/events/index.html.erb b/app/views/events/index.html.erb new file mode 100644 index 00000000..0c2b7cdd --- /dev/null +++ b/app/views/events/index.html.erb @@ -0,0 +1,13 @@ + + + + +<%# render partial: 'events/index', locals: { events: @events } %> diff --git a/app/views/events/show.html.erb b/app/views/events/show.html.erb new file mode 100644 index 00000000..1e93958e --- /dev/null +++ b/app/views/events/show.html.erb @@ -0,0 +1,19 @@ + +

<%= @event.name %>

+ + + + +<%# render partial: 'camps/list', locals: { camps: @event.camps } %> + + diff --git a/app/views/organizations/show.html.erb b/app/views/organizations/show.html.erb new file mode 100644 index 00000000..a1d69050 --- /dev/null +++ b/app/views/organizations/show.html.erb @@ -0,0 +1,9 @@ + +

<%= @organization.name %>

+

<%= @organization.bio %>

+ + diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb index 8aaa91b8..d143e764 100644 --- a/app/views/shared/_header.html.erb +++ b/app/views/shared/_header.html.erb @@ -21,6 +21,21 @@ <%= link_to t("top_headline_faq"), '/pages/faq-'+I18n.locale.to_s %> <%= link_to t("how_can_i_help_title"), howcanihelp_path %> + + <%# + def current_event + @event || @camp&.event + end + + then, in the view: + if current_event&.can_submit? + link_to t("register_creation_menu", new_camp_path(event_id: current_event.id)) + end + %> <% if user_signed_in? and !Rails.application.config.x.firestarter_settings['disable_open_new_dream'] and Lockdown.instance.allowed?('submit_dream') %> <%= link_to t("register_creation_menu"), new_camp_path %> <% end %> @@ -43,4 +58,4 @@
- \ No newline at end of file + diff --git a/config/initializers/initial_event.rb b/config/initializers/initial_event.rb new file mode 100644 index 00000000..0f6282ce --- /dev/null +++ b/config/initializers/initial_event.rb @@ -0,0 +1,23 @@ +# TODO: +# Write an initializer which populates a default Event and Organization if one +# does not exist in the database. This will allow us to be backwards compatible +# with existing instances. + +# Steps: +# Check to see if there are any events / organizations in the database + +# If there are no events, create one based on the following ENV variables: +# - INITIAL_EVENT_NAME +# - INITIAL_EVENT_STARTS_AT (this should be an ISO-formatted date string) +# - INITIAL_EVENT_ENDS_AT (this should be an ISO-formatted date string) + +# We'll want to pull the 'submission_deadline' and 'safety_deadline' +# from the existing 'lockdown.yml' file. + +# Assign all existing camps and grants to the newly created event + +# If there are no organizations, create one based on the following ENV variables: +# - INITIAL_ORGANIZATION_NAME + +# Assign all existing events to the newly created organization +# Assign all admin users to the newly created organization, by creating memberships for them diff --git a/config/initializers/lockdown.rb b/config/initializers/lockdown.rb index 5abcbd23..aaa5bd1c 100644 --- a/config/initializers/lockdown.rb +++ b/config/initializers/lockdown.rb @@ -1,3 +1,4 @@ +# TODO: get rid of this class class Lockdown include Singleton diff --git a/config/routes.rb b/config/routes.rb index e510a6d9..db379182 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,15 +1,22 @@ Rails.application.routes.draw do devise_for :admin_users, ActiveAdmin::Devise.config ActiveAdmin.routes(self) - - root 'camps#index' - + + root 'events#current' + devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks', registrations: 'users/registrations' } - + + resources :organizations, only: :show + resources :events, only: :show do + get :current, on: :collection + get :future, on: :collection + get :past, on: :collection + end + resources :camps, :path => 'dreams' do resources :images resources :people, only: [:show, :update] diff --git a/db/migrate/20190211174823_add_events.rb b/db/migrate/20190211174823_add_events.rb new file mode 100644 index 00000000..6b5e99ad --- /dev/null +++ b/db/migrate/20190211174823_add_events.rb @@ -0,0 +1,21 @@ +class AddEvents < ActiveRecord::Migration + def change + create_table :organizations do |t| + t.string :name + t.timestamps + end + + create_table :events do |t| + t.belongs_to :organization + t.string :name + t.datetime :submission_deadline + t.datetime :safety_deadline + t.datetime :starts_at + t.datetime :ends_at + t.timestamps + end + + add_column :memberships, :collective_type, :string, default: "Camp" + rename_column :memberships, :camp_id, :collective_id + end +end diff --git a/db/migrate/20190213093958_add_event_to_camps.rb b/db/migrate/20190213093958_add_event_to_camps.rb new file mode 100644 index 00000000..be3b428b --- /dev/null +++ b/db/migrate/20190213093958_add_event_to_camps.rb @@ -0,0 +1,5 @@ +class AddEventToCamps < ActiveRecord::Migration + def change + add_column :camps, :event_id, :integer, index: true + end +end diff --git a/db/schema.rb b/db/schema.rb index c63098a1..9d35b688 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170830102511) do +ActiveRecord::Schema.define(version: 20190213093958) do create_table "active_admin_comments", force: :cascade do |t| t.string "namespace", :index=>{:name=>"index_active_admin_comments_on_namespace"} @@ -151,6 +151,18 @@ t.string "en_subtitle", :limit=>255 t.string "dream_point_of_contact_email", :limit=>64 t.string "safety_file_comments", :limit=>4096 + t.integer "event_id", :index=>{:name=>"index_camps_on_event_id"} + end + + create_table "events", force: :cascade do |t| + t.integer "organization_id" + t.string "name" + t.datetime "submission_deadline" + t.datetime "safety_deadline" + t.datetime "starts_at" + t.datetime "ends_at" + t.datetime "created_at" + t.datetime "updated_at" end create_table "grants", force: :cascade do |t| @@ -173,10 +185,17 @@ end create_table "memberships", force: :cascade do |t| - t.datetime "created_at", :null=>false - t.datetime "updated_at", :null=>false - t.integer "user_id", :index=>{:name=>"index_memberships_on_user_id"} - t.integer "camp_id", :index=>{:name=>"index_memberships_on_camp_id"} + t.datetime "created_at", :null=>false + t.datetime "updated_at", :null=>false + t.integer "user_id", :index=>{:name=>"index_memberships_on_user_id"} + t.integer "collective_id", :index=>{:name=>"index_memberships_on_collective_id"} + t.string "collective_type", :default=>"Camp" + end + + create_table "organizations", force: :cascade do |t| + t.string "name" + t.datetime "created_at" + t.datetime "updated_at" end create_table "people", force: :cascade do |t| From b873195c94f643ba41c6a8f0fd0fe2dd89f293d7 Mon Sep 17 00:00:00 2001 From: James Kiesel Date: Sat, 16 Mar 2019 21:18:45 +1300 Subject: [PATCH 02/12] Fix error on me page --- app/controllers/users_controller.rb | 4 +--- app/views/users/me.html.erb | 2 +- db/schema.rb | 10 +++++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 585cc1cd..4e53004d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,8 +7,6 @@ def me # I've written a relation which may be able to replace it cleanly in user.rb#18, # so you could start off with seeing if something like the following works: - # @memberships = current_user.collaborators.distinct.pluck(:email) - Array(current_user.email) - @memberships = current_user.created_camps.joins(:memberships).joins(:users) - .where('users.id != ?', current_user.id).select('users.email') + @memberships = current_user.collaborators.distinct.pluck(:email) - Array(current_user.email) end end diff --git a/app/views/users/me.html.erb b/app/views/users/me.html.erb index c849edb8..1968037b 100644 --- a/app/views/users/me.html.erb +++ b/app/views/users/me.html.erb @@ -22,7 +22,7 @@ <% end %> - <% if @memberships.exists? %> + <% if @memberships.any? %>

<%=t :cocreators_list_guidetext %>

<% @memberships.each do |member| %> diff --git a/db/schema.rb b/db/schema.rb index 9d35b688..2b962209 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -227,11 +226,12 @@ t.string "tagger_type" t.string "context", :limit=>128, :index=>{:name=>"index_taggings_on_context"} t.datetime "created_at" + + t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], :name=>"taggings_idx", :unique=>true + t.index ["taggable_id", "taggable_type", "context"], :name=>"index_taggings_on_taggable_id_and_taggable_type_and_context" + t.index ["taggable_id", "taggable_type", "tagger_id", "context"], :name=>"taggings_idy" + t.index ["tagger_id", "tagger_type"], :name=>"index_taggings_on_tagger_id_and_tagger_type" end - add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], :name=>"taggings_idx", :unique=>true - add_index "taggings", ["taggable_id", "taggable_type", "context"], :name=>"index_taggings_on_taggable_id_and_taggable_type_and_context" - add_index "taggings", ["taggable_id", "taggable_type", "tagger_id", "context"], :name=>"taggings_idy" - add_index "taggings", ["tagger_id", "tagger_type"], :name=>"index_taggings_on_tagger_id_and_tagger_type" create_table "tags", force: :cascade do |t| t.string "name", :index=>{:name=>"index_tags_on_name", :unique=>true} From 381f1d29a46cfe2c7d4a11116a7196fe8f84a655 Mon Sep 17 00:00:00 2001 From: Jim Sagevid Date: Mon, 25 Mar 2019 18:17:33 +0100 Subject: [PATCH 03/12] Use datepicker fields for event datetime inputs. --- app/admin/event.rb | 17 +++++++++++++---- app/admin/membership.rb | 6 ++++++ app/models/event.rb | 2 ++ app/models/membership.rb | 2 ++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/admin/event.rb b/app/admin/event.rb index 6f571c26..ce91b284 100644 --- a/app/admin/event.rb +++ b/app/admin/event.rb @@ -2,8 +2,17 @@ actions :index, :show, :new, :create, :edit, :update, :destroy permit_params :organization_id, :name, :submission_deadline, :safety_deadline, :starts_at, :ends_at - # TODO: - # the default ActiveAdmin format for entering dates is ridiculously painful. - # putting a datepicker in here of some kind will make this thing so much better. - # https://github.com/activeadmin/activeadmin/wiki/Combine-datetime-picker-with-activeadmin + + form do |f| + f.semantic_errors + f.inputs do + f.input :name + f.input :organization, as: :select, collection: Organization.all + f.input :submission_deadline, as: :datepicker + f.input :safety_deadline, as: :datepicker + f.input :starts_at, as: :datepicker + f.input :ends_at, as: :datepicker + end + f.actions + end end diff --git a/app/admin/membership.rb b/app/admin/membership.rb index c0ee7105..56c7915a 100644 --- a/app/admin/membership.rb +++ b/app/admin/membership.rb @@ -2,6 +2,12 @@ actions :index, :show, :new, :create, :edit, :update permit_params :user_id, :collective_id, :collective_type + form do |f| + f.inputs + panel "hejsan" do + end + end + # TODO: currently this doesn't quite work to create memberships the way we'd like # A first pass solution might be to have a dropdown of users by email # and a dropdown of all Camps and Organizations combined, so that you can choose diff --git a/app/models/event.rb b/app/models/event.rb index 378b2346..e83d760a 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -3,6 +3,8 @@ class Event < ActiveRecord::Base has_many :grants has_many :camps + has_many :participants, through: :camps, source: :users + def self.current # TODO: make sure this actually works! # The intent here is to return the event in the database which is diff --git a/app/models/membership.rb b/app/models/membership.rb index 88bd7138..9f64aed7 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -1,4 +1,6 @@ class Membership < ApplicationRecord + enum collective_type: [ :Organization, :Camp ] + belongs_to :collective, polymorphic: true belongs_to :user From 6fdeba41b1fdd241bd23eb4ff63d40c2f99e2048 Mon Sep 17 00:00:00 2001 From: Jim Sagevid Date: Tue, 26 Mar 2019 10:06:50 +0100 Subject: [PATCH 04/12] Event list mockup. --- app/controllers/events_controller.rb | 4 ++++ config/routes.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 569a7111..090144ea 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -3,6 +3,10 @@ class EventsController < ApplicationController before_action :set_past_events, only: :past before_action :set_future_events, only: :future + def index + @events = Event.all.order(start_at: :desc) + end + def show # TODO: We should provide an option on the events#show page to view # all past or future events, which will allow users to navigate to diff --git a/config/routes.rb b/config/routes.rb index db379182..d4e3e2ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,7 +11,7 @@ } resources :organizations, only: :show - resources :events, only: :show do + resources :events, only: [:show, :list] do get :current, on: :collection get :future, on: :collection get :past, on: :collection From 86fd75a8d9fa693ecf1bd9376c42a393edcfba81 Mon Sep 17 00:00:00 2001 From: Jim Sagevid Date: Tue, 26 Mar 2019 15:01:20 +0100 Subject: [PATCH 05/12] Next camps under events and fix some initial routes. --- Gemfile.lock | 6 ++ app/controllers/camps_controller.rb | 8 ++ app/controllers/events_controller.rb | 23 +---- .../users/omniauth_callbacks_controller.rb | 22 ++--- app/models/camp.rb | 1 + app/models/event.rb | 6 +- app/models/grant_wallet.rb | 8 ++ app/models/user.rb | 5 +- app/views/camps/new.erb | 2 +- app/views/shared/_header.html.erb | 2 +- config/routes.rb | 18 ++-- .../20190326093403_create_grant_wallets.rb | 11 +++ db/schema.rb | 94 +++++++++---------- spec/models/grant_wallet_spec.rb | 5 + 14 files changed, 106 insertions(+), 105 deletions(-) create mode 100644 app/models/grant_wallet.rb create mode 100644 db/migrate/20190326093403_create_grant_wallets.rb create mode 100644 spec/models/grant_wallet_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 4da2ad5c..ffdcf800 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -251,6 +251,9 @@ GEM omniauth-oauth2 (1.6.0) oauth2 (~> 1.1) omniauth (~> 1.9) + omniauth-saml (1.10.1) + omniauth (~> 1.3, >= 1.3.2) + ruby-saml (~> 1.7) orm_adapter (0.5.0) os (1.0.0) paper_trail (10.2.0) @@ -344,6 +347,8 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) + ruby-saml (1.10.0) + nokogiri (>= 1.8.2) sass (3.7.3) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -458,6 +463,7 @@ DEPENDENCIES newrelic_rpm (~> 6.0.0) nokogiri omniauth-facebook + omniauth-saml paper_trail paperclip pg diff --git a/app/controllers/camps_controller.rb b/app/controllers/camps_controller.rb index 90ac40e8..c4e2fa11 100644 --- a/app/controllers/camps_controller.rb +++ b/app/controllers/camps_controller.rb @@ -8,6 +8,7 @@ class CampsController < ApplicationController before_action :ensure_admin_update!, only: [:update] before_action :ensure_grants!, only: [:update_grants] before_action :load_lang_detector, only: [:show, :index] + before_action :load_event def index end @@ -112,6 +113,13 @@ def archive private + def load_event + @event = Event.find(params[:event_id]) + if @event.nil? + redirect_to Event.most_relevant + end + end + # TODO: We can't permit! attributes like this, because it means that anyone # can update anything about a camp in any way (including the id, etc); recipe for disaster! # we'll have to go through and determine which attributes can actually be updated via diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 090144ea..5c4836fc 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -1,8 +1,4 @@ class EventsController < ApplicationController - before_action :set_current_id, only: :current - before_action :set_past_events, only: :past - before_action :set_future_events, only: :future - def index @events = Event.all.order(start_at: :desc) end @@ -29,22 +25,7 @@ def past render :index end - private - - def set_current_id - raise "No events created!" unless Event.current - params[:id] = Event.current.id - end - - def is_current? - @event.id == Event.current.id - end - - def set_past_events - @events = Event.past - end - - def set_future_events - @events = Event.future + def redirect_to_most_relevant + redirect_to Event.most_relevant end end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index df707280..45d4e56a 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -3,27 +3,17 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def facebook @user = User.from_omniauth(request.env["omniauth.auth"]) - - if @user.persisted? - sign_in_and_redirect @user, :event => :authentication - set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? - else - session["devise.facebook_data"] = request.env["omniauth.auth"] - redirect_to new_user_registration_url - end + + sign_in_and_redirect @user, :event => :authentication + set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? end def saml @user = User.from_omniauth(request.env["omniauth.auth"]) - if @user.persisted? - c = Rails.application.config.x.firestarter_settings - sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated - set_flash_message(:notice, :success, kind: c['saml_human_name']) if is_navigational_format? - else - session["devise.saml_data"] = request.env["omniauth.auth"] - redirect_to new_user_registration_url - end + c = Rails.application.config.x.firestarter_settings + sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated + set_flash_message(:notice, :success, kind: c['saml_human_name']) if is_navigational_format? end def failure diff --git a/app/models/camp.rb b/app/models/camp.rb index 4d635306..29887594 100644 --- a/app/models/camp.rb +++ b/app/models/camp.rb @@ -12,6 +12,7 @@ class Camp < ApplicationRecord include AppSettings extend AppSettings belongs_to :creator, class_name: 'User', foreign_key: 'user_id' + belongs_to :event has_many :memberships, as: :collective, dependent: :destroy has_many :users, through: :memberships diff --git a/app/models/event.rb b/app/models/event.rb index e83d760a..8ee6576d 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -5,11 +5,7 @@ class Event < ActiveRecord::Base has_many :participants, through: :camps, source: :users - def self.current - # TODO: make sure this actually works! - # The intent here is to return the event in the database which is - # a) starting soonest - # b) not over yet + def self.most_relevant where('ends_at > ?', Time.current).order(starts_at: :asc).first end diff --git a/app/models/grant_wallet.rb b/app/models/grant_wallet.rb new file mode 100644 index 00000000..a8c49ec6 --- /dev/null +++ b/app/models/grant_wallet.rb @@ -0,0 +1,8 @@ +class GrantWallet < ApplicationRecord + belongs_to :user + belongs_to :event + + def grant_to(camp) + + end +end diff --git a/app/models/user.rb b/app/models/user.rb index ae68d2de..5778a175 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -17,9 +17,12 @@ class User < ApplicationRecord schema_validations whitelist: [:id, :created_at, :updated_at, :encrypted_password] def self.from_omniauth(auth) - where(provider: auth.provider, uid: auth.uid).first_or_create! do |user| + user = where(provider: auth.provider, uid: auth.uid).first_or_create! do |user| user.email = auth.uid #.info.email facebook? user.password = Devise.friendly_token[0,20] end + + # Math auth roles to event_auth_identifier + # for each match create a new grant wallet for that event, if it doesn't already exist end end diff --git a/app/views/camps/new.erb b/app/views/camps/new.erb index 354bba21..3af7dd15 100644 --- a/app/views/camps/new.erb +++ b/app/views/camps/new.erb @@ -4,7 +4,7 @@ <% @can_edit = true %> -<%= simple_form_for @camp, :html => {:dir => I18n.t(:html_direction), id: 'createDreamForm'} do |form| %> +<%= simple_form_for([@event, @camp], :html => {:dir => I18n.t(:html_direction), id: 'createDreamForm'}) do |form| %>
<%= t("form_basics_headline") %>
diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb index c0b74bb6..4098b121 100644 --- a/app/views/shared/_header.html.erb +++ b/app/views/shared/_header.html.erb @@ -37,7 +37,7 @@ end %> <% if user_signed_in? and !app_setting('disable_open_new_dream') and Lockdown.instance.allowed?('submit_dream') %> - <%= link_to t("register_creation_menu"), new_camp_path %> + <%= link_to t("register_creation_menu"), new_event_camp_path(@event) %> <% end %> <% if !user_signed_in? %> <% if app_setting('saml_enabled') %> diff --git a/config/routes.rb b/config/routes.rb index 5adcd474..12db5f8e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,7 @@ devise_for :admin_users, ActiveAdmin::Devise.config ActiveAdmin.routes(self) - root 'events#current' + root 'events#redirect_to_most_relevant' devise_for :users, controllers: { @@ -15,15 +15,15 @@ get :current, on: :collection get :future, on: :collection get :past, on: :collection - end - resources :camps, :path => 'dreams' do - resources :images - post 'join', on: :member - post 'archive', on: :member - patch 'toggle_granting', on: :member - patch 'update_grants', on: :member - patch 'tag', on: :member + resources :camps, :path => 'dreams' do + resources :images + post 'join', on: :member + post 'archive', on: :member + patch 'toggle_granting', on: :member + patch 'update_grants', on: :member + patch 'tag', on: :member + end end get '/pages/:page' => 'pages#show' diff --git a/db/migrate/20190326093403_create_grant_wallets.rb b/db/migrate/20190326093403_create_grant_wallets.rb new file mode 100644 index 00000000..28e46cc1 --- /dev/null +++ b/db/migrate/20190326093403_create_grant_wallets.rb @@ -0,0 +1,11 @@ +class CreateGrantWallets < ActiveRecord::Migration[5.0] + def change + create_table :grant_wallets do |t| + t.integer :user_id + t.integer :event_id + t.integer :grants_left + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3e9b54d3..7e18a064 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190325151245) do +ActiveRecord::Schema.define(version: 20190325114929) do create_table "active_admin_comments", force: :cascade do |t| t.string "namespace", :index=>{:name=>"index_active_admin_comments_on_namespace"} @@ -47,36 +47,35 @@ end create_table "camps", force: :cascade do |t| - t.string "name", :limit=>64, :null=>false - t.text "subtitle", :limit=>255, :null=>false - t.string "contact_email", :limit=>64 - t.string "contact_name", :limit=>64, :null=>false - t.string "contact_phone", :limit=>64 - t.text "description", :limit=>4096 - t.text "electricity", :limit=>255 - t.text "light", :limit=>512 - t.text "fire", :limit=>512 - t.text "noise", :limit=>255 - t.text "nature", :limit=>255 - t.text "moop", :limit=>512 - t.text "plan", :limit=>1024 - t.text "cocreation", :limit=>1024 - t.text "neighbors", :limit=>512 - t.text "budgetplan", :limit=>1024 + t.string "name", :limit=>64, :null=>false + t.text "subtitle", :limit=>255, :null=>false + t.string "contact_email", :limit=>64 + t.string "contact_name", :limit=>64, :null=>false + t.string "contact_phone", :limit=>64 + t.text "description", :limit=>4096 + t.text "electricity", :limit=>255 + t.text "light", :limit=>512 + t.text "fire", :limit=>512 + t.text "noise", :limit=>255 + t.text "nature", :limit=>255 + t.text "moop", :limit=>512 + t.text "plan", :limit=>1024 + t.text "cocreation", :limit=>1024 + t.text "neighbors", :limit=>512 + t.text "budgetplan", :limit=>1024 t.integer "minbudget" t.integer "maxbudget" t.boolean "seeking_members" - t.integer "user_id", :index=>{:name=>"index_camps_on_user_id"} - t.boolean "grantingtoggle", :default=>false, :null=>false + t.integer "user_id", :index=>{:name=>"index_camps_on_user_id"} + t.boolean "grantingtoggle", :default=>false, :null=>false t.datetime "created_at" t.datetime "updated_at" - t.boolean "minfunded", :default=>false - t.boolean "fullyfunded", :default=>false - t.text "recycling", :limit=>512 + t.boolean "minfunded", :default=>false + t.boolean "fullyfunded", :default=>false + t.text "recycling", :limit=>512 t.integer "minbudget_realcurrency" t.integer "maxbudget_realcurrency" t.integer "safetybag_crewsize" -<<<<<<< HEAD t.string "safetybag_plan", :limit=>4096 t.string "safetybag_builder", :limit=>64 t.string "safetybag_safetyer", :limit=>64 @@ -171,34 +170,6 @@ t.datetime "ends_at" t.datetime "created_at" t.datetime "updated_at" -======= - t.string "safetybag_plan", :limit=>4096 - t.string "safetybag_builder", :limit=>64 - t.string "safetybag_safetyer", :limit=>64 - t.string "safetybag_mooper", :limit=>64 - t.string "safetybag_materials", :limit=>4096 - t.string "safetybag_work_in_height", :limit=>4096 - t.string "safetybag_tools", :limit=>4096 - t.string "safetybag_grounding", :limit=>4096 - t.string "safetybag_safety", :limit=>4096 - t.string "safetybag_electricity", :limit=>4096 - t.string "safetybag_daily_routine", :limit=>4096 - t.string "safetybag_other_comments", :limit=>4096 - t.string "safetybag_firstMemberName", :limit=>64 - t.string "safetybag_firstMemberEmail", :limit=>64 - t.string "safetybag_secondMemberName", :limit=>64 - t.string "safetybag_secondMemberEmail", :limit=>64 - t.boolean "active", :default=>true - t.string "about_the_artist", :limit=>1024 - t.string "website", :limit=>512 - t.boolean "is_public", :default=>true, :null=>false - t.string "google_drive_folder_path", :limit=>512 - t.string "google_drive_budget_file_path", :limit=>512 - t.string "en_name", :limit=>64 - t.string "en_subtitle", :limit=>255 - t.string "dream_point_of_contact_email", :limit=>64 - t.string "safety_file_comments", :limit=>4096 ->>>>>>> origin/master end create_table "grants", force: :cascade do |t| @@ -234,6 +205,27 @@ t.datetime "updated_at" end + create_table "people", force: :cascade do |t| + t.string "name" + t.string "email" + t.string "phone_number" + t.string "background" + t.datetime "created_at", :null=>false + t.datetime "updated_at", :null=>false + t.integer "camp_id", :null=>false, :index=>{:name=>"index_people_on_camp_id"} + t.boolean "has_ticket" + t.boolean "needs_early_arrival" + end + + create_table "people_roles", force: :cascade do |t| + t.integer "person_id", :index=>{:name=>"index_people_roles_on_person_id"} + t.integer "role_id", :index=>{:name=>"index_people_roles_on_role_id"} + end + + create_table "roles", force: :cascade do |t| + t.string "identifier" + end + create_table "taggings", force: :cascade do |t| t.integer "tag_id", :index=>{:name=>"index_taggings_on_tag_id"} t.string "taggable_type", :index=>{:name=>"index_taggings_on_taggable_type"} diff --git a/spec/models/grant_wallet_spec.rb b/spec/models/grant_wallet_spec.rb new file mode 100644 index 00000000..994fce1e --- /dev/null +++ b/spec/models/grant_wallet_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe GrantWallet, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 89df6b4dbb6d6cdf5c340c66b0e418eb7ba0f330 Mon Sep 17 00:00:00 2001 From: Jim Sagevid Date: Thu, 28 Mar 2019 11:29:56 +0100 Subject: [PATCH 06/12] Update camp routes to include event. --- app/controllers/camps_controller.rb | 20 +++++++++---------- app/views/camps/_edit_point_of_contact.haml | 2 +- .../camps/_edit_safety_file_comments.haml | 2 +- app/views/camps/_form.haml | 2 +- app/views/camps/_tags.erb | 2 +- app/views/camps/edit.html.erb | 6 +++--- app/views/camps/show.html.erb | 2 +- app/views/images/index.html.erb | 2 +- app/views/users/me.html.erb | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/controllers/camps_controller.rb b/app/controllers/camps_controller.rb index c4e2fa11..170fd2f3 100644 --- a/app/controllers/camps_controller.rb +++ b/app/controllers/camps_controller.rb @@ -26,7 +26,7 @@ def create if create_camp flash[:notice] = t('created_new_dream') - redirect_to edit_camp_path(id: @camp.id) + redirect_to edit_event_camp_path(@event, @camp) else flash.now[:notice] = "#{t:errors_str}: #{@camp.errors.full_messages.uniq.join(', ')}" render :new @@ -37,7 +37,7 @@ def create def toggle_granting @camp.toggle!(:grantingtoggle) - redirect_to camp_path(@camp) + redirect_to event_camp_path(@event, @camp) end def update_grants @@ -54,16 +54,16 @@ def update_grants flash[:error] = t(:errors_str, message: @camp.errors.full_messages.uniq.join(', ')) end - redirect_to camp_path(@camp) + redirect_to event_camp_path(@event, @camp) end def update if @camp.update_attributes camp_params if params[:done] == '1' - redirect_to camp_path(@camp) + redirect_to event_camp_path(@event, @camp) else respond_to do |format| - format.html { redirect_to edit_camp_path(@camp) } + format.html { redirect_to edit_event_camp_path(@event, @camp) } format.json { respond_with_bip(@camp) } end end @@ -80,12 +80,12 @@ def tag @camp.update_attributes(tag_list: params.require(:camp).require(:tag_list)) flash[:notice] = t(:tags_saved) - redirect_to camp_path(@camp) + redirect_to event_camp_path(@event, @camp) end def destroy @camp.destroy! - redirect_to camps_path + redirect_to event_camps_path(@event) end # Display a camp and its users @@ -108,7 +108,7 @@ def join def archive @camp.update!(active: false) - redirect_to camps_path + redirect_to event_camps_path(@event) end private @@ -131,7 +131,7 @@ def camp_params def load_camp! return if @camp = Camp.find_by(params.permit(:id)) flash[:alert] = t(:dream_not_found) - redirect_to camps_path + redirect_to event_camps_path(@event) end def ensure_admin_delete! @@ -162,7 +162,7 @@ def granted end def failure_path - camp_path(@camp) + event_camp_path(@event, @camp) end def create_camp diff --git a/app/views/camps/_edit_point_of_contact.haml b/app/views/camps/_edit_point_of_contact.haml index 33eec658..e13bcfd6 100755 --- a/app/views/camps/_edit_point_of_contact.haml +++ b/app/views/camps/_edit_point_of_contact.haml @@ -1,5 +1,5 @@ =# TODO: Having HAML and erb in the app isn't great; I'd suggest taking these haml ones out. -= simple_form_for @camp, :html => {:dir => I18n.t(:html_direction), :id => 'camp-form' } do |form| += simple_form_for [@event, @camp], :html => {:dir => I18n.t(:html_direction), :id => 'camp-form' } do |form| .combo = form.text_field :dream_point_of_contact_email, :maxlength => 64, :class => "form-control" .submit diff --git a/app/views/camps/_edit_safety_file_comments.haml b/app/views/camps/_edit_safety_file_comments.haml index 9235daca..b15fa88e 100755 --- a/app/views/camps/_edit_safety_file_comments.haml +++ b/app/views/camps/_edit_safety_file_comments.haml @@ -1,4 +1,4 @@ -= simple_form_for @camp, :html => {:dir => I18n.t(:html_direction), :id => 'camp-form' } do |form| += simple_form_for [@event, @camp], :html => {:dir => I18n.t(:html_direction), :id => 'camp-form' } do |form| .combo = form.input :safety_file_comments, :maxlength => 4096, as: 'text', :class => "form-control" .submit diff --git a/app/views/camps/_form.haml b/app/views/camps/_form.haml index 504eba54..6a087263 100755 --- a/app/views/camps/_form.haml +++ b/app/views/camps/_form.haml @@ -39,7 +39,7 @@ %br %br -= simple_form_for @camp, :html => {:dir => I18n.t(:html_direction), :id => 'camp-form' } do |form| += simple_form_for [@event, @camp], :html => {:dir => I18n.t(:html_direction), :id => 'camp-form' } do |form| = render 'dont_miss_out', except: nil .pink-div diff --git a/app/views/camps/_tags.erb b/app/views/camps/_tags.erb index a246bfa1..d9d27629 100644 --- a/app/views/camps/_tags.erb +++ b/app/views/camps/_tags.erb @@ -1,4 +1,4 @@ -<%= simple_form_for @camp, url: { action: 'tag' } do |f| %> +<%= simple_form_for [@event, @camp], url: { action: 'tag' } do |f| %>

<%= Camp.human_attribute_name(:tags) %>

diff --git a/app/views/camps/edit.html.erb b/app/views/camps/edit.html.erb index a9858ca5..faeb072d 100644 --- a/app/views/camps/edit.html.erb +++ b/app/views/camps/edit.html.erb @@ -27,9 +27,9 @@ diff --git a/app/views/camps/show.html.erb b/app/views/camps/show.html.erb index c60b2f99..63d07b4d 100644 --- a/app/views/camps/show.html.erb +++ b/app/views/camps/show.html.erb @@ -307,7 +307,7 @@

<%=t :actions_headline %>

  • - <%=t :edit_dream %> + <%=t :edit_dream %>
  • <%=t :manage_images %> diff --git a/app/views/images/index.html.erb b/app/views/images/index.html.erb index 3c44d97d..4f1c3e8c 100644 --- a/app/views/images/index.html.erb +++ b/app/views/images/index.html.erb @@ -49,7 +49,7 @@ <%=t :creation_info_headline %>
    - <%= link_to t(:back_to_dream), camp_path(@camp), class: "btn btn-info camp-button" %> + <%= link_to t(:back_to_dream), event_camp_path(@camp.event, @camp), class: "btn btn-info camp-button" %>
  • diff --git a/app/views/users/me.html.erb b/app/views/users/me.html.erb index 6ae7fd93..e35188f1 100644 --- a/app/views/users/me.html.erb +++ b/app/views/users/me.html.erb @@ -42,9 +42,9 @@

    <%=t :dreams_you_help_make %>: - <% Grant.where(user: current_user).each do |grant| %> + <% Grant.where(user: current_user).includes(camp: [:event]).each do |grant| %>

    - <%= link_to grant.camp.name, camp_path(grant.camp) %>
    + <%= link_to grant.camp.name, event_camp_path(grant.camp.event, grant.camp) %>
    <%= grant.created_at.strftime("%d/%m/%Y") %> <% grant.amount.times do |i| %> From fc329f69a1e45046d3e4c212ad70ebac725881d0 Mon Sep 17 00:00:00 2001 From: Jim Sagevid Date: Thu, 28 Mar 2019 12:54:21 +0100 Subject: [PATCH 07/12] Better routing for events. --- app/admin/event.rb | 4 +-- app/controllers/camps_controller.rb | 3 +- app/controllers/events_controller.rb | 5 ++-- app/models/event.rb | 7 +++++ app/views/camps/_card.html.erb | 4 +-- app/views/camps/edit.html.erb | 6 ++-- app/views/camps/show.html.erb | 2 +- app/views/howcanihelp/index.html.erb | 2 +- app/views/images/index.html.erb | 2 +- app/views/shared/_header.html.erb | 2 +- app/views/users/me.html.erb | 2 +- config/routes.rb | 40 ++++++++++++++----------- db/migrate/20190211174823_add_events.rb | 3 ++ db/schema.rb | 3 +- 14 files changed, 52 insertions(+), 33 deletions(-) diff --git a/app/admin/event.rb b/app/admin/event.rb index ce91b284..05fbe034 100644 --- a/app/admin/event.rb +++ b/app/admin/event.rb @@ -1,12 +1,12 @@ ActiveAdmin.register Event do actions :index, :show, :new, :create, :edit, :update, :destroy - permit_params :organization_id, :name, :submission_deadline, :safety_deadline, :starts_at, :ends_at - + permit_params :organization_id, :name, :slug, :submission_deadline, :safety_deadline, :starts_at, :ends_at form do |f| f.semantic_errors f.inputs do f.input :name + f.input :slug f.input :organization, as: :select, collection: Organization.all f.input :submission_deadline, as: :datepicker f.input :safety_deadline, as: :datepicker diff --git a/app/controllers/camps_controller.rb b/app/controllers/camps_controller.rb index e986cdac..cbd328bb 100644 --- a/app/controllers/camps_controller.rb +++ b/app/controllers/camps_controller.rb @@ -15,6 +15,7 @@ def index def new @camp = Camp.new + @camp.event = @event end def edit @@ -129,7 +130,7 @@ def archive private def load_event - @event = Event.find(params[:event_id]) + @event = Event.find_by(slug: params[:event_slug]) if @event.nil? redirect_to Event.most_relevant end diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 5c4836fc..f11edeb9 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -7,7 +7,8 @@ def show # TODO: We should provide an option on the events#show page to view # all past or future events, which will allow users to navigate to # events which are not the current one - @event = Event.find(params[:id]) + @event = Event.find_by(slug: params[:slug]) + redirect_to events_path if @event.nil? end def current @@ -26,6 +27,6 @@ def past end def redirect_to_most_relevant - redirect_to Event.most_relevant + redirect_to event_camps_path(event_slug: Event.most_relevant.slug) end end diff --git a/app/models/event.rb b/app/models/event.rb index 8ee6576d..31941748 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,4 +1,6 @@ class Event < ActiveRecord::Base + SLUG_FORMAT = /([[:lower:]]|[0-9]+-?[[:lower:]])(-[[:lower:]0-9]+|[[:lower:]0-9])*/ + belongs_to :organization has_many :grants has_many :camps @@ -11,4 +13,9 @@ def self.most_relevant scope :past, -> { where('ends_at < ?', Time.current) } scope :future, -> { where('starts_at > ?', Time.current) } + + validates :slug, + presence: true, + uniqueness: true, + format: {with: Regexp.new('\A' + SLUG_FORMAT.source + '\z')} end diff --git a/app/views/camps/_card.html.erb b/app/views/camps/_card.html.erb index 1c33e656..13ec7d68 100644 --- a/app/views/camps/_card.html.erb +++ b/app/views/camps/_card.html.erb @@ -1,10 +1,10 @@

    <% if user_signed_in? %> - <%= link_to toggle_favorite_camp_path(:id => camp.id), method: :patch, class: (camp.favorite_users.include?(current_user) ? 'favorite-button starred' : 'favorite-button'), id: 'favorite-button', :remote => true do %> + <%= link_to toggle_favorite_event_camp_path(event_slug: @event.slug, id: camp.id), method: :patch, class: (camp.favorite_users.include?(current_user) ? 'favorite-button starred' : 'favorite-button'), id: 'favorite-button', :remote => true do %> <% end %> <% end %> - +
    diff --git a/app/views/camps/edit.html.erb b/app/views/camps/edit.html.erb index faeb072d..cde76640 100644 --- a/app/views/camps/edit.html.erb +++ b/app/views/camps/edit.html.erb @@ -27,9 +27,9 @@ diff --git a/app/views/camps/show.html.erb b/app/views/camps/show.html.erb index 9bc39d56..9bc4dd25 100644 --- a/app/views/camps/show.html.erb +++ b/app/views/camps/show.html.erb @@ -242,7 +242,7 @@

    <%=t :actions_headline %>

  • - <%=t :edit_dream %> + <%=t :edit_dream %>
  • <%=t :manage_images %> diff --git a/app/views/howcanihelp/index.html.erb b/app/views/howcanihelp/index.html.erb index 5f526c9a..b6bb9773 100644 --- a/app/views/howcanihelp/index.html.erb +++ b/app/views/howcanihelp/index.html.erb @@ -42,7 +42,7 @@ <% @camps.each do |camp| %>
    - +
    diff --git a/app/views/images/index.html.erb b/app/views/images/index.html.erb index 0f6b3634..8faaf7fc 100644 --- a/app/views/images/index.html.erb +++ b/app/views/images/index.html.erb @@ -43,7 +43,7 @@ <%=t :creation_info_headline %>
    - <%= link_to t(:back_to_dream), event_camp_path(@camp.event, @camp), class: "btn btn-info camp-button" %> + <%= link_to t(:back_to_dream), event_camp_path(event_slug: @event.slug, id: @camp.id), class: "btn btn-info camp-button" %>
    \ No newline at end of file diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb index 4098b121..04c5f29f 100644 --- a/app/views/shared/_header.html.erb +++ b/app/views/shared/_header.html.erb @@ -37,7 +37,7 @@ end %> <% if user_signed_in? and !app_setting('disable_open_new_dream') and Lockdown.instance.allowed?('submit_dream') %> - <%= link_to t("register_creation_menu"), new_event_camp_path(@event) %> + <%= link_to t("register_creation_menu"), new_event_camp_path(event_slug: @event.slug) %> <% end %> <% if !user_signed_in? %> <% if app_setting('saml_enabled') %> diff --git a/app/views/users/me.html.erb b/app/views/users/me.html.erb index 93bb4cf6..174bc639 100644 --- a/app/views/users/me.html.erb +++ b/app/views/users/me.html.erb @@ -47,7 +47,7 @@ <%=t :dreams_you_help_make %>: <% Grant.where(user: current_user).includes(camp: [:event]).each do |grant| %>

    - <%= link_to grant.camp.name, event_camp_path(grant.camp.event, grant.camp) %>
    + <%= link_to grant.camp.name, event_camp_path(event_slug: grant.camp.event.slug, id: grant.camp.id) %>
    <%= grant.created_at.strftime("%d/%m/%Y") %> <% grant.amount.times do |i| %> diff --git a/config/routes.rb b/config/routes.rb index 67ee458f..ece42462 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do if Rails.env.development? - mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql" + #mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql" end post "/graphql", to: "graphql#execute" @@ -16,26 +16,32 @@ } resources :organizations, only: :show - resources :events, only: [:show, :list] do - get :current, on: :collection - get :future, on: :collection - get :past, on: :collection - - resources :camps, :path => 'dreams' do - resources :images - resources :safety_sketches - post 'join', on: :member - post 'archive', on: :member - patch 'toggle_favorite', on: :member - patch 'toggle_granting', on: :member - patch 'update_grants', on: :member - patch 'tag', on: :member - end - end get '/pages/:page' => 'pages#show' get '/me' => 'users#me' get '/howcanihelp' => 'howcanihelp#index' + + constraints(slug: Event::SLUG_FORMAT, id: /\d+/) do + resources :events, param: :slug, only: [:show, :index], path: "" do + get :current, on: :collection + get :future, on: :collection + get :past, on: :collection + + get '', to: 'camps#index', as: 'camps' + resources :camps, path: 'dreams', except: [:index] do + resources :images + resources :safety_sketches + post 'join', on: :member + post 'archive', on: :member + patch 'toggle_favorite', on: :member + patch 'toggle_granting', on: :member + patch 'update_grants', on: :member + patch 'tag', on: :member + end + end + end + + get '*unmatched_route' => 'application#not_found' end \ No newline at end of file diff --git a/db/migrate/20190211174823_add_events.rb b/db/migrate/20190211174823_add_events.rb index 6b5e99ad..d6f5c518 100644 --- a/db/migrate/20190211174823_add_events.rb +++ b/db/migrate/20190211174823_add_events.rb @@ -8,6 +8,7 @@ def change create_table :events do |t| t.belongs_to :organization t.string :name + t.string :slug t.datetime :submission_deadline t.datetime :safety_deadline t.datetime :starts_at @@ -15,6 +16,8 @@ def change t.timestamps end + add_index :events, :slug, unique: true + add_column :memberships, :collective_type, :string, default: "Camp" rename_column :memberships, :camp_id, :collective_id end diff --git a/db/schema.rb b/db/schema.rb index eb0cd1ef..7e0ad920 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190327152450) do +ActiveRecord::Schema.define(version: 20190328104245) do create_table "active_admin_comments", force: :cascade do |t| t.string "namespace", :index=>{:name=>"index_active_admin_comments_on_namespace"} @@ -98,6 +98,7 @@ t.datetime "ends_at" t.datetime "created_at" t.datetime "updated_at" + t.string "slug" end create_table "favorites", force: :cascade do |t| From 573b9efb6bfd824c838cf8df156d4f07d4cf9014 Mon Sep 17 00:00:00 2001 From: Jim Sagevid Date: Thu, 28 Mar 2019 13:28:52 +0100 Subject: [PATCH 08/12] Re-remove haml form. --- app/views/camps/_edit_point_of_contact.haml | 6 - .../camps/_edit_safety_file_comments.haml | 5 - app/views/camps/_form.haml | 321 ------------------ 3 files changed, 332 deletions(-) delete mode 100644 app/views/camps/_edit_point_of_contact.haml delete mode 100644 app/views/camps/_edit_safety_file_comments.haml delete mode 100644 app/views/camps/_form.haml diff --git a/app/views/camps/_edit_point_of_contact.haml b/app/views/camps/_edit_point_of_contact.haml deleted file mode 100644 index e13bcfd6..00000000 --- a/app/views/camps/_edit_point_of_contact.haml +++ /dev/null @@ -1,6 +0,0 @@ -=# TODO: Having HAML and erb in the app isn't great; I'd suggest taking these haml ones out. -= simple_form_for [@event, @camp], :html => {:dir => I18n.t(:html_direction), :id => 'camp-form' } do |form| - .combo - = form.text_field :dream_point_of_contact_email, :maxlength => 64, :class => "form-control" - .submit - = form.submit t(:update_point_of_contact), id: 'done-camp', class: 'btn btn-success' diff --git a/app/views/camps/_edit_safety_file_comments.haml b/app/views/camps/_edit_safety_file_comments.haml deleted file mode 100644 index b15fa88e..00000000 --- a/app/views/camps/_edit_safety_file_comments.haml +++ /dev/null @@ -1,5 +0,0 @@ -= simple_form_for [@event, @camp], :html => {:dir => I18n.t(:html_direction), :id => 'camp-form' } do |form| - .combo - = form.input :safety_file_comments, :maxlength => 4096, as: 'text', :class => "form-control" - .submit - = form.submit t(:dream_safety_file_comments_update), id: 'done-camp', class: 'btn btn-success' diff --git a/app/views/camps/_form.haml b/app/views/camps/_form.haml deleted file mode 100644 index 6a087263..00000000 --- a/app/views/camps/_form.haml +++ /dev/null @@ -1,321 +0,0 @@ -:javascript - // Iterate checkboxes with data-show attributes and show/hide their target divs - $(document).ready(function() { - $("[data-show]").change((e) => { - let target = e.target.attributes['data-show'].value; - $(target).fadeToggle(); - }); - - $("[data-show]").each((i,e) => { - let target = e.attributes['data-show'].value; - if ($(e).is(':checked')) { - $(target).show(); - }else { - $(target).hide(); - } - }); - - }); - -- if !app_setting("disable_edit_safetybag") or (current_user && (current_user.guide || current_user.admin)) - :javascript - $(function() { $(".hide_show_safetyfile").click(function(){ - if($('.safetybar-info').css('display') === "none") { - $('.safetybar-info').fadeIn(); - }else { - $('.safetybar-info').fadeOut(); - } - })}); -- else - :javascript - $(function() { $(".hide_show_safetyfile").click(function(){ - alert( "Safety file is currrently disabled" ); - })}); - -:javascript - $(function() { - $("textarea").autoGrow(); - }); -%br -%br - -= simple_form_for [@event, @camp], :html => {:dir => I18n.t(:html_direction), :id => 'camp-form' } do |form| - = render 'dont_miss_out', except: nil - - .pink-div - = t("press_to_edit") - - .header-heading - = t("form_basics_headline") - - .header-safetybag-description - - if app_setting("safetybag") - = t("form_basics_safety_bag") - - .combo#name - = form.label t("form_dream_name_label") - .field-description - = t("form_dream_name_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :name, html_attrs: {maxlength: 64, class: "form-control"} - - - if app_setting("multi_lang_support") - .combo - = form.label t("form_dream_name_en_label") - %blockquote - = best_in_place_if @can_edit,@camp, :en_name, html_attrs: {maxlength: 64, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo#subtitle - = form.label t("form_subtitle_label") - .field-description - = t("form_subtitle_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :subtitle, html_attrs: {maxlength: 255, class: "form-control"},as: :textarea, display_with: :simple_format - - - if app_setting("multi_lang_support") - .combo - = form.label t("form_subtitle_en_label") - %blockquote - = best_in_place_if @can_edit, @camp, :en_subtitle, html_attrs: {maxlength: 255, class: "form-control"},as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) - - .combo#contact_name - = form.label t("form_creator_name_label") - .field-description - = t("form_creator_name_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :contact_name, html_attrs: {maxlength: 64, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo#visability - = form.label t("form_dream_visability") - - = form.radio_button :is_public, true - = form.label t("form_dream_visability_yes") - = form.radio_button :is_public, false - = form.label t("form_dream_visability_no") - %br - = t("form_dream_visability_guidetext_html") - - .combo#contact_phone - - if app_setting("contact_phone") - = form.label t("form_contact_phone_label") - - .field-description - = t("form_contact_phone_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :contact_phone, html_attrs: {maxlength: 64, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo - = form.label t("form_about_the_artist_label") - %blockquote - = best_in_place_if @can_edit, @camp, :about_the_artist, html_attrs: {maxlength: 1024, class: "form-control"},as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) - - .combo - = form.label t("form_dream_website_label") - %blockquote - = best_in_place_if @can_edit, @camp, :website, html_attrs: {maxlength: 512, class: "form-control"}, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) - - .combo#description - - if app_setting("description") - = form.label t("form_description_label") - .field-description - = t("form_description_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :description, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) - - .combo#electricity - - if app_setting("electricity") - = form.label t("form_electricity_label") - .field-description - = t("form_electricity_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :electricity, html_attrs: {maxlength: 256, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) - - .combo#fire - - if app_setting("fire") - = form.label t("form_fire_label") - .field-description - = t("form_fire_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :fire, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) - - .combo#noise - - if app_setting("noise") - = form.label t("form_noise_label") - .field-description - = t("form_noise_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :noise, html_attrs: {maxlength: 256, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo#nature - - if app_setting("nature") - = form.label t("form_nature_label") - .field-description - = t("form_nature_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :nature, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) - - .combo#recycling - - if app_setting("recycling") - = form.label t("form_recycling_label") - .field-description - = t("form_recycling_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :recycling, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) - - .combo#light - - if app_setting("light") - = form.label t("form_light_label") - .field-description - = t("form_light_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :light, html_attrs: {maxlength: 512, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo#moop - - if app_setting("moop") - = form.label t("form_moop_label") - .field-description - = t("form_moop_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :moop, html_attrs: {maxlength: 1024, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) - - .combo#cocreation - - if app_setting("cocreation") - = form.label t("form_cocreation_label") - .field-description - = t("form_cocreation_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :cocreation, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) - - - .combo#neighbors - - if app_setting("neighbors") - = form.label t("form_neighbors_label") - .field-description - = t("form_neighbors_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :neighbors, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) - - - if app_setting("safetybag") - - .header-heading.safetybag-header - = t("form_safetybag_headline") - - %br - %br - .btn.btn-success.hide_show_safetyfile - = t("form_safetybag_show_hide") - - .safetybar-info.hideme - - .combo.safety - = form.label t("form_safetybag_plan_label") - .field-description - = t("form_safetybag_plan_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :safetybag_plan, html_attrs: {maxlength: 4096, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo.safety - = form.label t("form_safetybag_materials_label") - .field-description - = t("form_safetybag_materials_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :safetybag_materials, html_attrs: {maxlength: 4096, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo.safety - = form.label t("form_safetybag_work_in_height_label") - .field-description - = t("form_safetybag_work_in_height_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :safetybag_work_in_height, html_attrs: {maxlength: 4096, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo.safety - = form.label t("form_safetybag_tools_label") - .field-description - = t("form_safetybag_tools_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :safetybag_tools, html_attrs: {maxlength: 4096, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo.safety - = form.label t("form_safetybag_grounding_label") - .field-description - = t("form_safetybag_grounding_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :safetybag_grounding, html_attrs: {maxlength: 4096, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo.safety - = form.label t("form_safetybag_safety_label") - .field-description - = t("form_safetybag_safety_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :safetybag_safety, html_attrs: {maxlength: 4096, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo.safety - = form.label t("form_safetybag_electricity_label") - .field-description - = t("form_safetybag_electricity_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :safetybag_electricity, html_attrs: {maxlength: 4096, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo.safety - = form.label t("form_safetybag_daily_routine_label") - .field-description - = t("form_safetybag_daily_routine_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :safetybag_daily_routine, html_attrs: {maxlength: 4096, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - .combo.safety - = form.label t("form_safetybag_other_comments_label") - .field-description - = t("form_safetybag_other_comments_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :safetybag_other_comments, html_attrs: {maxlength: 4096, class: "form-control"}, place_holder: t(:form_click_to_edit_html) - - - %br - %div.safetytext - = t("form_safetybag_remember_sketch") - - %br - .combo - = t("form_safetybag_needs_to_fill") - - - if app_setting("granting") - %br - %br - .header-heading - = t("form_artgrants_headline") - - .combo#artgrants - - if app_setting("granting") - = t("form_artgrants_text_html") - - - if app_setting("granting") and !app_setting('disable_edit_budget') - .combo#minbudget_realcurrency - = form.label t("form_minigrants_realcurrency_label") - .field-description - = t("form_minigrants_realcurrency_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :minbudget_realcurrency, html_attrs: {maxlength: 6, class: "form-control"}, place_holder: t(:form_click_to_edit_html), display_with: :number_to_currency, :helper_options => {:unit => "", precision:0} - - - if app_setting("granting") and !app_setting('disable_edit_budget') - .combo#maxbudget_realcurrency - = form.label t("form_maxigrants_realcurrency_label") - .field-description - = t("form_maxigrants_realcurrency_guidetext_html") - %blockquote - = best_in_place_if @can_edit, @camp, :maxbudget_realcurrency, html_attrs: {maxlength: 6, class: "form-control"}, place_holder: t(:form_click_to_edit_html), display_with: :number_to_currency, :helper_options => {:unit => "", precision:0} - - - if app_setting("granting") and app_setting("budgeting") - .combo - = form.label t("budget_label") - .field-description - = t("form_budgetplan_guidetext_html") - #responsibles - = form.fields_for :budget_items do |budget_item| - = render 'budget_item_fields', :f => budget_item, :camp_id => @camp.id - - - if @can_edit - .row.links.col-xs-12 - = link_to_add_association t('add_new_budget_item'), form, :budget_items, render_options: { locals: { camp_id: @camp.id } }, class: 'btn btn-success', id: 'add-new-person' - %br - %br \ No newline at end of file From e6c6891080591a2aa94bd9ed11eff0979fd3432b Mon Sep 17 00:00:00 2001 From: Jim Sagevid Date: Thu, 28 Mar 2019 15:33:16 +0100 Subject: [PATCH 09/12] Fixed a route issue & redirects for bad urls --- app/controllers/camps_controller.rb | 3 ++- app/controllers/events_controller.rb | 9 +++++++-- config/routes.rb | 9 +++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/controllers/camps_controller.rb b/app/controllers/camps_controller.rb index 4934922a..146fa642 100644 --- a/app/controllers/camps_controller.rb +++ b/app/controllers/camps_controller.rb @@ -141,8 +141,9 @@ def archive def load_event @event = Event.find_by(slug: params[:event_slug]) + @event ||= Event.most_relevant if @event.nil? - redirect_to Event.most_relevant + redirect_to events_path end end diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index f11edeb9..fb079ed8 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -1,6 +1,6 @@ class EventsController < ApplicationController def index - @events = Event.all.order(start_at: :desc) + @events = Event.all.order(starts_at: :desc) end def show @@ -27,6 +27,11 @@ def past end def redirect_to_most_relevant - redirect_to event_camps_path(event_slug: Event.most_relevant.slug) + e = Event.most_relevant + unless e.nil? + redirect_to event_camps_path(event_slug: e.slug) + else + redirect_to events_path + end end end diff --git a/config/routes.rb b/config/routes.rb index 20d732d2..2040f157 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,10 +22,11 @@ get '/howcanihelp' => 'howcanihelp#index' constraints(slug: Event::SLUG_FORMAT, id: /\d+/) do - resources :events, param: :slug, only: [:show, :index], path: "" do - get :current, on: :collection - get :future, on: :collection - get :past, on: :collection + get 'events', to: 'events#index', as: 'events' + resources :events, param: :slug, only: [:show], path: "" do + get 'current', on: :collection + get 'future', on: :collection + get 'past', on: :collection get '', to: 'camps#index', as: 'camps' resources :camps, path: 'dreams', except: [:index] do From bf633e371720277b1dba1814a4f5c83252c07c67 Mon Sep 17 00:00:00 2001 From: Jim Sagevid Date: Thu, 28 Mar 2019 18:36:11 +0100 Subject: [PATCH 10/12] Per-event granting wip. --- app/controllers/camps_controller.rb | 16 ++++++---------- app/models/camp.rb | 4 +++- app/models/grant_wallet.rb | 15 +++++++++++++-- app/models/user.rb | 18 +++++++++++++++--- config/initializers/initial_event.rb | 11 +++++++++++ 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/app/controllers/camps_controller.rb b/app/controllers/camps_controller.rb index 146fa642..a4b1f6f8 100644 --- a/app/controllers/camps_controller.rb +++ b/app/controllers/camps_controller.rb @@ -41,15 +41,9 @@ def toggle_granting end def update_grants - @camp.grants.build(user: current_user, amount: granted) - @camp.assign_attributes( - minfunded: (@camp.grants_received + granted) >= @camp.minbudget, - fullyfunded: (@camp.grants_received + granted) >= @camp.maxbudget - ) - - if @camp.save - current_user.update(grants: current_user.grants - granted) - flash[:notice] = t(:thanks_for_sending, grants: granted) + actually_granted, ok = current_user.wallet_for(@event).grant_to(@camp, granted) + if ok + flash[:notice] = t(:thanks_for_sending, grants: actually_granted) else flash[:error] = t(:errors_str, message: @camp.errors.full_messages.uniq.join(', ')) end @@ -174,8 +168,10 @@ def ensure_admin_update! end def ensure_grants! + grants_left = current_user.grants_left_for(@event) + assert(@camp.maxbudget, :dream_need_to_have_max_budget) || - assert(current_user.grants >= granted, :security_more_grants, granted: granted, current_user_grants: current_user.grants) || + assert(grants_left >= granted, :security_more_grants, granted: granted, current_user_grants: grants_left) || assert(granted > 0, :cant_send_less_then_one) || assert( current_user.admin || (@camp.grants.where(user: current_user).sum(:amount) + granted <= app_setting('max_grants_per_user_per_dream')), diff --git a/app/models/camp.rb b/app/models/camp.rb index b130b598..1cdcb1c6 100644 --- a/app/models/camp.rb +++ b/app/models/camp.rb @@ -20,7 +20,9 @@ class Camp < ApplicationRecord has_many :favorite_users, through: :favorites, source: :user has_many :images #, :dependent => :destroy has_many :safety_sketches - has_many :grants + + has_many :all_grants, class_name: "Grant" + has_many :budget_items has_many :safety_items diff --git a/app/models/grant_wallet.rb b/app/models/grant_wallet.rb index a8c49ec6..474a585d 100644 --- a/app/models/grant_wallet.rb +++ b/app/models/grant_wallet.rb @@ -2,7 +2,18 @@ class GrantWallet < ApplicationRecord belongs_to :user belongs_to :event - def grant_to(camp) - + def grant_to(camp, requested_grants) + num_grants = [requested_grants, self.grants_left, app_setting('max_grants_per_user_per_dream')].min + + camp.grants.build(user: self.user, amount: num_grants) + camp.assign_attributes( + minfunded: (camp.grants_received + num_grants) >= @camp.minbudget, + fullyfunded: (camp.grants_received + num_grants) >= @camp.maxbudget + ) + + return 0, false unless camp.save + + self.assign_attributes!(grants_left: self.grants_left - num_grants) + return num_grants, true end end diff --git a/app/models/user.rb b/app/models/user.rb index aad57991..556edb97 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,6 +12,8 @@ class User < ApplicationRecord has_many :favorites has_many :favorite_camps, through: :favorites, source: :camp has_many :created_camps, class_name: :Camp + + has_many :grant_wallets # TODO: see if this works to replace the query in users_controller.rb#me has_many :collaborator_memberships, through: :created_camps, source: :memberships @@ -21,9 +23,9 @@ class User < ApplicationRecord def self.from_omniauth(auth) u = where(provider: auth.provider, uid: auth.uid).first_or_create! do |u| - user.email = auth.uid # .info.email TODO for supporting other things than keycloak - user.password = Devise.friendly_token[0,20] - + u.email = auth.uid # .info.email TODO for supporting other things than keycloak + u.password = Devise.friendly_token[0,20] + puts ">>>>>>>>>>>>>>>>", auth.extra.raw_info.all # Omniauth doesn't know the keycloak schema u.name = auth.extra.raw_info.all["urn:oid:2.5.4.42"][0] # Last name : urn:oid:2.5.4.4 @@ -32,4 +34,14 @@ def self.from_omniauth(auth) # either loomio picture or gravatar end end + + def wallet_for(event) + grant_wallets.find_or_create_by(event: event, user: self) do |w| + w.grants_left = ENV['DEFAULT_HEARTS'] || 10 + end + end + + def grants_left_for(event) + wallet_for(event).grants_left + end end diff --git a/config/initializers/initial_event.rb b/config/initializers/initial_event.rb index 0f6282ce..230b86f7 100644 --- a/config/initializers/initial_event.rb +++ b/config/initializers/initial_event.rb @@ -21,3 +21,14 @@ # Assign all existing events to the newly created organization # Assign all admin users to the newly created organization, by creating memberships for them + +# if defined?(Event) && defined?(Organization) +# return unless Event.all.any? && Organization.all.any? +# +# lockdown_data = Rails.application.config_for(:lockdown) +# name = ENV['INITIAL_EVENT_NAME'] || "" +# starts_at = ENV['INITIAL_EVENT_STARTS_AT'] || "" +# ends_at = ENV['INITIAL_EVENT_ENDS_AT'] || "" +# +# raise "" if name.empty? or start_at.empty? or end +# end \ No newline at end of file From bbda179a9411a940b44ba9e90a2b9aa4524d35dc Mon Sep 17 00:00:00 2001 From: Jim Sagevid Date: Fri, 29 Mar 2019 12:28:36 +0100 Subject: [PATCH 11/12] Update routes again to make url helpers nicer. --- app/assets/javascripts/camps.js.erb | 6 ++-- app/controllers/camps_controller.rb | 22 ++++++------- app/controllers/events_controller.rb | 4 +-- app/controllers/images_controller.rb | 13 +++++--- app/models/camp.rb | 2 +- app/models/event.rb | 10 +++++- app/models/user.rb | 2 +- app/views/camps/_card.html.erb | 4 +-- app/views/camps/_donate_form.html.erb | 7 ++-- app/views/camps/_form.html.erb | 42 ++++++++++++------------ app/views/camps/_tags.html.erb | 4 +-- app/views/camps/edit.html.erb | 6 ++-- app/views/camps/new.html.erb | 2 +- app/views/camps/show.html.erb | 18 +++++----- app/views/howcanihelp/index.html.erb | 2 +- app/views/images/index.html.erb | 6 ++-- app/views/safety_sketches/index.html.erb | 3 +- app/views/shared/_header.html.erb | 6 ++-- app/views/users/me.html.erb | 7 ++-- config/routes.rb | 39 ++++++++++------------ 20 files changed, 109 insertions(+), 96 deletions(-) diff --git a/app/assets/javascripts/camps.js.erb b/app/assets/javascripts/camps.js.erb index c96dc3d7..cc88f4ab 100644 --- a/app/assets/javascripts/camps.js.erb +++ b/app/assets/javascripts/camps.js.erb @@ -58,8 +58,8 @@ $(document).ready(function() { $.ajax({ url: url, - type: 'POST', - data: {method:'_patch', 'camp[tag]': tag, authenticity_token:token}, + type: 'DELETE', + data: {_method:'DELETE', 'camp[tag]': tag, authenticity_token:token}, success: function(data) { refreshTags(data); } @@ -76,7 +76,7 @@ $(document).ready(function() { $.ajax({ url: url, type: 'POST', - data: {method:'_patch', 'camp[tag_list]': tags, authenticity_token:token}, + data: {'camp[tag_list]': tags, authenticity_token:token}, success: function(data) { refreshTags(data); } diff --git a/app/controllers/camps_controller.rb b/app/controllers/camps_controller.rb index e5086d51..89d1c197 100644 --- a/app/controllers/camps_controller.rb +++ b/app/controllers/camps_controller.rb @@ -4,12 +4,12 @@ class CampsController < ApplicationController before_action :apply_filters, only: :index before_action :authenticate_user!, except: [:show, :index] + before_action :load_event! before_action :load_camp!, except: [:index, :new, :create] before_action :ensure_admin_delete!, only: [:destroy, :archive] before_action :ensure_admin_update!, only: [:update] before_action :ensure_grants!, only: [:update_grants] before_action :load_lang_detector, only: [:show, :index] - before_action :load_event def index end @@ -139,12 +139,9 @@ def archive private - def load_event - @event = Event.find_by(slug: params[:event_slug]) - @event ||= Event.most_relevant - if @event.nil? - redirect_to events_path - end + def load_event! + @event = Event.find(params[:event_id]) + not_found if @event.nil? end # TODO: We can't permit! attributes like this, because it means that anyone @@ -156,9 +153,12 @@ def camp_params end def load_camp! - return if @camp = Camp.find_by(params.permit(:id)) - flash[:alert] = t(:dream_not_found) - redirect_to event_camps_path(@event) + @camp = Camp.includes(:event).find(params[:id]) + + if @camp.nil? or @camp.event.id != @event.id + flash[:alert] = t(:dream_not_found) + redirect_to event_camps_path(@event) + end end def ensure_admin_delete! @@ -180,7 +180,7 @@ def ensure_grants! assert(grants_left >= granted, :security_more_grants, granted: granted, current_user_grants: grants_left) || assert(granted > 0, :cant_send_less_then_one) || assert( - current_user.admin || (@camp.grants.where(user: current_user).sum(:amount) + granted <= app_setting('max_grants_per_user_per_dream')), + current_user.admin || (@camp.grants_for(@event).where(user: current_user).sum(:amount) + granted <= app_setting('max_grants_per_user_per_dream')), :exceeds_max_grants_per_user_for_this_dream, max_grants_per_user_per_dream: app_setting('max_grants_per_user_per_dream') ) diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index fb079ed8..178d71ef 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -7,7 +7,7 @@ def show # TODO: We should provide an option on the events#show page to view # all past or future events, which will allow users to navigate to # events which are not the current one - @event = Event.find_by(slug: params[:slug]) + @event = Event.find(params[:id]) redirect_to events_path if @event.nil? end @@ -29,7 +29,7 @@ def past def redirect_to_most_relevant e = Event.most_relevant unless e.nil? - redirect_to event_camps_path(event_slug: e.slug) + redirect_to event_camps_path(e) else redirect_to events_path end diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index b5360226..a5b31d60 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -8,7 +8,7 @@ def index def create if Image.create(image_params) - redirect_to camp_images_path(params.permit(:camp_id)) + redirect_to event_camp_images_path(@event, @camp) else render action: :index end @@ -16,13 +16,18 @@ def create def destroy @camp.images.find(params[:id]).destroy! - redirect_to camp_images_path(params.permit(:camp_id)) + redirect_to event_camp_images_path(@event, @camp) end private def load_camp! - @camp = Camp.find(params[:camp_id]) + @event = Event.find(params[:event_id]) + not_found if @event.nil? if @event.nil? + + @camp = Camp.includes(:event).find(params[:camp_id]) + redirect_to event_camps_path(@event) if @camp.nil? or @camp.event.id != @event.id + assert(current_user == @camp.creator || current_user.admin, :security_cant_change_images_you_dont_own) end @@ -31,7 +36,7 @@ def ensure_image! end def failure_path - camp_images_path(params.permit(:camp_id)) + event_camp_images_path(@event, @camp) end def image_params diff --git a/app/models/camp.rb b/app/models/camp.rb index 5d493b90..86452fb7 100644 --- a/app/models/camp.rb +++ b/app/models/camp.rb @@ -21,7 +21,7 @@ class Camp < ApplicationRecord has_many :images #, :dependent => :destroy has_many :safety_sketches - has_many :all_grants, class_name: "Grant" + has_many :grants, -> { where(event: self.event) } has_many :budget_items has_many :safety_items diff --git a/app/models/event.rb b/app/models/event.rb index 31941748..c98ba4f0 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -8,7 +8,7 @@ class Event < ActiveRecord::Base has_many :participants, through: :camps, source: :users def self.most_relevant - where('ends_at > ?', Time.current).order(starts_at: :asc).first + @@most_relevant ||= where('ends_at > ?', Time.current).order(starts_at: :asc).first end scope :past, -> { where('ends_at < ?', Time.current) } @@ -18,4 +18,12 @@ def self.most_relevant presence: true, uniqueness: true, format: {with: Regexp.new('\A' + SLUG_FORMAT.source + '\z')} + + def to_param + slug + end + + def self.find(input) + input.to_i == 0 ? find_by_slug(input) : super + end end diff --git a/app/models/user.rb b/app/models/user.rb index dd5da5db..36f246d3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -25,7 +25,7 @@ def self.from_omniauth(auth) u = where(provider: auth.provider, uid: auth.uid).first_or_create! do |u| u.email = auth.uid # .info.email TODO for supporting other things than keycloak u.password = Devise.friendly_token[0,20] - puts ">>>>>>>>>>>>>>>>", auth.extra.raw_info.all + # Omniauth doesn't know the keycloak schema u.name = auth.extra.raw_info.all.fetch("urn:oid:2.5.4.42", []).fetch(0, "") # Last name : urn:oid:2.5.4.4 diff --git a/app/views/camps/_card.html.erb b/app/views/camps/_card.html.erb index 13ec7d68..490682b1 100644 --- a/app/views/camps/_card.html.erb +++ b/app/views/camps/_card.html.erb @@ -1,10 +1,10 @@

    <% if user_signed_in? %> - <%= link_to toggle_favorite_event_camp_path(event_slug: @event.slug, id: camp.id), method: :patch, class: (camp.favorite_users.include?(current_user) ? 'favorite-button starred' : 'favorite-button'), id: 'favorite-button', :remote => true do %> + <%= link_to toggle_favorite_event_camp_path(@event, camp), method: :patch, class: (camp.favorite_users.include?(current_user) ? 'favorite-button starred' : 'favorite-button'), id: 'favorite-button', :remote => true do %> <% end %> <% end %> - +
    diff --git a/app/views/camps/_donate_form.html.erb b/app/views/camps/_donate_form.html.erb index a62093b1..8ca86abd 100644 --- a/app/views/camps/_donate_form.html.erb +++ b/app/views/camps/_donate_form.html.erb @@ -1,6 +1,7 @@
    - <%= best_in_place_if @can_edit, @camp, :subtitle, html_attrs: {maxlength: 255, class: "form-control"},as: :textarea, display_with: :simple_format %> + <%= best_in_place_if @can_edit, [@event, @camp], :subtitle, html_attrs: {maxlength: 255, class: "form-control"},as: :textarea, display_with: :simple_format %>
    <% if app_setting("multi_lang_support") %>
    <%= form.label t("form_subtitle_en_label") %>
    - <%= best_in_place_if @can_edit, @camp, :en_subtitle, html_attrs: {maxlength: 255, class: "form-control"},as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :en_subtitle, html_attrs: {maxlength: 255, class: "form-control"},as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
    <% end %> @@ -99,7 +99,7 @@ <%= t("form_creator_name_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :contact_name, html_attrs: {maxlength: 64, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :contact_name, html_attrs: {maxlength: 64, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %>
    @@ -118,20 +118,20 @@ <%= t("form_contact_phone_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :contact_phone, html_attrs: {maxlength: 64, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :contact_phone, html_attrs: {maxlength: 64, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %>
    <% end %>
    <%= form.label t("form_about_the_artist_label") %>
    - <%= best_in_place_if @can_edit, @camp, :about_the_artist, html_attrs: {maxlength: 1024, class: "form-control"},as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :about_the_artist, html_attrs: {maxlength: 1024, class: "form-control"},as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
    <%= form.label t("form_dream_website_label") %>
    - <%= best_in_place_if @can_edit, @camp, :website, html_attrs: {maxlength: 512, class: "form-control"}, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :website, html_attrs: {maxlength: 512, class: "form-control"}, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
    @@ -141,7 +141,7 @@ <%= t("form_description_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :description, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :description, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
    <% end %>
  • @@ -152,7 +152,7 @@ <%= t("form_electricity_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :electricity, html_attrs: {maxlength: 256, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :electricity, html_attrs: {maxlength: 256, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
    <% end %>
    @@ -163,7 +163,7 @@ <%= t("form_fire_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :fire, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :fire, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
    <% end %>
    @@ -174,7 +174,7 @@ <%= t("form_noise_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :noise, html_attrs: {maxlength: 256, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :noise, html_attrs: {maxlength: 256, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %>
    <% end %> @@ -185,7 +185,7 @@ <%= t("form_nature_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :nature, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :nature, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
    <% end %> @@ -196,7 +196,7 @@ <%= t("form_recycling_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :recycling, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :recycling, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
    <% end %> @@ -207,7 +207,7 @@ <%= t("form_light_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :light, html_attrs: {maxlength: 512, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :light, html_attrs: {maxlength: 512, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %>
    <% end %> @@ -218,7 +218,7 @@ <%= t("form_moop_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :moop, html_attrs: {maxlength: 1024, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :moop, html_attrs: {maxlength: 1024, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
    <% end %> @@ -229,7 +229,7 @@ <%= t("form_cocreation_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :cocreation, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :cocreation, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
    <% end %> @@ -240,7 +240,7 @@ <%= t("form_neighbors_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :neighbors, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :neighbors, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
    <% end %> @@ -264,7 +264,7 @@ <%= t("form_minigrants_realcurrency_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :minbudget_realcurrency, html_attrs: {maxlength: 6, class: "form-control"}, place_holder: t(:form_click_to_edit_html), display_with: :number_to_currency, :helper_options => {:unit => "", precision:0} %> + <%= best_in_place_if @can_edit, [@event, @camp], :minbudget_realcurrency, html_attrs: {maxlength: 6, class: "form-control"}, place_holder: t(:form_click_to_edit_html), display_with: :number_to_currency, :helper_options => {:unit => "", precision:0} %>
    <% end %> <% if app_setting("granting") and !app_setting('disable_edit_budget') %> @@ -275,7 +275,7 @@ <%= t("form_maxigrants_realcurrency_guidetext_html") %>
    - <%= best_in_place_if @can_edit, @camp, :maxbudget_realcurrency, html_attrs: {maxlength: 6, class: "form-control"}, place_holder: t(:form_click_to_edit_html), display_with: :number_to_currency, :helper_options => {:unit => "", precision:0} %> + <%= best_in_place_if @can_edit, [@event, @camp], :maxbudget_realcurrency, html_attrs: {maxlength: 6, class: "form-control"}, place_holder: t(:form_click_to_edit_html), display_with: :number_to_currency, :helper_options => {:unit => "", precision:0} %>
    <% end %> <% if app_setting("granting") and app_setting("budgeting") %> diff --git a/app/views/camps/_tags.html.erb b/app/views/camps/_tags.html.erb index 8b834e77..276bfcb6 100644 --- a/app/views/camps/_tags.html.erb +++ b/app/views/camps/_tags.html.erb @@ -3,7 +3,7 @@

    <%= Camp.human_attribute_name(:tags) %>

    - <%= simple_form_for [@event, @camp], url: { action: 'remove_tag', :'format' => 'json' } do |f| %> + <%= simple_form_for [@event, @camp], url: tag_event_camp_path(@event, @camp, format: :json), method: :delete do |f| %>
    <% @camp.tags.each do |tag| %>
    @@ -13,7 +13,7 @@
    <% end %> - <%= simple_form_for [@event, @camp], url: { action: 'tag', :'format' => 'json' } do |f| %> + <%= simple_form_for [@event, @camp], url: tag_event_camp_path(@event, @camp, format: :json) do |f| %> <%= f.text_field :tag_list, class: 'form-control', value: '' %> <%= f.submit t(:add_tag), id: 'tags-add', class: 'btn btn-success btn-sm' %> <% end %> diff --git a/app/views/camps/edit.html.erb b/app/views/camps/edit.html.erb index cde76640..f0e6ae2f 100644 --- a/app/views/camps/edit.html.erb +++ b/app/views/camps/edit.html.erb @@ -27,9 +27,9 @@ diff --git a/app/views/camps/new.html.erb b/app/views/camps/new.html.erb index 5f5be599..1e2289df 100644 --- a/app/views/camps/new.html.erb +++ b/app/views/camps/new.html.erb @@ -4,7 +4,7 @@ <% @can_edit = true %> -<%= simple_form_for([@event, @camp], :html => {:dir => I18n.t(:html_direction), id: 'createDreamForm'}) do |form| %> +<%= simple_form_for(@camp, url: event_camps_path(event_slug: @event.slug), html: {dir: I18n.t(:html_direction), id: 'createDreamForm'}) do |form| %>
    <%= t("form_basics_headline") %>
    diff --git a/app/views/camps/show.html.erb b/app/views/camps/show.html.erb index e54f3401..fc275957 100644 --- a/app/views/camps/show.html.erb +++ b/app/views/camps/show.html.erb @@ -40,7 +40,7 @@

    <%= @camp.display_name %> <% if user_signed_in? %> - <%= link_to :toggle_favorite_camp, method: :patch, class: (@camp.favorite_users.include?(current_user) ? 'favorite-button starred' : 'favorite-button'), id: 'favorite-button', style: "position: absolute;", :remote => true do %> + <%= link_to toggle_favorite_event_camp_path(@event, @camp), method: :patch, class: (@camp.favorite_users.include?(current_user) ? 'favorite-button starred' : 'favorite-button'), id: 'favorite-button', style: "position: absolute;", :remote => true do %> <% end %> <% end %> @@ -65,7 +65,7 @@ <% if @camp.grantingtoggle %> - <% if current_user && current_user.grants > 0 && !@camp.fullyfunded %> + <% if current_user && current_user.grants_left_for(@event) > 0 && !@camp.fullyfunded %>