Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/chapter_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ChapterController < ApplicationController
include AttendanceConcerns
def show
@chapter = ChapterPresenter.new(Chapter.active.find_by!(slug: slug))

Expand All @@ -10,6 +11,7 @@ def show
@latest_workshops = event_presenters_by_date(past_events)

@recent_sponsors = Sponsor.recent_for_chapter(@chapter)
@attending_ids = attending_workshops
end

private
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/concerns/attendance_concerns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module AttendanceConcerns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is one concern I think this should just be AttendanceConcern same for the file name so it matches the following:

  1. Rails autoloading expectations
  2. ActiveSupport::Concern conventions
  3. The rails generate concern behaviour

extend ActiveSupport::Concern

def attending_workshops
current_user.nil? ? Set.new : current_user.workshop_invitations.accepted.pluck(:id).to_set
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end

def attending_events
current_user.nil? ? Set.new : current_user.invitations.accepted.pluck(:id).to_set
end
end
4 changes: 3 additions & 1 deletion app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class DashboardController < ApplicationController
include AttendanceConcerns
before_action :is_logged_in?, only: %i[dashboard]
skip_before_action :accept_terms, except: %i[dashboard show]

Expand All @@ -13,7 +14,7 @@ def show
hash[key] = EventPresenter.decorate_collection(value)
hash
end

@attending_ids = attending_workshops
@testimonials = Testimonial.order(Arel.sql('RANDOM()')).limit(5).includes(:member)
end

Expand All @@ -24,6 +25,7 @@ def dashboard
hash
end
@announcements = current_user.announcements.active
@attending_ids = attending_workshops
end

def code; end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'services/ticket'

class EventsController < ApplicationController
include AttendanceConcerns
before_action :is_logged_in?, only: %i[student coach]

RECENT_EVENTS_DISPLAY_LIMIT = 40
Expand All @@ -23,6 +24,7 @@ def index
events << Event.upcoming.includes(:venue, :sponsors).all
events = events.compact.flatten.sort_by(&:date_and_time).group_by(&:date)
@events = events.map.inject({}) { |hash, (key, value)| hash[key] = EventPresenter.decorate_collection(value); hash }
@attending_ids = attending_events
end

def show
Expand Down
20 changes: 19 additions & 1 deletion app/presenters/member_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
class MemberPresenter < BasePresenter

def organiser?
has_role? :organiser, :any
end

def is_admin?
@admin ||= has_role?(:admin)
end

# Gather all the ids of all the events the member has organised or has organising permissions for
def organising_events
@organised_events ||= roles.preload(:resource).where(name: 'organiser').pluck(:resource_type, :resource_id).group_by(&:first).transform_values { |pairs | pairs.map(&:last)}
end

def event_organiser?(event)
has_role?(:organiser, event) || has_role?(:organiser, event.chapter) || has_role?(:admin)
if model.nil?
false
else
event_types = %w[Workshop Meeting Event]
organising_events.slice(*event_types).values.any? { |ids| ids.include?(event.id) } || @organised_events['Chapter']&.include?(event.chapter.id) || is_admin?
end

end

def newbie?
Expand All @@ -23,6 +39,8 @@ def pairing_details_array(role, tutorial, note)
role.eql?('Coach') ? coach_pairing_details(note) : student_pairing_details(tutorial, note)
end


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these two spaces needed?


private

def coach_pairing_details(note)
Expand Down
3 changes: 2 additions & 1 deletion app/views/admin/members/_profile.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
- if @member.groups.any?
%h5 Groups
%ul.list-unstyled.ms-0#subscriptions
- @member.groups.each do |group|
- member_groups = @member.groups
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably just do @member.groups.each etc

- member_groups.each do |group|
%li
= link_to [:admin, group] do
#{group.name} (#{group.chapter.name})
Expand Down
4 changes: 2 additions & 2 deletions app/views/chapter/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
%h2.mb-4= t('homepage.events.upcoming')
- @upcoming_workshops.each do |date, workshops|
%h3.h5= date
= render workshops
= render workshops, attending_ids: @attending_ids

