Skip to content

Commit

Permalink
Merge pull request #2507 from manyfold3d/remove-flipper
Browse files Browse the repository at this point in the history
Remove Flipper for feature switching
  • Loading branch information
Floppy authored Aug 9, 2024
2 parents 722efb2 + 10d6494 commit cec24ea
Show file tree
Hide file tree
Showing 39 changed files with 77 additions and 115 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ docker-compose.yml
# ignore asdf config files
/.tool-versions
dump.rdb

# IDE workspace files
*.code-workspace
5 changes: 1 addition & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gem "redis", "~> 5.2"
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

gem "dotenv-rails", "~> 3.1"
gem "dotenv-rails", "~> 3.1", group: :development
gem "acts-as-taggable-on", "~> 10.0"

gem "ffi-libarchive", "~> 1.1"
Expand Down Expand Up @@ -115,9 +115,6 @@ gem "translation", "~> 1.41", group: :development

gem "string-similarity", "~> 2.1"

gem "flipper", "~> 1.3"
gem "flipper-active_record", "~> 1.3"

gem "rolify", "~> 6.0"

gem "letter_opener", "~> 1.10", group: :development
Expand Down
7 changes: 0 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,6 @@ GEM
ffi (1.17.0-x86_64-linux-gnu)
ffi-libarchive (1.1.14)
ffi (~> 1.0)
flipper (1.3.0)
concurrent-ruby (< 2)
flipper-active_record (1.3.0)
activerecord (>= 4.2, < 8)
flipper (~> 1.3.0)
formatador (1.1.0)
formtastic (5.0.0)
actionpack (>= 6.0.0)
Expand Down Expand Up @@ -713,8 +708,6 @@ DEPENDENCIES
faker (~> 3.4)
federails!
ffi-libarchive (~> 1.1)
flipper (~> 1.3)
flipper-active_record (~> 1.3)
guard (~> 2.18)
guard-rspec (~> 4.7)
i18n-js (~> 4.2)
Expand Down
2 changes: 1 addition & 1 deletion app/components/follow_button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def before_render
end

def render?
Flipper.enabled? :multiuser
SiteSettings.multiuser_enabled?
end

erb_template <<-ERB
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def auto_login_single_user
create_admin_user if User.with_role(:administrator).empty?
# If in single user mode, or on first run,
# automatically log in with an admin account
if !Flipper.enabled?(:multiuser) || User.with_role(:administrator).first.reset_password_token == "first_use"
if !SiteSettings.multiuser_enabled? || User.with_role(:administrator).first.reset_password_token == "first_use"
sign_in(:user, User.with_role(:administrator).first)
flash.discard
redirect_back_or_to root_path, alert: nil
Expand Down
16 changes: 14 additions & 2 deletions app/models/site_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class SiteSettings < RailsSettings::Base
field :analyse_manifold, type: :boolean, default: false
field :anonymous_usage_id, type: :string, default: nil

def self.registration_enabled
def self.registration_enabled?
ENV.fetch("REGISTRATION", false) == "enabled"
end

def self.email_configured
def self.email_configured?
!Rails.env.production? || ENV.fetch("SMTP_SERVER", false)
end

Expand All @@ -29,6 +29,18 @@ def self.max_file_extract_size
ENV.fetch("MAX_FILE_EXTRACT_SIZE", 1_073_741_824).to_i
end

def self.demo_mode_enabled?
Rails.application.config.manyfold_features[:demo_mode]
end

def self.multiuser_enabled?
Rails.application.config.manyfold_features[:multiuser]
end

def self.federation_enabled?
Rails.application.config.manyfold_features[:federation]
end

