-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Event & Org support #17
base: master
Are you sure you want to change the base?
Changes from all commits
3400b50
bcd6769
b873195
4ae46bf
381f1d2
6fdeba4
58856d5
86fd75a
89df6b4
862c820
fc329f6
1a955a0
620e8a1
573b9ef
b38e7c2
e6c6891
bf633e3
3b9d3df
bbda179
24cb1eb
f8c97fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -496,4 +496,4 @@ RUBY VERSION | |
ruby 2.5.1p57 | ||
|
||
BUNDLED WITH | ||
1.15.2 | ||
2.0.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
ActiveAdmin.register Event do | ||
actions :index, :show, :new, :create, :edit, :update, :destroy | ||
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 | ||
f.input :starts_at, as: :datepicker | ||
f.input :ends_at, as: :datepicker | ||
end | ||
f.actions | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
ActiveAdmin.register Membership do | ||
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 | ||
# who to put in what collective. | ||
|
||
# SUPER ROUGH mockup might be: | ||
# New Membership | ||
# -------------- | ||
|
||
# User | ||
# ---- | ||
# Hugi ([email protected]) | ||
# Kristoffer ([email protected]) | ||
|
||
# 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ActiveAdmin.register Organization do | ||
actions :index, :show, :new, :create, :edit, :update, :destroy | ||
permit_params :name | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ 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] | ||
|
@@ -15,6 +16,7 @@ def index | |
|
||
def new | ||
@camp = Camp.new | ||
@camp.event = @event | ||
end | ||
|
||
def edit | ||
|
@@ -30,7 +32,7 @@ def 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 | ||
|
@@ -41,36 +43,30 @@ def create | |
|
||
def toggle_granting | ||
@camp.toggle!(:grantingtoggle) | ||
redirect_to camp_path(@camp) | ||
redirect_to event_camp_path(@event, @camp) | ||
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 | ||
|
||
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) | ||
elsif params[:safetysave] == '1' | ||
puts(camp_safety_sketches_path(@camp)) | ||
redirect_to camp_safety_sketches_path(@camp) | ||
puts(event_camp_safety_sketches_path(@event, @camp)) | ||
redirect_to event_camp_safety_sketches_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 | ||
|
@@ -103,7 +99,7 @@ def remove_tag_params | |
|
||
def destroy | ||
@camp.destroy! | ||
redirect_to camps_path | ||
redirect_to event_camps_path(@event) | ||
end | ||
|
||
# Display a camp and its users | ||
|
@@ -138,11 +134,16 @@ def toggle_favorite | |
|
||
def archive | ||
@camp.update!(active: false) | ||
redirect_to camps_path | ||
redirect_to event_camps_path(@event) | ||
end | ||
|
||
private | ||
|
||
def load_event! | ||
@event = Event.find(params[:event_id]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
not_found if @event.nil? | ||
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 | ||
|
@@ -152,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 camps_path | ||
@camp = Camp.includes(:event).find(params[:id]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this wants to be
|
||
|
||
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! | ||
|
@@ -170,11 +174,13 @@ 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')), | ||
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') | ||
) | ||
|
@@ -185,7 +191,7 @@ def granted | |
end | ||
|
||
def failure_path | ||
camp_path(@camp) | ||
event_camp_path(@event, @camp) | ||
end | ||
|
||
def create_camp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class EventsController < ApplicationController | ||
def index | ||
@events = Event.all.order(starts_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 | ||
# events which are not the current one | ||
@event = Event.find(params[:id]) | ||
redirect_to events_path if @event.nil? | ||
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 | ||
|
||
def redirect_to_most_relevant | ||
e = Event.most_relevant | ||
unless e.nil? | ||
redirect_to event_camps_path(e) | ||
else | ||
redirect_to events_path | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,21 +8,26 @@ 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 | ||
end | ||
|
||
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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might consider pulling out load_camp! and load_event! into a module so you don't have to define them in multiple places; this loading code is important, reusable, and shouldn't be defined in more than one place. At the very least you should drop the double |
||
|
||
@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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a helper for this now; should be
You can include the |
||
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.