Skip to content

Commit 5b7a5fe

Browse files
committed
Merge remote-tracking branch 'origin/main' into accessories-shop
2 parents ce88e59 + 81e1ef7 commit 5b7a5fe

Some content is hidden

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

44 files changed

+303820
-140
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Api::Admin::UserSignupsController < ApplicationController
2+
def index
3+
authorize! :admin, :dashboard
4+
5+
# Build query with optional date filtering
6+
users_query = User.where("created_at >= ?", 1.year.ago)
7+
8+
# if filter_params[:start]
9+
# start_date = DateTime.parse(filter_params[:start])
10+
# users_query = users_query.where("created_at >= ?", start_date)
11+
# end
12+
#
13+
# if filter_params[:end]
14+
# end_date = DateTime.parse(filter_params[:end])
15+
# users_query = users_query.where("created_at <= ?", end_date)
16+
# end
17+
#
18+
user_signups = users_query.group_by { |m| m.created_at.beginning_of_month }.map {|k,v| [k.strftime("%B %Y"), v.count] }.to_h
19+
20+
render json: { user_signups: user_signups }
21+
end
22+
23+
private
24+
25+
def filter_params
26+
params.permit(:start, :end)
27+
end
28+
end

app/controllers/api/shrimpos/end_shrimpos_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ class Api::Shrimpos::EndShrimposController < ApplicationController
22
def create
33
# TODO auth
44
shrimpo = Shrimpo.friendly.find params[:shrimpo_id]
5-
# if !shrimpo.voting? && (!current_user != shrimpo.user || !current_user.admin?)
6-
# render status: :unprocessable_entity
7-
# end
5+
if !shrimpo.voting? && (!current_user != shrimpo.user || !current_user.admin?)
6+
render head: :forbidden
7+
end
88

99
if shrimpo.tally_results!
1010
ActiveSupport::Notifications.instrument 'shrimpo.ended', title: shrimpo.title

app/controllers/api/shrimpos_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ def create
1414
shrimpo.silver_trophy = Trophy.find_by(name: "silveren shrimpo")
1515
shrimpo.bronze_trophy = Trophy.find_by(name: "bronzeen shrimpo")
1616
shrimpo.consolation_trophy = Trophy.find_by(name: "good beverage")
17+
18+
if shrimpo.mega? && shrimpo_voting_categories_params
19+
shrimpo_voting_categories_params.each do |category|
20+
shrimpo.shrimpo_voting_categories.build name: category, emoji: ":#{category}:"
21+
end
22+
end
23+
1724
if shrimpo.valid? && shrimpo.save_and_deposit_fruit_tickets!
1825
ActiveSupport::Notifications.instrument 'shrimpo.created', username: shrimpo.user.username, title: shrimpo.title
1926
render json: shrimpo

app/controllers/api/tracks_controller.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,22 @@ class Api::TracksController < ApplicationController
33
before_action :current_radio_required
44

55
def index
6-
@tracks = @current_radio.tracks.where("id in (?)", params[:id])
6+
@tracks = @current_radio.tracks.order("created_at DESC")
77

8+
if params[:id]
9+
@tracks = @current_radio.tracks.where("id in (?)", params[:id])
10+
end
11+
12+
if params[:my] && !current_user.has_role?("admin")
13+
@tracks = @tracks.where(uploaded_by: current_user)
14+
end
15+
16+
if params[:term]
17+
@tracks = @tracks.where("audio_file_name ilike (?) OR title ilike (?)", "%#{params.permit(:term)[:term]}%", "%#{params.permit(:term)[:term]}%")
18+
end
19+
20+
@tracks = @tracks.page(params[:page])
21+
meta = { page: params[:page], total_pages: @tracks.total_pages.to_i }
822
render json: @tracks
923
end
1024

app/controllers/metadata_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class MetadataController < ApplicationController
22
def create
33
authorize! :update, :metadata
4-
if MetadataUpdate.perform(@current_radio, metadata_params)
5-
MetadataPublisher.perform @current_radio.name, metadata_params[:title]
4+
if LiquidsoapMetadataUpdate.perform(@current_radio, metadata_params)
5+
RedisMetadataPublisher.perform @current_radio.name, metadata_params[:title]
66
head :ok
77
else
88
head :error