module UserDefaults
RENDERER = {
grid_width: 200,
Expand Down
2 changes: 1 addition & 1 deletion app/policies/application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def destroy?
all_of(
user&.is_editor?,
none_of(
Flipper.enabled?(:demo_mode)
SiteSettings.demo_mode_enabled?
)
)
end
Expand Down
4 changes: 2 additions & 2 deletions app/policies/federails/following_policy.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class Federails::FollowingPolicy < ApplicationPolicy
def create?
all_of(
Flipper.enabled?(:multiuser)
SiteSettings.multiuser_enabled?
)
end

def destroy?
all_of(
Flipper.enabled?(:multiuser)
SiteSettings.multiuser_enabled?
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/policies/library_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def create?
all_of(
user&.is_administrator?,
none_of(
Flipper.enabled?(:demo_mode)
SiteSettings.demo_mode_enabled?
)
)
end
Expand Down
2 changes: 1 addition & 1 deletion app/policies/model_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def merge?
all_of(
user&.is_editor?,
none_of(
Flipper.enabled?(:demo_mode)
SiteSettings.demo_mode_enabled?
)
)
end
Expand Down
2 changes: 1 addition & 1 deletion app/policies/upload_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def create?
all_of(
user&.is_contributor?,
none_of(
Flipper.enabled?(:demo_mode)
SiteSettings.demo_mode_enabled?
)
)
end
Expand Down
12 changes: 6 additions & 6 deletions app/policies/user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def index?
all_of(
user&.is_administrator?,
none_of(
Flipper.enabled?(:demo_mode)
SiteSettings.demo_mode_enabled?
)
)
end
Expand All @@ -19,13 +19,13 @@ def show?

def create?
all_of(
Flipper.enabled?(:multiuser),
SiteSettings.multiuser_enabled?,
one_of(
SiteSettings.registration_enabled,
SiteSettings.registration_enabled?,
user&.is_administrator?
),
none_of(
Flipper.enabled?(:demo_mode)
SiteSettings.demo_mode_enabled?
)
)
end
Expand All @@ -43,9 +43,9 @@ def destroy?
user == record,
user&.is_administrator?
),
Flipper.enabled?(:multiuser),
SiteSettings.multiuser_enabled?,
none_of(
Flipper.enabled?(:demo_mode)
SiteSettings.demo_mode_enabled?
)
)
end
Expand Down
4 changes: 2 additions & 2 deletions app/policies/users/passwords_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

class Users::PasswordsPolicy < ApplicationPolicy
def create?
Flipper.enabled?(:multiuser) && SiteSettings.email_configured
SiteSettings.multiuser_enabled? && SiteSettings.email_configured?
end

def update?
Flipper.enabled?(:multiuser) && SiteSettings.email_configured
SiteSettings.multiuser_enabled? && SiteSettings.email_configured?
end
end
2 changes: 1 addition & 1 deletion app/policies/users/registrations_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class Users::RegistrationsPolicy < ApplicationPolicy
def cancel?
Flipper.enabled?(:multiuser)
SiteSettings.multiuser_enabled?
end
end
4 changes: 2 additions & 2 deletions app/policies/users/sessions_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ def new?
end

def create?
Flipper.enabled?(:multiuser)
SiteSettings.multiuser_enabled?
end

def destroy?
Flipper.enabled?(:multiuser)
SiteSettings.multiuser_enabled?
end
end
2 changes: 1 addition & 1 deletion app/views/activity/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class='col col-auto'>
<%= t ".description", retention_period: distance_of_time_in_words(ActiveJob::Status.options[:expires_in]) %>
</div>
<% if !Flipper.enabled?(:demo_mode) %>
<% if !SiteSettings.demo_mode_enabled? %>
<div class='col text-end'>
<%= link_to safe_join([icon("activity", t(".sidekiq")), t(".sidekiq")], " "),
"/sidekiq",
Expand Down
2 changes: 1 addition & 1 deletion app/views/application/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<%= f.search_field :q, class: "form-control ms-1 me-3", placeholder: translate(".search"), aria_label: translate(".search"), aria_describedby: "button-search", value: params[:q] %>
<% end %>
</li>
<%- if Flipper.enabled? :multiuser %>
<%- if SiteSettings.multiuser_enabled? %>
<%- if current_user %>
<li class="nav-item">
<%= nav_link "person", t(".account"), edit_user_registration_path, text_style: "d-lg-none" %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
nil %>
</div>
</div>
<%- if Flipper.enabled? :multiuser %>
<%- if SiteSettings.multiuser_enabled? %>
<div class="card border-danger mt-3">
<h4 class="card-header text-bg-danger"><%= t ".danger_zone" %></h4>
<div class="card-body">
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%= render "application/content_header" %>
<h1 class="d-none d-lg-block"><%= t "application.title" %></h1>
<p class='lead'><%= t "application.tagline" %></p>
<% if Flipper.enabled? :demo_mode %>
<% if SiteSettings.demo_mode_enabled? %>
<div class="alert alert-info">
<%= t "application.demo_mode" %>
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/views/settings/_multiuser_settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<h3 class="card-header"><%= t(".heading") %></h3>
<div class="card-body">
<p class='lead'>
<%= Flipper.enabled?(:multiuser) ? t(".multiuser_mode") : t(".single_user_mode") %>
<%= SiteSettings.multiuser_enabled? ? t(".multiuser_mode") : t(".single_user_mode") %>
</p>
<% if Flipper.enabled?(:multiuser) %>
<% if SiteSettings.multiuser_enabled? %>
<p>
<%= SiteSettings.registration_enabled ? t(".registrations_open") : t(".registrations_closed") %>
<%= SiteSettings.registration_enabled? ? t(".registrations_open") : t(".registrations_closed") %>
</p>
<% end %>
<p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/settings/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<div class='col'>
<button type="submit" class="btn btn-primary"><%= icon("save", t(".submit")) %> <%= t(".submit") %></button>
</div>
<% if current_user.is_administrator? && !Flipper.enabled?(:demo_mode) %>
<% if current_user.is_administrator? && !SiteSettings.demo_mode_enabled? %>
<div class='col text-end'>
<%= link_to safe_join([icon("tools", t(".advanced_admin")), t(".advanced_admin")], " "),
"/admin",
Expand Down
7 changes: 7 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ class Application < Rails::Application
user_name: ENV.fetch("SMTP_USERNAME", nil),
password: ENV.fetch("SMTP_PASSWORD", nil)
}.compact

