From 1c53dc28b505f2853750ed4ea8b954385c5bf598 Mon Sep 17 00:00:00 2001
From: Andrew Tomaka <atomaka@gmail.com>
Date: Wed, 2 Dec 2015 19:02:15 -0500
Subject: [PATCH] Notify user if they cannot create projects

---
 app/assets/javascripts/user.js.coffee                     | 6 ++++++
 app/assets/stylesheets/pages/projects.scss                | 2 +-
 app/controllers/profiles_controller.rb                    | 1 +
 app/views/dashboard/_projects_head.html.haml              | 3 +++
 app/views/shared/_project_limit.html.haml                 | 8 ++++++++
 .../20151203162133_add_hide_project_limit_to_users.rb     | 5 +++++
 db/schema.rb                                              | 3 ++-
 7 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100644 app/views/shared/_project_limit.html.haml
 create mode 100644 db/migrate/20151203162133_add_hide_project_limit_to_users.rb

diff --git a/app/assets/javascripts/user.js.coffee b/app/assets/javascripts/user.js.coffee
index d0d81f96921..ec4271b092c 100644
--- a/app/assets/javascripts/user.js.coffee
+++ b/app/assets/javascripts/user.js.coffee
@@ -2,3 +2,9 @@ class @User
   constructor: ->
     $('.profile-groups-avatars').tooltip("placement": "top")
     new ProjectsList()
+
+    $('.hide-project-limit-message').on 'click', (e) ->
+      path = '/'
+      $.cookie('hide_project_limit_message', 'false', { path: path })
+      $(@).parents('.project-limit-message').remove()
+      e.preventDefault()
diff --git a/app/assets/stylesheets/pages/projects.scss b/app/assets/stylesheets/pages/projects.scss
index 352f0ba2781..2ded32dba12 100644
--- a/app/assets/stylesheets/pages/projects.scss
+++ b/app/assets/stylesheets/pages/projects.scss
@@ -5,7 +5,7 @@
     font-weight: normal;
   }
 }
-.no-ssh-key-message {
+.no-ssh-key-message, .project-limit-message {
   background-color: #f28d35;
   margin-bottom: 16px;
 }
diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb
index 8da7b4d50ea..28803164fcf 100644
--- a/app/controllers/profiles_controller.rb
+++ b/app/controllers/profiles_controller.rb
@@ -70,6 +70,7 @@ class ProfilesController < Profiles::ApplicationController
       :email,
       :hide_no_password,
       :hide_no_ssh_key,
+      :hide_project_limit,
       :linkedin,
       :location,
       :name,
diff --git a/app/views/dashboard/_projects_head.html.haml b/app/views/dashboard/_projects_head.html.haml
index ed480b8caf8..991e67b1cd3 100644
--- a/app/views/dashboard/_projects_head.html.haml
+++ b/app/views/dashboard/_projects_head.html.haml
@@ -1,3 +1,6 @@
+= content_for :flash_message do
+  = render 'shared/project_limit'
+
 %ul.center-top-menu
   = nav_link(path: ['projects#index', 'root#index']) do
     = link_to dashboard_projects_path, title: 'Home', class: 'shortcuts-activity', data: {placement: 'right'} do
diff --git a/app/views/shared/_project_limit.html.haml b/app/views/shared/_project_limit.html.haml
new file mode 100644
index 00000000000..960ff00b49d
--- /dev/null
+++ b/app/views/shared/_project_limit.html.haml
@@ -0,0 +1,8 @@
+- if cookies[:hide_project_limit_message].blank? && !current_user.hide_project_limit && !current_user.can_create_project?
+  .project-limit-message.alert.alert-warning.hidden-xs
+    You won't be able to create new projects because you have reached your project limit.
+
+    .pull-right
+      = link_to "Don't show again", profile_path(user: {hide_project_limit: true}), method: :put, class: 'alert-link'
+      |
+      = link_to 'Remind later', '#', class: 'hide-project-limit-message alert-link'
diff --git a/db/migrate/20151203162133_add_hide_project_limit_to_users.rb b/db/migrate/20151203162133_add_hide_project_limit_to_users.rb
new file mode 100644
index 00000000000..6ffadfa1894
--- /dev/null
+++ b/db/migrate/20151203162133_add_hide_project_limit_to_users.rb
@@ -0,0 +1,5 @@
+class AddHideProjectLimitToUsers < ActiveRecord::Migration
+  def change
+    add_column :users, :hide_project_limit, :boolean, default: false
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index fbcb711e569..fb59e187625 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20151118162244) do
+ActiveRecord::Schema.define(version: 20151203162133) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -814,6 +814,7 @@ ActiveRecord::Schema.define(version: 20151118162244) do
     t.integer  "project_view",               default: 0
     t.integer  "consumed_timestep"
     t.integer  "layout",                     default: 0
+    t.boolean  "hide_project_limit",         default: false
   end
 
   add_index "users", ["admin"], name: "index_users_on_admin", using: :btree
-- 
GitLab