app/controllers/publish_metadata_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ class PublishMetadataController < ApplicationController
22
before_action :current_radio_required
33
def create
44
if liq_authorized?
5-
MetadataPublisher.perform @current_radio.name, params[:metadata]
6-
MetadataUpdate.perform(@current_radio, { title: params[:metadata] })
5+
RedisMetadataPublisher.perform @current_radio.name, params[:metadata]
6+
LiquidsoapMetadataUpdate.perform(@current_radio, { title: params[:metadata] })
7+
CanonicalMetadataSync.perform(@current_radio.id, params[:metadata] )
78
head :ok
89
else
910
render json: "not permitted", status: :unauthorized

app/controllers/scheduled_shows_controller.rb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,8 @@ def next
4141

4242
def current
4343
response.headers["Access-Control-Allow-Origin"] = "*" # This is a public API, maybe I should namespace it later
44-
current = StreamPusher.redis.hgetall "#{@current_radio.name}:current_show"
45-
# if no current show, return current archive + episode id info
46-
if current.empty?
47-
archive = StreamPusher.redis.hgetall "#{@current_radio.name}:current_archive"
48-
show = ScheduledShow.friendly.find archive["episode"]
49-
render json: show
50-
# if no scheduled_show id, it's a renegade show B-)
51-
elsif current["title"].present? && current["scheduled_show"].blank?
52-
render json: { title: current["title"], renegade: true }
53-
# otherwise its a live show and on the timetable, so return the show json
54-
else
55-
show = ScheduledShow.find current["scheduled_show"]
56-
render json: show
57-
end
44+
current = StreamPusher.redis.hgetall "#{@current_radio.name}:canonical_metadata"
45+
render json: current
5846
end
5947

6048
def create

app/models/fruit_summon.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
class FruitSummon < ApplicationRecord
2+
include RedisConnection
3+
24
belongs_to :fruit_ticket_transaction
35
belongs_to :fruit_summon_entity
46
belongs_to :user
7+
8+
after_create :maybe_trigger_hype_meter
9+
10+
private
11+
12+
def maybe_trigger_hype_meter
13+
latest_fruit_summons = FruitSummon.where("created_at > ?", 10.minutes.ago)
14+
if latest_fruit_summons.count >= 3
15+
hype_meter_active = redis.get "datafruits:hype_meter_cooldown"
16+
# only activate if not on cooldown or already active
17+
if hype_meter_active.nil?
18+
redis.set "datafruits:hype_meter_status", "active"
19+
redis.set "datafruits:hype_meter_cooldown", true
20+
redis.expire "datafruits:hype_meter_cooldown", 900
21+
end
22+
end
23+
end
524
end

app/models/notification.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ def set_message
104104
"#{self.source.title} has a new comment!"
105105
when "patreon_sub"
106106
gif_url = GiphyTextAnimator.animate_text self.source.name
107+
name = self.source.user&.username || self.source.name
107108
if gif_url.is_a? String
108-
"#{self.source.name} subscribed to the #{self.source.tier_name} tier on patreon! #{gif_url} #{self.source.patreon_checkout_link}"
109+
"#{name} subscribed to the #{self.source.tier_name} tier on patreon! #{gif_url} #{self.source.patreon_checkout_link}"
109110
else
110-
"#{self.source.name} subscribed to the #{self.source.tier_name} tier on patreon! #{self.source.patreon_checkout_link}"
111+
"#{name} subscribed to the #{self.source.tier_name} tier on patreon! #{self.source.patreon_checkout_link}"
111112
end
112113
when "new_thread"
113114
"New thread posted in da fruit standz: #{self.source.title}"

app/models/patreon_pledge.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class PatreonPledge < ApplicationRecord
22
after_create :add_role_to_user
3+
belongs_to :user
34

45
def tier_mappings
56
# FIXME
@@ -47,7 +48,7 @@ def add_role_to_user
4748
user = User.find_by email: email
4849
# if we can't find the user by the email, will have to assign later manually
4950
if user.present? && tier_name.present?
50-
user.add_role_to_user
51+
self.update! user: user
5152
case tier_name
5253
# TODO make new badges for these??
5354
# when "it's just a website"

0 commit comments

Comments
 (0)