# Load some feature settings from ENV
config.manyfold_features = {
multiuser: (ENV.fetch("MULTIUSER", nil) == "enabled"),
federation: (ENV.fetch("FEDERATION", nil) == "enabled"),
demo_mode: (ENV.fetch("DEMO_MODE", nil) == "enabled")
}
end
end

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/active_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
# Active Admin resources and pages from here.
#
config.before_action do
raise Pundit::NotAuthorizedError, I18n.t("active_admin.demo_mode") if Flipper.enabled? :demo_mode
raise Pundit::NotAuthorizedError, I18n.t("active_admin.demo_mode") if SiteSettings.demo_mode_enabled?
end

# == Attribute Filters
Expand Down
8 changes: 1 addition & 7 deletions config/initializers/federails.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# frozen_string_literal: true

federation_enabled = begin
Flipper.enabled?(:federation)
rescue ActiveRecord::StatementInvalid
false
end

Federails.configure do |conf|
conf.app_name = "Manyfold"
conf.app_version = Rails.application.config.app_version
Expand All @@ -14,7 +8,7 @@
conf.site_port = Rails.application.default_url_options[:port]
conf.force_ssl = Rails.application.config.force_ssl

conf.enable_discovery = federation_enabled
conf.enable_discovery = Rails.application.config.manyfold_features[:federation]
conf.server_routes_path = "federation"
conf.client_routes_path = "client"

Expand Down
32 changes: 0 additions & 32 deletions config/initializers/flipper.rb

This file was deleted.

10 changes: 2 additions & 8 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
resources :activity
end

begin
mount Federails::Engine => "/" if Flipper.enabled?(:multiuser)
rescue ActiveRecord::StatementInvalid
nil
end
mount Federails::Engine => "/" if Rails.application.config.manyfold_features[:multiuser]

resources :users, only: [] do
resource :settings, only: [:show, :update]
Expand All @@ -40,15 +36,13 @@
end

concern :followable do |options|
if Flipper.enabled?(:multiuser)
if Rails.application.config.manyfold_features[:multiuser]
resources :follows, {only: [:create]}.merge(options) do
collection do
delete "/", action: "destroy"
end
end
end
rescue ActiveRecord::StatementInvalid
nil
end

resources :models do
Expand Down
2 changes: 1 addition & 1 deletion spec/components/follow_button_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe FollowButtonComponent, type: :component do
before do
allow(Flipper).to receive(:enabled?).with(:multiuser).and_return true
allow(SiteSettings).to receive(:multiuser_enabled?).and_return(true)
end

let(:follower) { create(:user) }
Expand Down
Loading

0 comments on commit cec24ea

Please sign in to comment.