From 836d5930332797192094ce4a3c8083e96f7e8c53 Mon Sep 17 00:00:00 2001
From: Robert Speicher <rspeicher@gmail.com>
Date: Sat, 5 Mar 2016 17:17:49 -0500
Subject: [PATCH] Remove `Snippet#expires_at`

This was removed from the interface in
https://github.com/gitlabhq/gitlabhq/pull/6027 but its implementation
lingered around for two years.
---
 app/finders/snippets_finder.rb                         |  6 +++---
 app/helpers/snippets_helper.rb                         | 10 ----------
 app/models/personal_snippet.rb                         |  1 -
 app/models/project_snippet.rb                          |  3 ---
 app/models/snippet.rb                                  |  7 -------
 .../20160305220806_remove_expires_at_from_snippets.rb  |  5 +++++
 db/schema.rb                                           |  4 +---
 doc/api/notes.md                                       |  1 -
 doc/api/project_snippets.md                            |  1 -
 doc/web_hooks/web_hooks.md                             |  1 -
 lib/api/entities.rb                                    |  2 +-
 spec/models/project_snippet_spec.rb                    |  1 -
 spec/models/snippet_spec.rb                            |  1 -
 13 files changed, 10 insertions(+), 33 deletions(-)
 create mode 100644 db/migrate/20160305220806_remove_expires_at_from_snippets.rb

diff --git a/app/finders/snippets_finder.rb b/app/finders/snippets_finder.rb
index 07b5759443b..a41172816b8 100644
--- a/app/finders/snippets_finder.rb
+++ b/app/finders/snippets_finder.rb
@@ -4,7 +4,7 @@ class SnippetsFinder
 
     case filter
     when :all then
-      snippets(current_user).fresh.non_expired
+      snippets(current_user).fresh
     when :by_user then
       by_user(current_user, params[:user], params[:scope])
     when :by_project
@@ -27,7 +27,7 @@ class SnippetsFinder
   end
 
   def by_user(current_user, user, scope)
-    snippets = user.snippets.fresh.non_expired
+    snippets = user.snippets.fresh
 
     return snippets.are_public unless current_user
 
@@ -48,7 +48,7 @@ class SnippetsFinder
   end
 
   def by_project(current_user, project)
-    snippets = project.snippets.fresh.non_expired
+    snippets = project.snippets.fresh
 
     if current_user
       if project.team.member?(current_user.id)
diff --git a/app/helpers/snippets_helper.rb b/app/helpers/snippets_helper.rb
index 41ae4048992..0a5a8eb5aee 100644
--- a/app/helpers/snippets_helper.rb
+++ b/app/helpers/snippets_helper.rb
@@ -1,14 +1,4 @@
 module SnippetsHelper
-  def lifetime_select_options
-    options = [
-        ['forever', nil],
-        ['1 day',   "#{Date.current + 1.day}"],
-        ['1 week',  "#{Date.current + 1.week}"],
-        ['1 month', "#{Date.current + 1.month}"]
-    ]
-    options_for_select(options)
-  end
-
   def reliable_snippet_path(snippet)
     if snippet.project_id?
       namespace_project_snippet_path(snippet.project.namespace,
diff --git a/app/models/personal_snippet.rb b/app/models/personal_snippet.rb
index 9cee3b70cb3..452f3913eef 100644
--- a/app/models/personal_snippet.rb
+++ b/app/models/personal_snippet.rb
@@ -10,7 +10,6 @@
 #  created_at       :datetime
 #  updated_at       :datetime
 #  file_name        :string(255)
-#  expires_at       :datetime
 #  type             :string(255)
 #  visibility_level :integer          default(0), not null
 #
diff --git a/app/models/project_snippet.rb b/app/models/project_snippet.rb
index 9e2c1b0e18e..1f7d85a5f3d 100644
--- a/app/models/project_snippet.rb
+++ b/app/models/project_snippet.rb
@@ -10,7 +10,6 @@
 #  created_at       :datetime
 #  updated_at       :datetime
 #  file_name        :string(255)
-#  expires_at       :datetime
 #  type             :string(255)
 #  visibility_level :integer          default(0), not null
 #
@@ -23,6 +22,4 @@ class ProjectSnippet < Snippet
 
   # Scopes
   scope :fresh, -> { order("created_at DESC") }
-  scope :non_expired, -> { where(["expires_at IS NULL OR expires_at > ?", Time.current]) }
-  scope :expired, -> { where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) }
 end
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index f876be7a4c8..dd3925c7a7d 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -10,7 +10,6 @@
 #  created_at       :datetime
 #  updated_at       :datetime
 #  file_name        :string(255)
-#  expires_at       :datetime
 #  type             :string(255)
 #  visibility_level :integer          default(0), not null
 #
@@ -46,8 +45,6 @@ class Snippet < ActiveRecord::Base
   scope :are_public, -> { where(visibility_level: Snippet::PUBLIC) }
   scope :public_and_internal, -> { where(visibility_level: [Snippet::PUBLIC, Snippet::INTERNAL]) }
   scope :fresh,   -> { order("created_at DESC") }
