Skip to content

Commit 0d57ec1

Browse files
Luke-Oldenburgpolypixeldevgaryhtougithub-actions[bot]davidcornu
authored
Organization Announcements (Tier 1) (#10830)
## Summary of the problem <!-- Why these changes are being made? What problem does it solve? Link any related issues to provide more details. --> ## Describe your changes <!-- Explain your thought process to the solution and provide a quick summary of the changes. --> <!-- If there are any visual changes, please attach images, videos, or gifs. --> --------- Co-authored-by: Samuel Fernandez <[email protected]> Co-authored-by: Gary Tou <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: David Cornu <[email protected]> Co-authored-by: yodalightsabr <[email protected]> Co-authored-by: yodalightsabr <[email protected]>
1 parent 97f22e2 commit 0d57ec1

File tree

61 files changed

+1490
-60
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1490
-60
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,5 @@ gem "rack-timeout", require: "rack/timeout/base"
228228
gem "irb"
229229

230230
gem "pstore"
231+
232+
gem "prosemirror_to_html"

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ GEM
588588
net-smtp
589589
premailer (~> 1.7, >= 1.7.9)
590590
prism (1.4.0)
591+
prosemirror_to_html (0.2.0)
592+
nokogiri
591593
pry (0.15.2)
592594
coderay (~> 1.1)
593595
method_source (~> 1.0)
@@ -953,6 +955,7 @@ DEPENDENCIES
953955
plaid (~> 34.0)
954956
poppler
955957
premailer-rails
958+
prosemirror_to_html
956959
pry-byebug
957960
pry-rails
958961
pstore

app/assets/stylesheets/application.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ summary {
252252
@import 'components/event_settings';
253253
@import 'components/reactions';
254254
@import 'components/tags';
255+
@import 'components/tiptap';
255256
@import 'components/filter_tabs';
256257
@import 'components/filter_menu';
257258
@import 'components/home_page';

app/assets/stylesheets/components/_forms.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ input:where([data-behavior='otp_input']) {
530530
display: flex;
531531
border-radius: 0.75rem;
532532

533+
width: fit-content;
534+
533535
transform: scale(1);
534536
transition:
535537
transform 0.125s ease-in-out,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.tiptap p.is-editor-empty:first-child::before {
2+
color: #adb5bd;
3+
content: attr(data-placeholder);
4+
float: left;
5+
height: 0;
6+
pointer-events: none;
7+
}
8+
9+
.tiptap p:first-child {
10+
margin-top: 0px;
11+
}
12+
13+
.tiptap p:last-child {
14+
margin-bottom: 0px;
15+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# frozen_string_literal: true
2+
3+
class AnnouncementsController < ApplicationController
4+
before_action :set_event
5+
before_action :set_announcement, except: [:index, :new]
6+
before_action :set_event_follow
7+
8+
def index
9+
@announcement = Announcement.new
10+
@announcement.event = @event
11+
12+
authorize @announcement
13+
14+
@all_announcements = Announcement.where(event: @event).order(published_at: :desc, created_at: :desc)
15+
@announcements = @all_announcements.page(params[:page]).per(10)
16+
17+
raise ActionController::RoutingError.new("Not Found") if !@event.is_public && @all_announcements.empty? && !organizer_signed_in?
18+
end
19+
20+
def new
21+
@announcement = Announcement.new
22+
@announcement.event = @event
23+
24+
authorize @announcement
25+
end
26+
27+
def create
28+
@announcement = @event.announcements.build(params.require(:announcement).permit(:title, :content).merge(author: current_user))
29+
30+
authorize @announcement
31+
32+
@announcement.save!
33+
34+
unless params[:announcement][:draft] == "true"
35+
@announcement.publish!
36+
end
37+
38+
flash[:success] = "Announcement successfully #{params[:announcement][:draft] == "true" ? "drafted" : "published"}!"
39+
40+
rescue => e
41+
puts e.message
42+
flash[:error] = "Something went wrong. #{e.message}"
43+
Rails.error.report(e)
44+
ensure
45+
redirect_to event_announcement_path(@event, @announcement)
46+
end
47+
48+
def show
49+
authorize @announcement
50+
end
51+
52+
def edit
53+
authorize @announcement
54+
55+
render "announcements/show", locals: { editing: true }
56+
end
57+
58+
def update
59+
authorize @announcement
60+
61+
@announcement.update!(params.require(:announcement).permit(:title, :content))
62+
63+
if params[:announcement][:autosave] != "true"
64+
flash[:success] = "Updated announcement"
65+
redirect_to event_announcement_path(@event, @announcement)
66+
end
67+
end
68+
69+
def destroy
70+
authorize @announcement
71+
72+
@announcement.destroy!
73+
74+
flash[:success] = "Deleted announcement"
75+
76+
redirect_to event_announcements_path(@event)
77+
end
78+
79+
def publish
80+
authorize @announcement
81+
82+
@announcement.publish!
83+
84+
flash[:success] = "Published announcement"
85+
86+
redirect_to event_announcement_path(@event, @announcement)
87+
end
88+
89+
private
90+
91+
def set_announcement
92+
if params[:id].present?
93+
@announcement = @event.announcements.find(params[:id])
94+
end
95+
end
96+
97+
def set_event
98+
if params[:event_id].present?
99+
@event = Event.find_by!(slug: params[:event_id])
100+
end
101+
end
102+
103+
def set_event_follow
104+
@event_follow = Event::Follow.where({ user_id: current_user.id, event_id: @event.id }).first if current_user
105+
end
106+
107+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
class Event
4+
class FollowsController < ApplicationController
5+
include SetEvent
6+
skip_before_action :signed_in_user, only: :create
7+
before_action :set_event, only: :create
8+
9+
def create
10+
unless signed_in?
11+
skip_authorization
12+
return redirect_to auth_users_path(return_to: event_url(@event), require_reload: true)
13+
end
14+
15+
attrs = {
16+
user_id: current_user.id,
17+
event: @event
18+
}
19+
follow = Event::Follow.new(attrs)
20+
authorize follow
21+
follow.save!
22+
redirect_to event_announcements_path(@event)
23+
end
24+
25+
def destroy
26+
@event_follow = Event::Follow.find(params[:id])
27+
authorize @event_follow
28+
slug = @event_follow.event.slug
29+
@event_follow.destroy!
30+
redirect_to event_path(slug)
31+
end
32+
33+
end
34+
35+
end

app/controllers/events_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class EventsController < ApplicationController
1414
end
1515
skip_before_action :signed_in_user
1616
before_action :set_mock_data
17+
before_action :set_event_follow, only: [:show, :transactions]
1718

1819
before_action :redirect_to_onboarding, unless: -> { @event&.is_public? }
1920

@@ -1116,4 +1117,8 @@ def set_mock_data
11161117
end
11171118
end
11181119

1120+
def set_event_follow
1121+
@event_follow = Event::Follow.where({ user_id: current_user.id, event_id: @event.id }).first if current_user
1122+
end
1123+
11191124
end

app/controllers/my_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
class MyController < ApplicationController
4-
skip_after_action :verify_authorized, only: [:activities, :toggle_admin_activities, :cards, :missing_receipts_list, :missing_receipts_icon, :inbox, :reimbursements, :reimbursements_icon, :tasks, :payroll, :toggle_three_teens_banner] # do not force pundit
4+
skip_after_action :verify_authorized, only: [:activities, :toggle_admin_activities, :cards, :missing_receipts_list, :missing_receipts_icon, :inbox, :reimbursements, :reimbursements_icon, :tasks, :payroll, :toggle_three_teens_banner, :feed] # do not force pundit
55

66
def activities
77
@before = params[:before] || Time.now
@@ -146,4 +146,10 @@ def payroll
146146
@payout_method = current_user.payout_method
147147
end
148148

149+
def feed
150+
@event_follows = current_user.event_follows
151+
@all_announcements = Announcement.published.where(event: @event_follows.map(&:event)).order(published_at: :desc, created_at: :desc)
152+
@announcements = @all_announcements.page(params[:page]).per(10)
153+
end
154+
149155
end

app/helpers/application_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,18 +392,18 @@ def ugc_link_to(name, string, *options)
392392
def dropdown_button(button_class: "bg-success", template: ->(value) { value }, **options)
393393
return content_tag :div, class: "relative w-fit #{options[:class]}", data: { controller: "dropdown-button", "dropdown-button-target": "container" } do
394394
(content_tag :div, class: "dropdown-button__container", **options[:button_container_options] do
395-
(content_tag :button, class: "btn !transform-none rounded-l-xl rounded-r-none #{button_class}" do
395+
(content_tag :button, class: "btn !transform-none rounded-l-xl rounded-r-none #{button_class}", **options[:button_options] do
396396
(inline_icon options[:button_icon]) +
397397
(content_tag :span, template.call(options[:options][0][1]), data: { "dropdown-button-target": "text", "template": template })
398398
end) +
399399
(content_tag :button, type: "button", class: "btn !transform-none rounded-r-xl rounded-l-none !w-12 ml-[2px] #{button_class}", data: { action: "click->dropdown-button#toggle" } do
400400
inline_icon "down-caret", class: "!mr-0"
401401
end)
402402
end) +
403-
(content_tag :div, class: "dropdown-button__menu fade-card-hide", data: { "dropdown-button-target": "menu" } do
403+
(content_tag :div, class: "dropdown-button__menu fade-card-hide #{options[:menu_class]}", data: { "dropdown-button-target": "menu" } do
404404
content_tag :div do
405-
(options[:options].map do |option|
406-
(options[:form].radio_button options[:name], option[1], { data: { action: "change->dropdown-button#change", "dropdown-button-target": "select", "label": template.call(option[1]) } }) +
405+
(options[:options].map.with_index do |option, index|
406+
(options[:form].radio_button options[:name], option[1], { checked: index == 0, data: { action: "change->dropdown-button#change", "dropdown-button-target": "select", "label": template.call(option[1]) } }) +
407407
(options[:form].label options[:name], value: option[1] do
408408
(tag.strong option[0]) + (tag.p option[2])
409409
end)

0 commit comments

Comments
 (0)