Skip to content

Commit 305a68a

Browse files
Add - Grant option to market
Fix - Market hanging Add - hide button to ysws dashboard
1 parent 6864334 commit 305a68a

File tree

7 files changed

+410
-28
lines changed

7 files changed

+410
-28
lines changed

app/assets/stylesheets/application.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,26 @@ h2 {
179179
z-index: 1;
180180
text-decoration: none;
181181
}
182+
183+
/* Greg project hide/unhide button styles */
184+
.greg-hide-btn {
185+
background-color: #dc2626 !important;
186+
color: white !important;
187+
border-color: #dc2626 !important;
188+
}
189+
190+
.greg-hide-btn:hover {
191+
background-color: #b91c1c !important;
192+
border-color: #b91c1c !important;
193+
}
194+
195+
.greg-unhide-btn {
196+
background-color: #059669 !important;
197+
color: white !important;
198+
border-color: #059669 !important;
199+
}
200+
201+
.greg-unhide-btn:hover {
202+
background-color: #047857 !important;
203+
border-color: #047857 !important;
204+
}

app/controllers/greg_controller.rb

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ def index
55
@projects = Project.includes(:user)
66
.where(status: [ "submitted", "pending_voting", "waiting_for_review", "finished" ])
77

8+
# Filter out hidden projects by default, unless super admin explicitly shows them
9+
@show_hidden = current_user&.super_admin? && params[:show_hidden] == 'true'
10+
unless @show_hidden
11+
@projects = @projects.where(hidden: false)
12+
end
13+
814
# Default to showing only sus projects
915
fraud_status_filter = params[:fraud_status].presence || "sus"
1016

@@ -120,6 +126,46 @@ def update_fraud_status
120126
end
121127
end
122128

129+
def hide_project
130+
unless current_user&.super_admin?
131+
render json: { success: false, error: "Access denied. Super admin privileges required." }
132+
return
133+
end
134+
135+
@project = Project.find(params[:id])
136+
137+
# Skip screenshot validation when hiding project
138+
@project.skip_screenshot_validation!
139+
140+
if @project.update(hidden: true)
141+
render json: { success: true, message: "Project '#{@project.name}' has been hidden." }
142+
else
143+
render json: { success: false, error: "Failed to hide project." }
144+
end
145+
rescue ActiveRecord::RecordNotFound
146+
render json: { success: false, error: "Project not found." }
147+
end
148+
149+
def unhide_project
150+
unless current_user&.super_admin?
151+
render json: { success: false, error: "Access denied. Super admin privileges required." }
152+
return
153+
end
154+
155+
@project = Project.find(params[:id])
156+
157+
# Skip screenshot validation when unhiding project
158+
@project.skip_screenshot_validation!
159+
160+
if @project.update(hidden: false)
161+
render json: { success: true, message: "Project '#{@project.name}' has been unhidden." }
162+
else
163+
render json: { success: false, error: "Failed to unhide project." }
164+
end
165+
rescue ActiveRecord::RecordNotFound
166+
render json: { success: false, error: "Project not found." }
167+
end
168+
123169
private
124170

125171
def generate_fraud_leaderboard(week_number)
@@ -172,13 +218,19 @@ def require_fraud_access
172218
def get_project_navigation(current_project, filter_params)
173219
# Convert params to hash safely
174220
safe_params = filter_params.respond_to?(:permit) ?
175-
filter_params.permit(:name, :author, :week, :fraud_status, :reasoning).to_h :
221+
filter_params.permit(:name, :author, :week, :fraud_status, :reasoning, :show_hidden).to_h :
176222
filter_params.to_h
177223

178224
# Build the same query as index action to get the filtered list
179225
projects = Project.includes(:user)
180226
.where(status: [ "submitted", "pending_voting", "waiting_for_review", "finished" ])
181227

228+
# Apply hidden filter (same logic as index action)
229+
show_hidden = current_user&.super_admin? && (safe_params[:show_hidden] == 'true' || safe_params["show_hidden"] == 'true')
230+
unless show_hidden
231+
projects = projects.where(hidden: false)
232+
end
233+
182234
# Apply the same filters as index action
183235
fraud_status_filter = safe_params[:fraud_status].presence || safe_params["fraud_status"].presence || "sus"
184236

app/controllers/market_controller.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ def index
1616
.pluck(:item_name)
1717
@purchasable_cosmetics = Cosmetic.purchasable
1818
.where.not(name: purchased_cosmetic_names)
19-
.includes(image_attachment: :blob)
19+
.includes(:image_attachment)
2020

2121
# Get all purchasable physical items (can be bought multiple times)
22-
@purchasable_physical_items = PhysicalItem.purchasable.includes(image_attachment: :blob)
22+
@purchasable_physical_items = PhysicalItem.purchasable.includes(:image_attachment)
2323

