Skip to content

Commit ae2e9c8

Browse files
author
Theresa
committed
Adapt user abilities for rating and exercise user name showing
1 parent 0370dcc commit ae2e9c8

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

app/models/ability.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def initialize(user)
3030
end
3131
elsif user.role == 'user'
3232
can :read, Exercise
33-
can :create, Rating
33+
can :read, Rating
3434
can :read, Comment
3535
can :manage, User do |_user|
3636
_user == user

app/views/comments/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<td><%= comment.text %></td>
2828
<% if !comment.user %>
2929
<td> <%= 'User undefined' %> </td>
30-
<% elsif comment.user.first_name.nil?%>
30+
<% elsif comment.user.first_name.nil? || current_user.role === 'user'%>
3131
<td><%= "User#{comment.user.id}"%></td>
3232
<% else %>
3333
<td><%= comment.user.name%></td>

app/views/exercises/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<dt><%= 'Created by' %>:</dt>
1717
<% if !@exercise.user %>
1818
<dd><%= 'User undefined' %></dd>
19-
<% elsif @exercise.user.first_name.nil?%>
19+
<% elsif @exercise.user.first_name.nil? || current_user.role === 'user'%>
2020
<dd><%= "User#{@exercise.user.id}"%></dd>
2121
<% else %>
2222
<dd><%= @exercise.user.name %></dd>

app/views/home/_exercises.html.erb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<h3 class="panel-title"> <span><%= link_to exercise.title, exercise_path(exercise) %></span>
55
<span class="star-rating pull-right">
66
<% [*1..5].each do |i| %>
7-
<a href="/exercises/<%= exercise.id %>/ratings?rating[rating]=<%= i %>" data-method="post">
7+
<% if can? :create, Rating %>
8+
<a href="/exercises/<%= exercise.id %>/ratings?rating[rating]=<%= i %>" data-method="post">
9+
<% end %>
810
<% if exercise.round_avg_rating >= i %>
911
<span class="fa fa-star" data-rating="<%= i %>"></span>
1012
<% elsif (exercise.round_avg_rating + 0.5) >= i %>
@@ -15,7 +17,6 @@
1517
</a>
1618
<% end %>
1719
<small><%= exercise.ratings.count %> ratings</small>
18-
<input type="hidden" name="whatever" class="rating-value" value="3">
1920
</span>
2021
</h3>
2122
</div>
@@ -27,7 +28,7 @@
2728
</div>
2829

2930
<div class="btn-group-vertical pull-right" role="group" aria-label="...">
30-
<%= link_to 'Select', exercise_path(exercise), class:'btn btn-default' %>
31+
<%= link_to 'View', exercise_path(exercise), class:'btn btn-default' %>
3132
<%= link_to 'Show Comments', exercise_comments_path(exercise), class:'btn btn-default' %>
3233
<% if can? :create, exercise %>
3334
<%= link_to 'Duplicate', duplicate_exercise_path(exercise), class:'btn btn-default' %>

0 commit comments

Comments
 (0)