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

Reportarticle #70

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
33 changes: 19 additions & 14 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,12 @@ 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)
rspec-core (3.2.3)
rspec-support (~> 3.2.0)
rspec-expectations (3.2.1)
Expand All @@ -164,7 +164,6 @@ GEM
tilt (~> 1.1)
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
simplecov (0.9.2)
docile (~> 1.1.0)
multi_json (~> 1.0)
Expand All @@ -182,8 +181,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 +194,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 @@ -229,5 +233,6 @@ DEPENDENCIES
sqlite3
turbolinks
twitter-bootstrap-rails
tzinfo-data
uglifier (>= 1.3.0)
web-console (~> 2.0)
Binary file added UML Wordspace/sequence_diagram_s20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions app/controllers/articles_controller.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def show
@comment = Comment.new(params[:comment])
@replies = Reply.all
@reply = Reply.new(params[:reply])
@report = Reportarticle.where("user_id = ? AND article_id = ?", current_user.id ,params[:id])
end

# GET /articles/new
Expand Down Expand Up @@ -89,6 +90,23 @@ def check_for_cancel
redirect_to @article
end

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

private

# Use callbacks to share common setup or constraints between actions.
Expand Down
2 changes: 1 addition & 1 deletion 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,6 +12,7 @@ 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
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
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
2 changes: 2 additions & 0 deletions app/models/user.rb
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# User Model
class User < ActiveRecord::Base
has_many :reportarticles
has_many :articles, through: :reportarticles
# to upload avatar for user
mount_uploader :avatar, AvatarUploader
has_many :magazines
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 @report.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
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

# adding resources
resources :sponsors
resources :articles do
member do
get 'report'
end
end
resources :articles
resources :comments
resources :replies
Expand All @@ -16,7 +21,6 @@
devise_for :users
get 'main/index'
root 'main#index'
resources :articles
# Search url matching
get '/search' => 'search#search'
end
Expand Down
Binary file modified db/development.sqlite3
Binary file not shown.
12 changes: 12 additions & 0 deletions db/migrate/20150327104939_create_reportarticles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateReportarticles < ActiveRecord::Migration
def change
create_table :reportarticles do |t|
t.references :user, index: true
t.references :article, index: true

t.timestamps null: false
end
add_foreign_key :reportarticles, :users
add_foreign_key :reportarticles, :articles
end
end
22 changes: 20 additions & 2 deletions db/schema.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150407210738) do

create_table "articles", force: :cascade do |t|
t.text "title"
t.text "body"
Expand Down Expand Up @@ -92,6 +90,26 @@
t.datetime "updated_at", null: false
end

create_table "reportarticles", force: :cascade do |t|
t.integer "user_id"
t.integer "article_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "reportarticles", ["article_id"], name: "index_reportarticles_on_article_id"
add_index "reportarticles", ["user_id"], name: "index_reportarticles_on_user_id"

create_table "requestjoiningmagazines", force: :cascade do |t|
t.integer "user_id"
t.integer "magazine_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "requestjoiningmagazines", ["magazine_id"], name: "index_requestjoiningmagazines_on_magazine_id"
add_index "requestjoiningmagazines", ["user_id"], name: "index_requestjoiningmagazines_on_user_id"

create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
Expand Down
Loading