Added authorization + issues dashboard
authorShrey <shrey14099@iiitd.ac.in>
Tue, 26 May 2015 12:42:43 +0000 (18:12 +0530)
committerMatt Amos <zerebubuth@gmail.com>
Mon, 22 Aug 2016 15:14:10 +0000 (16:14 +0100)
app/assets/stylesheets/common.scss
app/controllers/issues_controller.rb
app/helpers/issues_helper.rb
app/models/issue.rb
app/models/user.rb
app/views/diary_entry/_diary_entry.html.erb
app/views/issues/_reports.html.erb [new file with mode: 0644]
app/views/issues/index.html.erb
app/views/issues/show.html.erb
config/locales/en-GB.yml
config/locales/en.yml

index b2b6057bee6951fbf81f3963dbecec6094d7e528..24538ebfeb7d1dcaeb3e8a45f2af2cd92968cdd0 100644 (file)
@@ -2739,3 +2739,8 @@ input.richtext_title[type="text"] {
     display: none;
   }
 }
     display: none;
   }
 }
+
+.read-reports {
+  background: #eee;
+  opacity: 0.7;
+}
index 0479e66418f805d3f69d4a4e2e3673729bb58e89..6ca61b4ce5eea3200d7ac3649c254b1479ef1b90 100644 (file)
@@ -1,6 +1,8 @@
 class IssuesController < ApplicationController
   layout "site"
 
 class IssuesController < ApplicationController
   layout "site"
 
+  before_action :authorize_web
+  before_action :check_permission, only: [:index, :show, :resolve,:open,:ignore]
   before_action :find_issue, only: [:show, :resolve, :reopen, :ignore]
 
   def index
   before_action :find_issue, only: [:show, :resolve, :reopen, :ignore]
 
   def index
@@ -71,6 +73,13 @@ class IssuesController < ApplicationController
       @issue = Issue.find(params[:id])
     end
 
       @issue = Issue.find(params[:id])
     end
 
+    def check_permission
+      unless @user.administrator?
+        flash[:error] = t("application.require_admin.not_an_admin")
+        redirect_to root_path
+      end
+    end
+
     def create_new_issue_params
       params.permit(:reportable_id, :reportable_type, :user_id)
     end
     def create_new_issue_params
       params.permit(:reportable_id, :reportable_type, :user_id)
     end
@@ -80,6 +89,6 @@ class IssuesController < ApplicationController
     end
 
     def report_params
     end
 
     def report_params
-      params[:report].permit(:details)
+      params[:report].permit(:details, :user_id)
     end
 end
     end
 end
index bfb9d25e5641b5809d8428fde68b027c8bc07743..7e9e233df064eea7faf89bf64759ed250a7340ea 100644 (file)
@@ -1,2 +1,25 @@
 module IssuesHelper
 module IssuesHelper
+
+       def reportable_url(reportable)
+               class_name = reportable.class.name
+               case class_name
+               when "DiaryEntry"
+                       link_to reportable.title,       :controller => reportable.class.name.underscore,
+                                                                                                                               :action => :view,
+                                                                                                                               :display_name => reportable.user.display_name,
+                                                                                                                               :id => reportable.id
+               when "User"
+                       link_to reportable.display_name,        :controller => reportable.class.name.underscore,
+                                                                                                                                                               :action => "view",
+                                                                                                                                                               :display_name => reportable.diary_entry.user.display_name
+               when "DiaryComment"
+                       link_to "#{reportable.diary_entry.title} Comment id ##{reportable.id}", :controller => reportable.diary_entry.class.name.underscore,
+                                                                                                               :action => :view,
+                                                                                                               :display_name => reportable.diary_entry.user.display_name,
+                                                                                                               :id => reportable.id
+
+               else
+                       nil
+               end
+       end
 end
 end
index 1726e690fe2d3c33f14560bffb07dfe79bc6507a..277ea3569ca94fe003cfa456b6372ce498519648 100644 (file)
@@ -2,7 +2,7 @@ class Issue < ActiveRecord::Base
        belongs_to :reportable, :polymorphic => true
        has_many :reports
        validates :reportable_id, :uniqueness => { :scope => [ :reportable_type ] }
        belongs_to :reportable, :polymorphic => true
        has_many :reports
        validates :reportable_id, :uniqueness => { :scope => [ :reportable_type ] }