2424
# Check if user is in supported region for regular tech tree
2525
@user_in_supported_region = user_in_supported_region?
@@ -87,14 +87,17 @@ def purchase
8787
render json: { success: false, error: "You've already purchased the maximum amount of this item! (#{purchased_count}/#{max_purchases})" }
8888
return
8989
end
90+
elsif tech_tree_item[:maxPurchases].nil?
91+
# Unlimited purchases (maxPurchases is null)
92+
# No purchase limit check needed
9093
elsif tech_tree_item[:maxPurchases] && tech_tree_item[:maxPurchases] > 1
9194
# Multi-purchase item with static limit
9295
if purchased_count >= tech_tree_item[:maxPurchases]
9396
render json: { success: false, error: "You've already purchased the maximum amount of this item!" }
9497
return
9598
end
9699
else
97-
# Default: Single purchase item (maxPurchases nil or 1)
100+
# Default: Single purchase item (maxPurchases is 1)
98101
if purchased_count > 0
99102
render json: { success: false, error: "You already own this item!" }
100103
return

app/controllers/ysws_review_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def show
223223
@time_readable = view_context.format_time_from_seconds(@time_seconds)
224224
@votes = @project ? Vote.joins(:ballot).includes(ballot: :user).where(project: @project).order("ballots.created_at DESC") : []
225225

226-
cast_votes = @votes.where(voted: true)
226+
cast_votes = @project ? @votes.where(voted: true) : []
227227
@average_score = cast_votes.any? ? cast_votes.average(:star_count).to_f.round(2) : nil
228228
@raw_hours = (@time_seconds / 3600.0).round(2)
229229

app/views/greg/index.html.erb

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,17 @@
505505
placeholder: "Search in reasoning text",
506506
class: "filter-input" %>
507507
</div>
508+
509+
<% if current_user&.super_admin? %>
510+
<div class="filter-group">
511+
<label class="filter-label" style="display: flex; align-items: center; gap: 0.5rem;">
512+
<%= form.check_box :show_hidden,
513+
{ checked: params[:show_hidden] == 'true' },
514+
'true', 'false' %>
515+
Show Hidden Projects
516+
</label>
517+
</div>
518+
<% end %>
508519
</div>
509520

510521
<div class="filter-actions">
@@ -604,6 +615,18 @@
604615
<% if project.user.slack_id.present? %>
605616
<%= link_to "Joe Profile", "https://dash.fraud.land/profile/#{project.user.slack_id}", target: "_blank", class: "greg-project-link", onclick: "event.stopPropagation()" %>
606617
<% end %>
618+
619+
<% if current_user&.super_admin? %>
620+
<% if project.hidden? %>
621+
<button class="greg-project-link greg-unhide-btn" onclick="event.stopPropagation(); unhideProject(<%= project.id %>)" title="Unhide project">
622+
Unhide
623+
</button>
624+
<% else %>
625+
<button class="greg-project-link greg-hide-btn" onclick="event.stopPropagation(); hideProject(<%= project.id %>)" title="Hide project">
626+
Hide
627+
</button>
628+
<% end %>
629+
<% end %>
607630
</div>
608631
</div>
609632
<% end %>
@@ -676,4 +699,73 @@
676699
localStorage.removeItem('greg-dark-mode');
677700
}
678701
})();
702+
703+
// Hide/Unhide project functionality
704+
function hideProject(projectId) {
705+
if (!confirm('Are you sure you want to hide this project?')) {
706+
return;
707+
}
708+
709+
fetch(`/fraud/projects/${projectId}/hide`, {
710+
method: 'PATCH',
711+
headers: {
712+
'Content-Type': 'application/json',
713+
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
714+
}
715+
})
716+
.then(response => response.json())
717+
.then(data => {
718+
if (data.success) {
719+
// Update the button to show "Unhide"
720+
const hideBtn = document.querySelector(`button[onclick*="hideProject(${projectId})"]`);
721+
if (hideBtn) {
722+
hideBtn.textContent = 'Unhide';
723+
hideBtn.setAttribute('onclick', `event.stopPropagation(); unhideProject(${projectId})`);
724+
hideBtn.className = 'greg-project-link greg-unhide-btn';
725+
hideBtn.title = 'Unhide project';
726+
}
727+
alert(data.message);
728+
} else {
729+
alert('Error: ' + data.error);
730+
}
731+
})
732+
.catch(error => {
733+
console.error('Error:', error);
734+
alert('An error occurred while hiding the project.');
735+
});
736+
}
737+
738+
function unhideProject(projectId) {
739+
if (!confirm('Are you sure you want to unhide this project?')) {
740+
return;
741+
}
742+
743+
fetch(`/fraud/projects/${projectId}/unhide`, {
744+
method: 'PATCH',
745+
headers: {
746+
'Content-Type': 'application/json',
747+
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
748+
}
749+
})
750+
.then(response => response.json())
751+
.then(data => {
752+
if (data.success) {
753+
// Update the button to show "Hide"
754+
const unhideBtn = document.querySelector(`button[onclick*="unhideProject(${projectId})"]`);
755+
if (unhideBtn) {
756+
unhideBtn.textContent = 'Hide';
757+
unhideBtn.setAttribute('onclick', `event.stopPropagation(); hideProject(${projectId})`);
758+
unhideBtn.className = 'greg-project-link greg-hide-btn';
759+
unhideBtn.title = 'Hide project';
760+
}
761+
alert(data.message);
762+
} else {
763+
alert('Error: ' + data.error);
764+
}
765+
})
766+
.catch(error => {
767+
console.error('Error:', error);
768+
alert('An error occurred while unhiding the project.');
769+
});
770+
}
679771
</script>

0 commit comments

Comments
 (0)