chore: 🤖 add status columns to maps and users tables (#1753)

* chore: 🤖 add status columns to maps and users tables

* style: 💄 remove extra indentation
This commit is contained in:
PeculiarE
2022-06-10 09:20:15 +01:00
committed by GitHub
parent e3ed715e6f
commit a817a4d2df
4 changed files with 23 additions and 1 deletions

View File

@@ -66,6 +66,7 @@ class MapsController < ApplicationController
def archive def archive
if logged_in? && current_user.can_delete?(@map) if logged_in? && current_user.can_delete?(@map)
@map.archived = true @map.archived = true
@map.status = 0
if @map.save if @map.save
flash[:notice] = 'Archived map.' flash[:notice] = 'Archived map.'
else else

View File

@@ -0,0 +1,17 @@
class AddStatusToUsersAndMaps < ActiveRecord::Migration[5.2]
class Map < ApplicationRecord
end
def up
add_column :users, :status, :integer, :default => 1
add_column :maps, :status, :integer, :default => 1
Map.reset_column_information
Map.where(archived: true).update(status: 0)
end
def down
remove_column :users, :status
remove_column :maps, :status
end
end

View File

@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_12_19_051509) do ActiveRecord::Schema.define(version: 2022_06_08_115906) do
create_table "annotations", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "annotations", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.integer "map_id" t.integer "map_id"
@@ -77,6 +77,7 @@ ActiveRecord::Schema.define(version: 2019_12_19_051509) do
t.boolean "anon_annotatable", default: false t.boolean "anon_annotatable", default: false
t.string "slug" t.string "slug"
t.boolean "display_welcome", default: true t.boolean "display_welcome", default: true
t.integer "status", default: 1
t.index ["author"], name: "index_maps_on_author" t.index ["author"], name: "index_maps_on_author"
t.index ["slug"], name: "index_maps_on_slug", unique: true t.index ["slug"], name: "index_maps_on_slug", unique: true
t.index ["user_id"], name: "index_maps_on_user_id" t.index ["user_id"], name: "index_maps_on_user_id"
@@ -122,6 +123,7 @@ ActiveRecord::Schema.define(version: 2019_12_19_051509) do
t.datetime "updated_at" t.datetime "updated_at"
t.string "remember_token", limit: 40 t.string "remember_token", limit: 40
t.datetime "remember_token_expires_at" t.datetime "remember_token_expires_at"
t.integer "status", default: 1
t.index ["login"], name: "index_users_on_login", unique: true t.index ["login"], name: "index_users_on_login", unique: true
end end

View File

@@ -191,6 +191,7 @@ class MapsControllerTest < ActionController::TestCase
assert_redirected_to '/' assert_redirected_to '/'
assert @map.archived assert @map.archived
assert_equal 0, @map.status
end end
test 'should not archive map without enough permissions' do test 'should not archive map without enough permissions' do
@@ -200,6 +201,7 @@ class MapsControllerTest < ActionController::TestCase
assert_redirected_to '/' assert_redirected_to '/'
assert_not @map.archived assert_not @map.archived
assert_equal 1, @map.status
end end
test 'should update map' do test 'should update map' do