-  scope :expired, -> { where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) }
-  scope :non_expired, -> { where(["expires_at IS NULL OR expires_at > ?", Time.current]) }
 
   participant :author, :notes
 
@@ -111,10 +108,6 @@ class Snippet < ActiveRecord::Base
     nil
   end
 
-  def expired?
-    expires_at && expires_at < Time.current
-  end
-
   def visibility_level_field
     visibility_level
   end
diff --git a/db/migrate/20160305220806_remove_expires_at_from_snippets.rb b/db/migrate/20160305220806_remove_expires_at_from_snippets.rb
new file mode 100644
index 00000000000..fc12b5b09e6
--- /dev/null
+++ b/db/migrate/20160305220806_remove_expires_at_from_snippets.rb
@@ -0,0 +1,5 @@
+class RemoveExpiresAtFromSnippets < ActiveRecord::Migration
+  def change
+    remove_column :snippets, :expires_at, :datetime
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 71d9257a31e..2d6b9b5a4cc 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: 20160222153918) do
+ActiveRecord::Schema.define(version: 20160305220806) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -777,7 +777,6 @@ ActiveRecord::Schema.define(version: 20160222153918) do
     t.datetime "created_at"
     t.datetime "updated_at"
     t.string   "file_name"
-    t.datetime "expires_at"
     t.string   "type"
     t.integer  "visibility_level", default: 0, null: false
   end
@@ -785,7 +784,6 @@ ActiveRecord::Schema.define(version: 20160222153918) do
   add_index "snippets", ["author_id"], name: "index_snippets_on_author_id", using: :btree
   add_index "snippets", ["created_at", "id"], name: "index_snippets_on_created_at_and_id", using: :btree
   add_index "snippets", ["created_at"], name: "index_snippets_on_created_at", using: :btree
-  add_index "snippets", ["expires_at"], name: "index_snippets_on_expires_at", using: :btree
   add_index "snippets", ["project_id"], name: "index_snippets_on_project_id", using: :btree
   add_index "snippets", ["updated_at"], name: "index_snippets_on_updated_at", using: :btree
   add_index "snippets", ["visibility_level"], name: "index_snippets_on_visibility_level", using: :btree
diff --git a/doc/api/notes.md b/doc/api/notes.md
index d4d63e825ab..85d4f0bafa2 100644
--- a/doc/api/notes.md
+++ b/doc/api/notes.md
@@ -145,7 +145,6 @@ Parameters:
     "state": "active",
     "created_at": "2013-09-30T13:46:01Z"
   },
-  "expires_at": null,
   "updated_at": "2013-10-02T07:34:20Z",
   "created_at": "2013-10-02T07:34:20Z"
 }
diff --git a/doc/api/project_snippets.md b/doc/api/project_snippets.md
index a7acf37b5bc..fb802102e3a 100644
--- a/doc/api/project_snippets.md
+++ b/doc/api/project_snippets.md
@@ -51,7 +51,6 @@ Parameters:
     "state": "active",
     "created_at": "2012-05-23T08:00:58Z"
   },
-  "expires_at": null,
   "updated_at": "2012-06-28T10:52:04Z",
   "created_at": "2012-06-28T10:52:04Z"
 }
diff --git a/doc/web_hooks/web_hooks.md b/doc/web_hooks/web_hooks.md
index b82306bd1da..e2b53c45ab1 100644
--- a/doc/web_hooks/web_hooks.md
+++ b/doc/web_hooks/web_hooks.md
@@ -582,7 +582,6 @@ X-Gitlab-Event: Note Hook
     "created_at": "2015-04-09 02:40:38 UTC",
     "updated_at": "2015-04-09 02:40:38 UTC",
     "file_name": "test.rb",
-    "expires_at": null,
     "type": "ProjectSnippet",
     "visibility_level": 0
   }
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index b021db8fa5b..aa3d8fe8437 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -141,7 +141,7 @@ module API
     class ProjectSnippet < Grape::Entity
       expose :id, :title, :file_name
       expose :author, using: Entities::UserBasic
-      expose :expires_at, :updated_at, :created_at
+      expose :updated_at, :created_at
     end
 
     class ProjectEntity < Grape::Entity
diff --git a/spec/models/project_snippet_spec.rb b/spec/models/project_snippet_spec.rb
index cc92eb0bd9f..e0feb606f78 100644
--- a/spec/models/project_snippet_spec.rb
+++ b/spec/models/project_snippet_spec.rb
@@ -10,7 +10,6 @@
 #  created_at       :datetime
 #  updated_at       :datetime
 #  file_name        :string(255)
-#  expires_at       :datetime
 #  type             :string(255)
 #  visibility_level :integer          default(0), not null
 #
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index eb2dbbdc5a4..7e5b5499aea 100644
--- a/spec/models/snippet_spec.rb
+++ b/spec/models/snippet_spec.rb
@@ -10,7 +10,6 @@
 #  created_at       :datetime
 #  updated_at       :datetime
 #  file_name        :string(255)
-#  expires_at       :datetime
 #  type             :string(255)
 #  visibility_level :integer          default(0), not null
 #
-- 
GitLab