Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reportcomment #71

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'devise'
gem 'redactor-rails'
gem "mini_magick"
gem 'carrierwave'
gem 'carrierwave'
gem 'mini_magick'
gem 'cancan'
Expand Down
40 changes: 28 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ GEM
tzinfo (~> 1.1)
arel (6.0.0)
bcrypt (3.1.10)
bcrypt (3.1.10-x86-mingw32)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
byebug (3.5.1)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
slop (~> 3.6)
byebug (4.0.3)
columnize (= 0.9.0)
cancan (1.6.10)
carrierwave (0.10.0)
activemodel (>= 3.2.0)
Expand All @@ -57,10 +56,9 @@ GEM
coffee-script (2.3.0)
coffee-script-source
execjs
coffee-script-source (1.9.1)
coffee-script-source (1.8.0)
columnize (0.9.0)
debug_inspector (0.0.2)
debugger-linecache (1.2.0)
devise (3.4.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand All @@ -83,7 +81,7 @@ GEM
activesupport (>= 4.1.0)
hike (1.2.3)
i18n (0.7.0)
jbuilder (2.2.11)
jbuilder (2.2.12)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (4.0.3)
Expand All @@ -96,12 +94,14 @@ GEM
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.4.3)
mini_magick (4.1.0)
mini_magick (4.2.0)
mini_portile (0.6.2)
minitest (5.5.1)
multi_json (1.11.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
nokogiri (1.6.6.2-x86-mingw32)
mini_portile (~> 0.6.0)
orm_adapter (0.5.0)
rack (1.6.0)
rack-test (0.6.3)
Expand All @@ -119,11 +119,11 @@ GEM
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.5)
rails-dom-testing (1.0.6)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.1)
rails-html-sanitizer (1.0.2)
loofah (~> 2.0)
railties (4.2.0)
actionpack (= 4.2.0)
Expand All @@ -132,12 +132,15 @@ GEM
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rdoc (4.2.0)
json (~> 1.4)
redactor-rails (0.5.0)
devise
mime-types
orm_adapter
responders (2.1.0)
railties (>= 4.2.0, < 5)
<<<<<<< HEAD
=======
rspec-core (3.2.3)
rspec-support (~> 3.2.0)
rspec-expectations (3.2.1)
Expand All @@ -155,6 +158,7 @@ GEM
rspec-mocks (~> 3.2.0)
rspec-support (~> 3.2.0)
rspec-support (3.2.2)
>>>>>>> 7e82538ecad07b868cf6a42bca170df9527169a3
sass (3.4.13)
sass-rails (5.0.1)
railties (>= 4.0.0, < 5.0)
Expand All @@ -165,12 +169,15 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
<<<<<<< HEAD
=======
simplecov (0.9.2)
docile (~> 1.1.0)
multi_json (~> 1.0)
simplecov-html (~> 0.9.0)
simplecov-html (0.9.0)
slop (3.6.0)
>>>>>>> 7e82538ecad07b868cf6a42bca170df9527169a3
spring (1.3.3)
sprockets (2.12.3)
hike (~> 1.2)
Expand All @@ -182,8 +189,9 @@ GEM
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10)
sqlite3 (1.3.10-x86-mingw32)
thor (0.19.1)
thread_safe (0.3.4)
thread_safe (0.3.5)
tilt (1.4.1)
turbolinks (2.5.3)
coffee-rails
Expand All @@ -194,25 +202,29 @@ GEM
railties (~> 4.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)
tzinfo-data (1.2015.2)
tzinfo (>= 1.0.0)
uglifier (2.7.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
warden (1.2.3)
rack (>= 1.0)
web-console (2.1.1)
web-console (2.1.2)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)

PLATFORMS
ruby
x86-mingw32