-       belongs_to :user_id
+       belongs_to :user
 
        # Check if more statuses are needed
        enum status: %w( open ignored resolved )
 
        # Check if more statuses are needed
        enum status: %w( open ignored resolved )
index a550b9f05fd2a8ddd891b9dd134e58a04898d88a..4a36b3e61e5c2dbca369528bae2356f7dcc87f22 100644 (file)
@@ -26,6 +26,9 @@ class User < ActiveRecord::Base
 
   has_many :roles, :class_name => "UserRole"
 
 
   has_many :roles, :class_name => "UserRole"
 
+  has_many :issues
+  has_many :reports
+
   scope :visible, -> { where(:status => %w(pending active confirmed)) }
   scope :active, -> { where(:status => %w(active confirmed)) }
   scope :identifiable, -> { where(:data_public => true) }
   scope :visible, -> { where(:status => %w(pending active confirmed)) }
   scope :active, -> { where(:status => %w(active confirmed)) }
   scope :identifiable, -> { where(:data_public => true) }
index 410e13047663bb32439a90da611a646906216a5c..efcd2ec4744f53675e6a6472342c7096d896e7a7 100644 (file)
@@ -31,6 +31,8 @@
       <%= link_to t('diary_entry.diary_entry.edit_link'), :action => 'edit', :display_name => diary_entry.user.display_name, :id => diary_entry.id %>
     <% end %>
 
       <%= link_to t('diary_entry.diary_entry.edit_link'), :action => 'edit', :display_name => diary_entry.user.display_name, :id => diary_entry.id %>
     <% end %>
 
+      <li><%= link_to 'Report', new_issue_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name, user: diary_entry.user.id) %></li>
+
     <%= if_administrator(:li) do %>
       <%= link_to t('diary_entry.diary_entry.hide_link'), hide_diary_entry_path(:display_name => diary_entry.user.display_name, :id => diary_entry.id), :method => :post, :data => { :confirm => t('diary_entry.diary_entry.confirm') } %>
     <% end %>
     <%= if_administrator(:li) do %>
       <%= link_to t('diary_entry.diary_entry.hide_link'), hide_diary_entry_path(:display_name => diary_entry.user.display_name, :id => diary_entry.id), :method => :post, :data => { :confirm => t('diary_entry.diary_entry.confirm') } %>
     <% end %>
