Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-03-22 02:09:20 +0300
committerDouwe Maan <douwe@selenight.nl>2016-03-22 02:09:20 +0300
commit31266c5be4748f57a7d56bbcc6f06d570cbf5356 (patch)
tree1ee744a7303335cf1a270d92ec6b9e955a52cace /db
parentae7b2ef62cdf61c990f914d776a6fdfc2bc49fa2 (diff)
Address feedback
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20160301124843_add_visibility_level_to_groups.rb28
-rw-r--r--db/migrate/20160308212903_add_default_group_visibility_to_application_settings.rb27
-rw-r--r--db/schema.rb1
3 files changed, 51 insertions, 5 deletions
diff --git a/db/migrate/20160301124843_add_visibility_level_to_groups.rb b/db/migrate/20160301124843_add_visibility_level_to_groups.rb
index 89b5ac19983..8121a0c6f90 100644
--- a/db/migrate/20160301124843_add_visibility_level_to_groups.rb
+++ b/db/migrate/20160301124843_add_visibility_level_to_groups.rb
@@ -1,12 +1,30 @@
class AddVisibilityLevelToGroups < ActiveRecord::Migration
- def change
- #All groups public by default
- add_column :namespaces, :visibility_level, :integer, null: false, default: allowed_visibility_level
+ def up
+ add_column :namespaces, :visibility_level, :integer, null: false, default: Gitlab::VisibilityLevel::PUBLIC
+ add_index :namespaces, :visibility_level
+
+ # Unfortunately, this is needed on top of the `default`, since we don't want the configuration specific
+ # `allowed_visibility_level` to end up in schema.rb
+ if allowed_visibility_level < Gitlab::VisibilityLevel::PUBLIC
+ execute("UPDATE namespaces SET visibility_level = #{allowed_visibility_level}")
+ end
+ end
+
+ def down
+ remove_column :namespaces, :visibility_level
end
+ private
+
def allowed_visibility_level
- # TODO: Don't use `current_application_settings`
- allowed_levels = Gitlab::VisibilityLevel.values - current_application_settings.restricted_visibility_levels
+ return 20
+ application_settings = select_one("SELECT restricted_visibility_levels FROM application_settings ORDER BY id DESC LIMIT 1")
+ if application_settings
+ restricted_visibility_levels = YAML.safe_load(application_settings["restricted_visibility_levels"]) rescue nil
+ end
+ restricted_visibility_levels ||= []
+
+ allowed_levels = Gitlab::VisibilityLevel.values - restricted_visibility_levels
allowed_levels.max
end
end
diff --git a/db/migrate/20160308212903_add_default_group_visibility_to_application_settings.rb b/db/migrate/20160308212903_add_default_group_visibility_to_application_settings.rb
new file mode 100644
index 00000000000..37179926d42
--- /dev/null
+++ b/db/migrate/20160308212903_add_default_group_visibility_to_application_settings.rb
@@ -0,0 +1,27 @@
+# Create visibility level field on DB
+# Sets default_visibility_level to value on settings if not restricted
+# If value is restricted takes higher visibility level allowed
+
+class AddDefaultGroupVisibilityToApplicationSettings < ActiveRecord::Migration
+ def up
+ add_column :application_settings, :default_group_visibility, :integer
+ execute("UPDATE application_settings SET default_group_visibility = #{allowed_visibility_level}")
+ end
+
+ def down
+ remove_column :application_settings, :default_group_visibility
+ end
+
+ private
+
+ def allowed_visibility_level
+ application_settings = select_one("SELECT restricted_visibility_levels FROM application_settings ORDER BY id DESC LIMIT 1")
+ if application_settings
+ restricted_visibility_levels = YAML.safe_load(application_settings["restricted_visibility_levels"]) rescue nil
+ end
+ restricted_visibility_levels ||= []
+
+ allowed_levels = Gitlab::VisibilityLevel.values - restricted_visibility_levels
+ allowed_levels.max
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index bb3f0497539..dce2bfe62ca 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -77,6 +77,7 @@ ActiveRecord::Schema.define(version: 20160320204112) do
t.boolean "akismet_enabled", default: false
t.string "akismet_api_key"
t.boolean "email_author_in_body", default: false
+ t.integer "default_group_visibility"
end
create_table "audit_events", force: :cascade do |t|