DEPENDENCIES
byebug
cancan
carrierwave
coffee-rails (~> 4.1.0)
coffee-script-source (= 1.8.0)
devise
factory_girl_rails
font-awesome-rails
Expand All @@ -221,13 +233,17 @@ DEPENDENCIES
mini_magick
rails (= 4.2.0)
redactor-rails
<<<<<<< HEAD
=======
rspec-rails (~> 3.0)
>>>>>>> 7e82538ecad07b868cf6a42bca170df9527169a3
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
simplecov
spring
sqlite3
turbolinks
twitter-bootstrap-rails
tzinfo-data
uglifier (>= 1.3.0)
web-console (~> 2.0)
Binary file added UML Wordspace/sequence_diagram_s17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/assets/javascripts/magazines.coffee
100755 → 100644
Empty file.
Empty file modified app/assets/stylesheets/magazines.scss
100755 → 100644
Empty file.
11 changes: 10 additions & 1 deletion app/controllers/articles_controller.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ def check_for_cancel
return false if params[:commit] != 'Cancel'
redirect_to @article
end
end

# Report an article
def report
reportarticlehash = { "user_id" => current_user.id,
"article_id" => params[:id] }
Reportarticle.create(reportarticlehash)
@article = Article.find(params[:id])
redirect_to @article
end

private

Expand All @@ -101,4 +111,3 @@ def article_params
params.require(:article).permit(:title, :body, :user_id, :id, :image,
:magazine_id)
end
end
17 changes: 17 additions & 0 deletions app/controllers/comments_controller.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ def edit
def new
end

def report
# Author:Mina Hany
# 8.4.2015
# A hash is created containing user's id who wants to report a comment
# and that comment's id and it is added to model contaioning reported requests
@report = Reportcomment.where(
"user_id = ? AND comment_id = ?", current_user.id, @comment.id)
@article = Article.find(params[:id])
if @report.present?
redirect_to @article && return
end
reportcommenthash = { "user_id" => current_user.id,
"comment_id" => @comment.id }
Reportcomment.create(reportcommenthash)
redirect_to @article
end

def comment_params
params.require(:comment).permit(:user_id, :article_id, :des)
end
Expand Down
Empty file modified app/controllers/magazines_controller.rb
100755 → 100644
Empty file.
Empty file modified app/helpers/magazines_helper.rb
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions app/models/ability.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# You don't need to be signed in to view Comments or replies. But, you need to be signed in in order to add any of them. Also you can delete or edit them if you wrote them. A moderator can delete any of them.
class Ability
include CanCan::Ability

def initialize(user)
can :show, Article
can :show, Comment
Expand All @@ -13,15 +12,16 @@ def initialize(user)
article.user_id == user.id
end
can :create, Article
can :report, Article
can :create, Magazine
can :update, Comment do |c|
c.user_id == user.id
end
can :destroy, Comment do |co|
co.user_id == user.id
end
can :report, Comment
can :create, Comment

can :update, Reply do |r|
r.user_id == user.id
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/article.rb
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Article Model
class Article < ActiveRecord::Base
has_many :reportarticles
has_many :users, through: :reportarticles
# adding The uploader to Image field
# adding relation between user and articles
mount_uploader :image, ImgUploader
Expand Down
2 changes: 2 additions & 0 deletions app/models/comment.rb
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Comment Model
class Comment < ActiveRecord::Base
has_many :users, through: :reportcomments
has_many :reportcomments
# A comment belongs to an Article
# and has many replies
# and has a field for description
Expand Down
Empty file modified app/models/magazine.rb
100755 → 100644
Empty file.
4 changes: 4 additions & 0 deletions app/models/reportarticle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Reportarticle < ActiveRecord::Base
belongs_to :user
belongs_to :article
end
4 changes: 4 additions & 0 deletions app/models/reportcomment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Reportcomment < ActiveRecord::Base
belongs_to :comment
belongs_to :user
end
7 changes: 7 additions & 0 deletions app/models/user.rb
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# User Model
class User < ActiveRecord::Base
# many-to-many relation between user and comment
# user can report many comments
# comment can be reported by many users
has_many :reportcomments
has_many :comments, through: :reportcomments
has_many :reportarticles
has_many :articles, through: :reportarticles
# to upload avatar for user
mount_uploader :avatar, AvatarUploader
has_many :magazines
Expand Down
3 changes: 3 additions & 0 deletions app/views/articles/_comment.html.erb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<% if can? :update, comment %>
<%= link_to 'Edit', edit_comment_path(comment)%>
<% end %>
<% if can? :report, comment %>
<%= link_to 'Report',action: "report",controller: "comments" %>
<% end %>
</div>
<div class="row">
<div class="col-md-1"></div>
Expand Down
8 changes: 7 additions & 1 deletion app/views/articles/show.html.erb
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!-- A simple note displayed on the top to notify the user whether he/she reported this article before -->
<% if Reportarticle.where("user_id = ? AND article_id = ?", current_user.id ,params[:id]).present? %>
<%= flash[:notice] = "You have reported this article." %>
<% end %>