diff --git a/app/views/issues/_reports.html.erb b/app/views/issues/_reports.html.erb
new file mode 100644 (file)
index 0000000..0a55a59
--- /dev/null
@@ -0,0 +1,11 @@
+<% reports.each do |report| %>
+       <div class="reports">
+               <div class="display:inline">
+                       <%= user_thumbnail report.user %>
+                       <%= report.details %>
+               </div>
+               <span class="deemphasize"><%= raw(t('Reported by:',:link_user => (link_to h(report.user.display_name), :controller => :user, :action => :view, :display_name => report.user.display_name), :comment_created_at => link_to(l(report.created_at,:format => :friendly)))) %>
+               on <%= l report.created_at.to_datetime, :format => :long %> </span>
+       </div>
+       <hr>
+<% end %>
index 83fe41be954d2a325628638629e108fe11f76265..a599abb994ec4907dae06a8de4164bcca495cc38 100644 (file)
@@ -1,2 +1,36 @@
-<h1>Issues#index</h1>
-<p>Find me in app/views/issues/index.html.erb</p>
+<p id= "notice"><%= notice %></p>
+
+<% content_for :heading do %>
+       <h1>List of existing Issues:</h1>
+<% end %>
+
+<table>
+       <thead>
+               <tr>
+                       <tr>
+                               <td style="text-align:center"><b> # </b> </td>
+                               <td style="text-align:center"><b>Issue Type </b></td>
+                               <td style="text-align:center"><b> Status </b></td>
+                               <td style="text-align:center"><b> Number of Reports</b></td>
+                               <td style="text-align:center"><b> Link to instance </b></td>
+                               <td style="text-align:center"><b> Reported User </b></td>
+                               <td style="text-align:center"></td>
+                       </tr>
+               </tr>
+       </thead>
+       <tbody>
+               <% @issues.each do |issue| %>
+                       <tr>
+                               <td style="text-align:center">Issue #<%= issue.id %> </td>
+                               <td style="text-align:center"> <%= issue.reportable_type %></td>
+                               <td style="text-align:center"><span class="count-number"> <strong><%= issue.status %></strong></span> </td>
+                               <td style="text-align:center"><%= issue.reports.count %></td>
+                               <td style="text-align:center"> <%= reportable_url(issue.reportable) %></td>
+                               <td style="text-align:center"><%= link_to issue.user.display_name , :controller => :user, :action => :view,:display_name => issue.user.display_name %></td>
+                               <td style="text-align:center"><%= link_to "Show Issue", issue %></td>
+                       </tr>
+               <% end %>
+       </tbody>
+</table>
+
+
index 1c3b8bb653b1f047fe0c8ce138668515f14eb56c..d756595cf9335f6123c908cf6a660a2055923336 100644 (file)
@@ -1,2 +1,29 @@
-<h1>Issues#show</h1>
-<p>Find me in app/views/issues/show.html.erb</p>
+<% content_for :heading do %>
+       <h2> Issue #<%= @issue.id %> <br/> <span class="count-number">Status: <strong><%= @issue. status %></strong></span></h2>
+       <p>Issue against: <%= reportable_url(@issue.reportable) %></p>
+       <p>Issue type: <%= @issue.reportable_type %></p>
+       <p class="deemphasize">
+               <small>
+                       <%= @issue.reports.count %> reports | First reported: <%= l @issue.created_at.to_date, :format => :long %> | <%= "Last resolved at #{l(@issue.resolved_at.to_datetime, :format =>:long)}" if @issue.resolved? %>
+               </small>
+       </p>
+       <p><%= link_to "Resolve", resolve_issue_url(@issue), :method => :post if @issue.may_resolve? %></p>
+       <p><%= link_to "Ignore", ignore_issue_url(@issue), :method => :post if @issue.may_ignore? %></p>
+       <p><%= link_to "Reopen", reopen_issue_url(@issue), :method => :post if @issue.may_reopen? %></p>
+<% end %>
+
+<h3>Reports under this issue:</h3>
+
+<% if @read_reports.present? %>
+       <div class="read-reports">
+               <h4>Read Reports:</h4>
+               <%= render 'reports',reports: @read_reports %>
+       </div>
+<% end %>      
+
+<% if @unread_reports.any? %>
+       <div class="unread-reports">
+               <h4>New Reports:</h4>
+               <%= render 'reports',reports: @unread_reports %>
+       </div>
+<% end %>      
index 101b71e2e7ab3ce119abadaff4f8c95273fa5272..f3f2a6859b93cfba616636c624ec98be75addaed 100644 (file)
@@ -1675,6 +1675,8 @@ en-GB:
     require_cookies:
       cookies_needed: You appear to have cookies disabled - please enable cookies
         in your browser before continuing.
     require_cookies:
       cookies_needed: You appear to have cookies disabled - please enable cookies
         in your browser before continuing.
+    require_admin:
+      not_an_admin: You need to be an admin to perform that action.
     require_moderator:
       not_a_moderator: You need to be a moderator to perform that action.
     setup_user_auth:
     require_moderator:
       not_a_moderator: You need to be a moderator to perform that action.
     setup_user_auth:
index 3c9ec7131a68f5b03416de2ca5bb1fdd8becd838..9a03a6a7f16aeca62dd87689bd3cc79101374e98 100644 (file)
@@ -1624,6 +1624,8 @@ en:
   application:
     require_cookies:
       cookies_needed: "You appear to have cookies disabled - please enable cookies in your browser before continuing."
   application:
     require_cookies:
       cookies_needed: "You appear to have cookies disabled - please enable cookies in your browser before continuing."
+    require_admin:
+      not_an_admin: You need to be an admin to perform that action.
     require_moderator:
       not_a_moderator: "You need to be a moderator to perform that action."
     setup_user_auth:
     require_moderator:
       not_a_moderator: "You need to be a moderator to perform that action."
     setup_user_auth: