Add ratings, reviews, and publisher reputation system

- Add database schema for reviews, issues, and stats caching
- Add API endpoints for reviews (CRUD, voting, flagging)
- Add API endpoints for issues (report, list, resolve)
- Add publisher stats and badge system
- Add trust score calculation (0-100 scale)
- Update tool detail page with ratings, reviews, issues sections
- Update publisher profile with stats, badges, trust score
- Add dedicated reviews and issues pages with filtering
- Update dashboard tools table with rating/issues columns
- Update tool cards with inline rating display

Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit is contained in:
rob
2026-01-14 03:12:31 -04:00
co-authored by Claude Opus 4.5
parent d2c668dc99
commit 604b473806
10 changed files with 2566 additions and 9 deletions
@@ -132,6 +132,153 @@
{% endif %}
</div>
</div>
<!-- Reviews Section -->
<div id="reviews" class="bg-white rounded-lg border border-gray-200 p-6 mt-6">
<div class="flex items-center justify-between mb-6">
<h2 class="text-xl font-bold text-gray-900">Reviews</h2>
{% if session.get('auth_token') %}
<button type="button" onclick="openReviewModal()"
class="inline-flex items-center px-4 py-2 text-sm font-medium text-white bg-indigo-600 rounded-md hover:bg-indigo-700">
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
</svg>
Write Review
</button>
{% else %}
<a href="{{ url_for('web.login') }}?next={{ request.path }}"
class="inline-flex items-center px-4 py-2 text-sm font-medium text-indigo-600 border border-indigo-600 rounded-md hover:bg-indigo-50">
Login to review
</a>
{% endif %}
</div>
{% if reviews %}
<div class="space-y-6">
{% for review in reviews %}
<div class="border-b border-gray-200 pb-6 last:border-0 last:pb-0">
<div class="flex items-start justify-between">
<div>
<div class="flex items-center mb-1">
{% for i in range(1, 6) %}
<svg class="w-4 h-4 {{ 'text-yellow-400' if i <= review.rating else 'text-gray-300' }}" fill="currentColor" viewBox="0 0 20 20">
<path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"/>
</svg>
{% endfor %}
</div>
{% if review.title %}
<h4 class="font-semibold text-gray-900">{{ review.title }}</h4>
{% endif %}
</div>
<span class="text-xs text-gray-400">{{ review.created_at|timeago }}</span>
</div>
{% if review.content %}
<p class="mt-2 text-sm text-gray-600">{{ review.content }}</p>
{% endif %}
<div class="mt-3 flex items-center justify-between">
<span class="text-sm text-gray-500">
by <a href="{{ url_for('web.publisher', slug=review.reviewer_slug) if review.reviewer_slug else '#' }}"
class="text-indigo-600 hover:text-indigo-800">{{ review.reviewer_name }}</a>
</span>
<div class="flex items-center space-x-4 text-sm text-gray-400">
<button type="button" onclick="voteReview({{ review.id }}, 'helpful')"
class="flex items-center hover:text-gray-600">
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 10h4.764a2 2 0 011.789 2.894l-3.5 7A2 2 0 0115.263 21h-4.017c-.163 0-.326-.02-.485-.06L7 20m7-10V5a2 2 0 00-2-2h-.095c-.5 0-.905.405-.905.905 0 .714-.211 1.412-.608 2.006L7 11v9m7-10h-2M7 20H5a2 2 0 01-2-2v-6a2 2 0 012-2h2.5"/>
</svg>
{{ review.helpful_count }}
</button>
<button type="button" onclick="voteReview({{ review.id }}, 'unhelpful')"
class="flex items-center hover:text-gray-600">
<svg class="w-4 h-4 mr-1 transform rotate-180" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 10h4.764a2 2 0 011.789 2.894l-3.5 7A2 2 0 0115.263 21h-4.017c-.163 0-.326-.02-.485-.06L7 20m7-10V5a2 2 0 00-2-2h-.095c-.5 0-.905.405-.905.905 0 .714-.211 1.412-.608 2.006L7 11v9m7-10h-2M7 20H5a2 2 0 01-2-2v-6a2 2 0 012-2h2.5"/>
</svg>
{{ review.unhelpful_count }}
</button>
</div>
</div>
</div>
{% endfor %}
</div>
{% if reviews_total > 5 %}
<div class="mt-6 text-center">
<a href="{{ url_for('web.tool_reviews', owner=tool.owner, name=tool.name) }}"
class="text-sm text-indigo-600 hover:text-indigo-800">
View all {{ reviews_total }} reviews &rarr;
</a>
</div>
{% endif %}
{% else %}
<p class="text-gray-500 text-center py-8">
No reviews yet. {% if session.get('auth_token') %}Be the first to review this tool!{% endif %}
</p>
{% endif %}
</div>
<!-- Issues Section -->
<div id="issues" class="bg-white rounded-lg border border-gray-200 p-6 mt-6">
<div class="flex items-center justify-between mb-6">
<h2 class="text-xl font-bold text-gray-900">Issues</h2>
<button type="button" onclick="openIssueModal()"
class="inline-flex items-center px-4 py-2 text-sm font-medium text-gray-700 border border-gray-300 rounded-md hover:bg-gray-50">
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
</svg>
Report Issue
</button>
</div>
{% if issues %}
<div class="space-y-3">
{% for issue in issues %}
<div class="flex items-start p-3 border border-gray-200 rounded-lg hover:bg-gray-50">
<div class="flex-shrink-0">
<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium
{{ 'bg-red-100 text-red-800' if issue.issue_type == 'security' else
'bg-blue-100 text-blue-800' if issue.issue_type == 'bug' else
'bg-purple-100 text-purple-800' }}">
{{ issue.issue_type }}
</span>
</div>
<div class="ml-3 flex-1">
<p class="text-sm font-medium text-gray-900">{{ issue.title }}</p>
<p class="text-xs text-gray-500 mt-1">
<span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs
{{ 'bg-red-100 text-red-800' if issue.severity == 'critical' else
'bg-orange-100 text-orange-800' if issue.severity == 'high' else
'bg-yellow-100 text-yellow-800' if issue.severity == 'medium' else
'bg-gray-100 text-gray-800' }}">
{{ issue.severity }}
</span>
&middot; {{ issue.created_at|timeago }}
&middot; by {{ issue.reporter_name }}
</p>
</div>
<div class="flex-shrink-0 ml-2">
<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium
{{ 'bg-green-100 text-green-800' if issue.status in ('fixed', 'wontfix', 'duplicate') else
'bg-yellow-100 text-yellow-800' if issue.status == 'confirmed' else
'bg-gray-100 text-gray-800' }}">
{{ issue.status }}
</span>
</div>
</div>
{% endfor %}
</div>
{% if issues_total > 5 %}
<div class="mt-6 text-center">
<a href="{{ url_for('web.tool_issues', owner=tool.owner, name=tool.name) }}"
class="text-sm text-indigo-600 hover:text-indigo-800">
View all {{ issues_total }} issues &rarr;
</a>
</div>
{% endif %}
{% else %}
<p class="text-gray-500 text-center py-8">
No issues reported for this tool.
</p>
{% endif %}
</div>
</main>
<!-- Sidebar -->
@@ -206,9 +353,98 @@
</dd>
</div>
{% endif %}
{% if rating.unique_users %}
<div class="flex items-center justify-between">
<dt class="text-sm text-gray-500">Users</dt>
<dd class="text-sm font-medium text-gray-900">{{ rating.unique_users|format_number }}</dd>
</div>
{% endif %}
</dl>
</div>
<!-- Rating Summary -->
<div class="bg-white rounded-lg border border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4">Rating</h3>
{% if rating.rating_count and rating.rating_count > 0 %}
<div class="flex items-center mb-3">
<div class="flex items-center">
{% set avg = rating.average_rating|default(0)|float %}
{% for i in range(1, 6) %}
<svg class="w-5 h-5 {{ 'text-yellow-400' if i <= avg else 'text-gray-300' }}" fill="currentColor" viewBox="0 0 20 20">
<path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"/>
</svg>
{% endfor %}
</div>
<span class="ml-2 text-lg font-bold text-gray-900">{{ "%.1f"|format(avg) }}</span>
</div>
<p class="text-sm text-gray-500 mb-4">{{ rating.rating_count }} review{{ 's' if rating.rating_count != 1 else '' }}</p>
<!-- Rating Distribution -->
<div class="space-y-1">
{% for star in range(5, 0, -1) %}
{% set count = rating.distribution[star|string]|default(0) %}
{% set pct = (count / rating.rating_count * 100)|int if rating.rating_count else 0 %}
<div class="flex items-center text-sm">
<span class="w-4 text-gray-500">{{ star }}</span>
<svg class="w-4 h-4 text-yellow-400 mx-1" fill="currentColor" viewBox="0 0 20 20">
<path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"/>
</svg>
<div class="flex-1 h-2 bg-gray-200 rounded-full overflow-hidden mx-2">
<div class="h-full bg-yellow-400 rounded-full" style="width: {{ pct }}%"></div>
</div>
<span class="w-8 text-right text-gray-400">{{ count }}</span>
</div>
{% endfor %}
</div>
{% else %}
<p class="text-sm text-gray-500">No reviews yet</p>
{% endif %}
<a href="#reviews" class="mt-4 block text-sm text-indigo-600 hover:text-indigo-800">
{{ 'Write a review' if session.get('auth_token') else 'View all reviews' }} &rarr;
</a>
</div>
<!-- Issues Summary -->
{% if issues_total > 0 or rating.security_issues %}
<div class="bg-white rounded-lg border {{ 'border-red-300' if rating.security_issues else 'border-gray-200' }} p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4">Known Issues</h3>
{% if rating.security_issues %}
<div class="mb-4 p-3 bg-red-50 border border-red-200 rounded-lg">
<div class="flex items-center text-red-700">
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
</svg>
<span class="font-medium">{{ rating.security_issues }} security issue{{ 's' if rating.security_issues != 1 else '' }}</span>
</div>
</div>
{% endif %}
<dl class="space-y-2">
<div class="flex items-center justify-between">
<dt class="text-sm text-gray-500">Open issues</dt>
<dd class="text-sm font-medium text-gray-900">{{ rating.open_issues|default(0) }}</dd>
</div>
</dl>
{% if issues %}
<ul class="mt-4 space-y-2">
{% for issue in issues[:3] %}
<li class="text-sm">
<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium
{{ 'bg-red-100 text-red-800' if issue.severity == 'critical' else
'bg-orange-100 text-orange-800' if issue.severity == 'high' else
'bg-yellow-100 text-yellow-800' if issue.severity == 'medium' else
'bg-gray-100 text-gray-800' }}">
{{ issue.severity }}
</span>
<span class="ml-1 text-gray-700">{{ issue.title|truncate(40) }}</span>
</li>
{% endfor %}
</ul>
{% endif %}
<a href="#issues" class="mt-4 block text-sm text-indigo-600 hover:text-indigo-800">
View all issues &rarr;
</a>
</div>
{% endif %}
<!-- Publisher -->
<div class="bg-white rounded-lg border border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4">Publisher</h3>
@@ -299,6 +535,122 @@
</div>
</div>
<!-- Review Modal -->
<div id="review-modal" class="hidden fixed inset-0 z-50 overflow-y-auto" aria-modal="true" role="dialog">
<div class="min-h-screen px-4 text-center">
<div class="fixed inset-0 bg-black bg-opacity-50 transition-opacity" onclick="closeReviewModal()"></div>
<div class="inline-block w-full max-w-lg my-8 text-left align-middle bg-white shadow-xl rounded-lg">
<div class="p-6">
<h3 class="text-lg font-semibold text-gray-900">Write a Review</h3>
<p class="mt-2 text-sm text-gray-600">Share your experience with this tool.</p>
<div class="mt-6 space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">Rating</label>
<div class="flex items-center space-x-1" id="star-rating">
{% for i in range(1, 6) %}
<button type="button" onclick="setRating({{ i }})" data-star="{{ i }}"
class="star-btn p-1 text-gray-300 hover:text-yellow-400 transition-colors">
<svg class="w-8 h-8" fill="currentColor" viewBox="0 0 20 20">
<path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"/>
</svg>
</button>
{% endfor %}
<span id="rating-text" class="ml-3 text-sm text-gray-500">Select a rating</span>
</div>
<input type="hidden" id="review-rating" value="">
</div>
<div>
<label for="review-title" class="block text-sm font-medium text-gray-700 mb-1">Title (optional)</label>
<input type="text" id="review-title" maxlength="100" placeholder="Summarize your experience"
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="review-content" class="block text-sm font-medium text-gray-700 mb-1">Review</label>
<textarea id="review-content" rows="4" maxlength="2000"
placeholder="Tell others about your experience with this tool..."
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 resize-none"></textarea>
<p class="mt-1 text-xs text-gray-400"><span id="review-char-count">0</span>/2000</p>
</div>
</div>
</div>
<div class="bg-gray-50 px-6 py-4 rounded-b-lg flex justify-end gap-3">
<button type="button" onclick="closeReviewModal()"
class="px-4 py-2 text-sm font-medium text-gray-700 hover:text-gray-900">
Cancel
</button>
<button type="button" onclick="submitReview()"
class="px-4 py-2 text-sm font-medium text-white bg-indigo-600 rounded-md hover:bg-indigo-700">
Submit Review
</button>
</div>
</div>
</div>
</div>
<!-- Issue Modal -->
<div id="issue-modal" class="hidden fixed inset-0 z-50 overflow-y-auto" aria-modal="true" role="dialog">
<div class="min-h-screen px-4 text-center">
<div class="fixed inset-0 bg-black bg-opacity-50 transition-opacity" onclick="closeIssueModal()"></div>
<div class="inline-block w-full max-w-lg my-8 text-left align-middle bg-white shadow-xl rounded-lg">
<div class="p-6">
<h3 class="text-lg font-semibold text-gray-900">Report an Issue</h3>
<p class="mt-2 text-sm text-gray-600">Help improve this tool by reporting bugs or security issues.</p>
<div class="mt-6 space-y-4">
<div>
<label for="issue-type" class="block text-sm font-medium text-gray-700 mb-1">Issue Type</label>
<select id="issue-type" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500">
<option value="bug">Bug</option>
<option value="security">Security Issue</option>
<option value="compatibility">Compatibility</option>
</select>
</div>
<div>
<label for="issue-severity" class="block text-sm font-medium text-gray-700 mb-1">Severity</label>
<select id="issue-severity" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500">
<option value="low">Low</option>
<option value="medium" selected>Medium</option>
<option value="high">High</option>
<option value="critical">Critical</option>
</select>
</div>
<div>
<label for="issue-title" class="block text-sm font-medium text-gray-700 mb-1">Title</label>
<input type="text" id="issue-title" maxlength="200" required placeholder="Brief description of the issue"
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="issue-description" class="block text-sm font-medium text-gray-700 mb-1">Description</label>
<textarea id="issue-description" rows="4" maxlength="5000"
placeholder="Steps to reproduce, expected behavior, actual behavior..."
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 resize-none"></textarea>
</div>
</div>
</div>
<div class="bg-gray-50 px-6 py-4 rounded-b-lg flex justify-end gap-3">
<button type="button" onclick="closeIssueModal()"
class="px-4 py-2 text-sm font-medium text-gray-700 hover:text-gray-900">
Cancel
</button>
<button type="button" onclick="submitIssue()"
class="px-4 py-2 text-sm font-medium text-white bg-indigo-600 rounded-md hover:bg-indigo-700">
Submit Issue
</button>
</div>
</div>
</div>
</div>
<script>
function copyInstall() {
const cmd = 'cmdforge install {{ tool.owner }}/{{ tool.name }}';
@@ -314,5 +666,143 @@ function copyInstall() {
});
}
// Review Modal Functions
let selectedRating = 0;
const ratingTexts = ['', 'Poor', 'Fair', 'Good', 'Very Good', 'Excellent'];
function openReviewModal() {
document.getElementById('review-modal').classList.remove('hidden');
document.body.style.overflow = 'hidden';
}
function closeReviewModal() {
document.getElementById('review-modal').classList.add('hidden');
document.body.style.overflow = '';
// Reset form
selectedRating = 0;
updateStars();
document.getElementById('review-title').value = '';
document.getElementById('review-content').value = '';
document.getElementById('review-char-count').textContent = '0';
}
function setRating(rating) {
selectedRating = rating;
document.getElementById('review-rating').value = rating;
document.getElementById('rating-text').textContent = ratingTexts[rating];
updateStars();
}
function updateStars() {
document.querySelectorAll('.star-btn').forEach(btn => {
const star = parseInt(btn.dataset.star);
if (star <= selectedRating) {
btn.classList.remove('text-gray-300');
btn.classList.add('text-yellow-400');
} else {
btn.classList.add('text-gray-300');
btn.classList.remove('text-yellow-400');
}
});
}
document.getElementById('review-content')?.addEventListener('input', function() {
document.getElementById('review-char-count').textContent = this.value.length;
});
function submitReview() {
const rating = selectedRating;
const title = document.getElementById('review-title').value.trim();
const content = document.getElementById('review-content').value.trim();
if (!rating) {
alert('Please select a rating');
return;
}
fetch('/api/v1/tools/{{ tool.owner }}/{{ tool.name }}/reviews', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + (document.cookie.match(/auth_token=([^;]+)/)?.[1] || '')
},
body: JSON.stringify({ rating, title, content })
})
.then(response => response.json())
.then(data => {
if (data.error) {
alert(data.error.message || 'Failed to submit review');
} else {
closeReviewModal();
window.location.reload();
}
})
.catch(err => {
alert('Failed to submit review. Please try again.');
});
}
// Issue Modal Functions
function openIssueModal() {
document.getElementById('issue-modal').classList.remove('hidden');
document.body.style.overflow = 'hidden';
}
function closeIssueModal() {
document.getElementById('issue-modal').classList.add('hidden');
document.body.style.overflow = '';
// Reset form
document.getElementById('issue-type').value = 'bug';
document.getElementById('issue-severity').value = 'medium';
document.getElementById('issue-title').value = '';
document.getElementById('issue-description').value = '';
}
function submitIssue() {
const issue_type = document.getElementById('issue-type').value;
const severity = document.getElementById('issue-severity').value;
const title = document.getElementById('issue-title').value.trim();
const description = document.getElementById('issue-description').value.trim();
if (!title) {
alert('Please provide a title');
return;
}
fetch('/api/v1/tools/{{ tool.owner }}/{{ tool.name }}/issues', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ issue_type, severity, title, description })
})
.then(response => response.json())
.then(data => {
if (data.error) {
alert(data.error.message || 'Failed to submit issue');
} else {
closeIssueModal();
window.location.reload();
}
})
.catch(err => {
alert('Failed to submit issue. Please try again.');
});
}
// Vote Functions
function voteReview(reviewId, voteType) {
fetch('/api/v1/reviews/' + reviewId + '/vote', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ vote: voteType })
})
.then(response => response.json())
.then(data => {
if (!data.error) {
window.location.reload();
}
});
}
</script>
{% endblock %}