<div class="row">
<!-- empty column for layouts -->
<!-- main image for the article setting image width & hight to not get out of the border if there is no image for the article a default one is set-->
Expand Down Expand Up @@ -41,8 +46,9 @@
<p><font size="3"><%= @article.body.html_safe %></font></p>
</div>
</div>
<div class="col-md-2"></div>
<div class="col-md-2"></div>
</div>
<%= link_to 'Report this article', action: "report" %>
<!....This is the part where we call all comments.....>
<%= render :partial => 'comment', :collection => @article.comments %>
<div class="col-md-2"></div>
Expand Down
Empty file modified app/views/magazines/_form.html.erb
100755 → 100644
Empty file.
Empty file modified app/views/magazines/edit.html.erb
100755 → 100644
Empty file.
Empty file modified app/views/magazines/index.html.erb
100755 → 100644
Empty file.
Empty file modified app/views/magazines/index.json.jbuilder
100755 → 100644
Empty file.
Empty file modified app/views/magazines/new.html.erb
100755 → 100644
Empty file.
Empty file modified app/views/magazines/show.html.erb
100755 → 100644
Empty file.
Empty file modified app/views/magazines/show.json.jbuilder
100755 → 100644
Empty file.
Empty file modified bin/bundler
100755 → 100644
Empty file.
Empty file modified bin/byebug
100755 → 100644
Empty file.
Empty file modified bin/erubis
100755 → 100644
Empty file.
Empty file modified bin/htmldiff
100755 → 100644
Empty file.
Empty file modified bin/ldiff
100755 → 100644
Empty file.
Empty file modified bin/nokogiri
100755 → 100644
Empty file.
Empty file modified bin/rackup
100755 → 100644
Empty file.
Empty file modified bin/rdoc
100755 → 100644
Empty file.
Empty file modified bin/ri
100755 → 100644
Empty file.
Empty file modified bin/rspec
100755 → 100644
Empty file.
Empty file modified bin/sass
100755 → 100644
Empty file.
Empty file modified bin/sass-convert
100755 → 100644
Empty file.
Empty file modified bin/scss
100755 → 100644
Empty file.
Empty file modified bin/sdoc
100755 → 100644
Empty file.
Empty file modified bin/sdoc-merge
100755 → 100644
Empty file.
Empty file modified bin/sprockets
100755 → 100644
Empty file.
Empty file modified bin/thor
100755 → 100644
Empty file.
Empty file modified bin/tilt
100755 → 100644
Empty file.
14 changes: 12 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@

# adding resources
resources :sponsors
resources :articles do
member do
get 'report'
end
end
# specifying route for report action in comment controller
resources :comments do
member do
get 'report'
end
end
resources :replies
resources :articles
resources :comments
resources :replies
resources :collaboration_invitations do
collection do
get 'check_for_approve'
Expand All @@ -16,7 +27,6 @@
devise_for :users
get 'main/index'
root 'main#index'
resources :articles
# Search url matching
get '/search' => 'search#search'
end
Expand Down
9 changes: 0 additions & 9 deletions coverage/.last_run.json

This file was deleted.

Loading