diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index ace3949..3075012 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -3,6 +3,7 @@ class StoriesController < ApplicationController :only => [ :upvote, :downvote, :unvote, :hide, :unhide, :preview ] before_filter :require_logged_in_user, :only => [ :destroy, :create, :edit, :fetch_url_attributes, :new, :suggest ] + before_filter :verify_user_can_submit_stories, :only => [ :new, :create ] before_filter :find_user_story, :only => [ :destroy, :edit, :undelete, :update ] before_filter :find_story!, :only => [ :suggest, :submit_suggestions ] @@ -378,4 +379,11 @@ private end end end + + def verify_user_can_submit_stories + if !@user.can_submit_stories? + flash[:error] = "You are not allowed to submit new stories." + return redirect_to "/" + end + end end diff --git a/app/models/user.rb b/app/models/user.rb index 4df0b97..528adf5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -64,6 +64,9 @@ class User < ActiveRecord::Base # minimum karma required to be able to offer title/tag suggestions MIN_KARMA_TO_SUGGEST = 10 + # minimum karma required to be able to submit new stories + MIN_KARMA_TO_SUBMIT_STORIES = -4 + def self.recalculate_all_karmas! User.all.each do |u| u.karma = u.stories.map(&:score).sum + u.comments.map(&:score).sum @@ -178,10 +181,18 @@ class User < ActiveRecord::Base false end + def can_invite? + !disabled_invite_at? && self.can_submit_stories? + end + def can_offer_suggestions? !self.is_new? && (self.karma >= MIN_KARMA_TO_SUGGEST) end + def can_submit_stories? + self.karma >= MIN_KARMA_TO_SUBMIT_STORIES + end + def check_session_token if self.session_token.blank? self.session_token = Utils.random_str(60) @@ -281,10 +292,6 @@ class User < ActiveRecord::Base banned_at? end - def can_invite? - !disabled_invite_at? - end - def is_new? Time.now - self.created_at <= NEW_USER_DAYS.days end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5ba6fda..06d4ebe 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -55,7 +55,7 @@ "/comments" => t('.commentslink') } %> - <% if @user %> + <% if @user && @user.can_submit_stories? %> <% links.merge!({ "/threads" => t('.yourthreadslink'), "/stories/new" => t('.submitstorylink') }) %> <% end %>