- if @latest_workshops.any?
.pt-4
%h2.mb-4 Past Events
- @latest_workshops.each do |date, workshops|
= render workshops
= render workshops, attending_ids: @attending_ids

- if @recent_sponsors.any?
.py-4.py-lg-5.bg-light
Expand Down
5 changes: 3 additions & 2 deletions app/views/dashboard/dashboard.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
%small= link_to 'Edit', subscriptions_path, class: 'ms-2'
- if current_user.chapters.any?
.list-group.list-group-flush
- current_user.chapters.each do |chapter|
- chapters = current_user.chapters
- chapters.each do |chapter|
= link_to chapter.name, chapter_url(chapter.slug), class: 'list-group-item list-group-item-action'
- else
%i.fas.fa-exclamation-triangle
Expand All @@ -32,4 +33,4 @@
There are no upcoming events announced for the chapters you are subscribed to.
- @ordered_events.each do |date, workshops|
%h4= date
= render workshops
= render workshops, attending_ids: @attending_ids
2 changes: 1 addition & 1 deletion app/views/dashboard/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
%h2.h3.mb-4= t('homepage.events.upcoming')
- @upcoming_workshops.each do |date, workshops|
%h3.h5= date
= render workshops
= render workshops, attending_ids: @attending_ids

.col-lg-4.pl-lg-5
%h3
Expand Down
11 changes: 7 additions & 4 deletions app/views/events/_event.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
- if event.chapter
%span.badge.bg-primary.mb-3.mb-md-0
= link_to event.chapter.name, event.chapter.slug, class: 'text-light text-decoration-none'
- if @user
- if @user.attending?(event.__getobj__)
- if !attending_ids.blank?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attending_ids.present? might be better here

- if attending_ids.include?(event.id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you mentioned in the PR description, this seems problematic if there is a crossover of ids between different event types.

%span.badge.bg-success.mb-3.mb-md-0
= link_to 'Attending', event.path, class: 'text-light text-decoration-none'
- if @user
- if @user.event_organiser?(event)
%span.badge.bg-secondary.mb-3.mb-md-0
= link_to 'Manage', event.admin_path, class: 'text-light text-decoration-none'
Expand All @@ -31,10 +32,12 @@
.d-md-flex.justify-content-md-between.align-items-md-center
- if event.organisers.any?
.mb-3.mb-md-0
- event.organisers.each do |organiser|
- organisers = event.organisers
- organisers.each do |organiser|
= image_tag(organiser.avatar(26), class: 'rounded-circle', title: organiser.full_name, alt: organiser.full_name)
- if event.sponsors.any?
.ms-auto
- event.sponsors.each do |sponsor|
- sponsors = event.sponsors
- sponsors.each do |sponsor|
= link_to sponsor.website, class: 'd-inline-block' do
= image_tag(sponsor.avatar.thumb.url, class: 'sponsor-sm mx-1', alt: sponsor.name)
2 changes: 1 addition & 1 deletion app/views/events/_events.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
%h3.h5= date
.row
.col-md-8
= render workshops
= render workshops, attending_ids: attending_ids
4 changes: 2 additions & 2 deletions app/views/events/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
.col
- if @events.any?
%h3.mb-4 Upcoming Events
= render partial: 'events', locals: { grouped_events: @events }
= render partial: 'events', locals: { grouped_events: @events, attending_ids: @attending_ids}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need a space before the closing }


.container{'data-test': 'past-events'}
.row
.col
- if @past_events.any?
%h3.mb-4 Past Events
= render partial: 'events', locals: { grouped_events: @past_events }
= render partial: 'events', locals: { grouped_events: @past_events, attending_ids: @attending_ids }
2 changes: 1 addition & 1 deletion app/views/workshops/_workshop.html.haml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
= render partial: 'events/event', locals: { event: workshop }
= render partial: 'events/event', locals: { event: workshop, attending_ids: attending_ids }