From 3cd9a975235a410d69b7b8de9c6d54d02fc363c9 Mon Sep 17 00:00:00 2001 From: Risko986 Date: Fri, 22 Nov 2024 18:52:00 +0100 Subject: [PATCH 01/16] Feature flags GUI v 0.1 --- .../feature_flag_component.html.erb | 1 + .../feature_flags/feature_flag_component.rb | 8 ++++++ .../feature_flags_list_component.html.erb | 12 +++++++++ .../feature_flags_list_component.rb | 5 ++++ .../feature_flags_list_row_component.html.erb | 8 ++++++ .../feature_flags_list_row_component.rb | 5 ++++ .../visibility_toggle_component.html.erb | 7 +++++ .../visibility_toggle_component.rb | 6 +++++ app/components/common/icon_component.rb | 3 ++- .../admin/feature_flags_controller.rb | 26 +++++++++++++++++++ app/lib/sidebar_menu.rb | 5 ++-- app/models/tenant.rb | 6 ++++- app/views/admin/feature_flags/index.html.erb | 1 + config/routes.rb | 2 ++ 14 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 app/components/admin/feature_flags/feature_flag_component.html.erb create mode 100644 app/components/admin/feature_flags/feature_flag_component.rb create mode 100644 app/components/admin/feature_flags/feature_flags_list_component.html.erb create mode 100644 app/components/admin/feature_flags/feature_flags_list_component.rb create mode 100644 app/components/admin/feature_flags/feature_flags_list_row_component.html.erb create mode 100644 app/components/admin/feature_flags/feature_flags_list_row_component.rb create mode 100644 app/components/admin/feature_flags/visibility_toggle_component.html.erb create mode 100644 app/components/admin/feature_flags/visibility_toggle_component.rb create mode 100644 app/controllers/admin/feature_flags_controller.rb create mode 100644 app/views/admin/feature_flags/index.html.erb diff --git a/app/components/admin/feature_flags/feature_flag_component.html.erb b/app/components/admin/feature_flags/feature_flag_component.html.erb new file mode 100644 index 000000000..bfc4ee6fd --- /dev/null +++ b/app/components/admin/feature_flags/feature_flag_component.html.erb @@ -0,0 +1 @@ +<%= render Common::BadgeComponent.new( @label, @color, @icon, @classes) %> diff --git a/app/components/admin/feature_flags/feature_flag_component.rb b/app/components/admin/feature_flags/feature_flag_component.rb new file mode 100644 index 000000000..1178ecaa8 --- /dev/null +++ b/app/components/admin/feature_flags/feature_flag_component.rb @@ -0,0 +1,8 @@ +class Admin::FeatureFlags::FeatureFlagComponent < ViewComponent::Base + def initialize(feature_flag, classes: "", color: nil) + @label = feature_flag.to_s + @classes = classes + @color = "gray" + @icon = nil + end +end diff --git a/app/components/admin/feature_flags/feature_flags_list_component.html.erb b/app/components/admin/feature_flags/feature_flags_list_component.html.erb new file mode 100644 index 000000000..128c82822 --- /dev/null +++ b/app/components/admin/feature_flags/feature_flags_list_component.html.erb @@ -0,0 +1,12 @@ +
+
+
+
Feature flags
+
+ <% @feature_flags.each do |flag| %> +
+ <%= render Admin::FeatureFlags::FeatureFlagsListRowComponent.new(flag) %> +
+ <% end %> +
+
diff --git a/app/components/admin/feature_flags/feature_flags_list_component.rb b/app/components/admin/feature_flags/feature_flags_list_component.rb new file mode 100644 index 000000000..7cd4c0d48 --- /dev/null +++ b/app/components/admin/feature_flags/feature_flags_list_component.rb @@ -0,0 +1,5 @@ +class Admin::FeatureFlags::FeatureFlagsListComponent < ViewComponent::Base + def initialize(feature_flags:) + @feature_flags = feature_flags + end +end diff --git a/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb b/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb new file mode 100644 index 000000000..39999c3f3 --- /dev/null +++ b/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb @@ -0,0 +1,8 @@ +
+
+
+ <%= render Admin::FeatureFlags::FeatureFlagComponent.new(@feature_flag) %> +
+
+ <%= render Admin::FeatureFlags::VisibilityToggleComponent.new(@feature_flag) %> +
diff --git a/app/components/admin/feature_flags/feature_flags_list_row_component.rb b/app/components/admin/feature_flags/feature_flags_list_row_component.rb new file mode 100644 index 000000000..26950e49e --- /dev/null +++ b/app/components/admin/feature_flags/feature_flags_list_row_component.rb @@ -0,0 +1,5 @@ +class Admin::FeatureFlags::FeatureFlagsListRowComponent < ViewComponent::Base + def initialize(flag) + @feature_flag = flag + end +end diff --git a/app/components/admin/feature_flags/visibility_toggle_component.html.erb b/app/components/admin/feature_flags/visibility_toggle_component.html.erb new file mode 100644 index 000000000..aadc90ba3 --- /dev/null +++ b/app/components/admin/feature_flags/visibility_toggle_component.html.erb @@ -0,0 +1,7 @@ +<%= form_with model: Current.tenant, url: admin_tenant_feature_flags_path(Current.tenant), title: "Toggle feature state", method: :patch do |form| %> + <%= form.hidden_field :feature_flags, value: @includes ? (Current.tenant.feature_flags - [@feature_flag.to_s]).join(",") : (Current.tenant.feature_flags + [@feature_flag.to_s]).join(",") %> + <%= form.button class: "#{@includes ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @includes.to_s } do %> + Use setting + + <% end %> +<% end %> \ No newline at end of file diff --git a/app/components/admin/feature_flags/visibility_toggle_component.rb b/app/components/admin/feature_flags/visibility_toggle_component.rb new file mode 100644 index 000000000..7eeab989a --- /dev/null +++ b/app/components/admin/feature_flags/visibility_toggle_component.rb @@ -0,0 +1,6 @@ +class Admin::FeatureFlags::VisibilityToggleComponent < ViewComponent::Base + def initialize(feature_flag) + @feature_flag = feature_flag + @includes = Current.tenant.feature_flags.include?(feature_flag.to_s) + end +end diff --git a/app/components/common/icon_component.rb b/app/components/common/icon_component.rb index a4d509ca3..6eeb7a5d2 100644 --- a/app/components/common/icon_component.rb +++ b/app/components/common/icon_component.rb @@ -26,7 +26,8 @@ class IconComponent < ViewComponent::Base "paper-airplane" => "M6 12 3.269 3.125A59.769 59.769 0 0 1 21.485 12 59.768 59.768 0 0 1 3.27 20.875L5.999 12Zm0 0h7.5", "document-arrow-down" => "M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m.75 12 3 3m0 0 3-3m-3 3v-6m-1.5-9H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z", "document-text" => "M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z", - "folder-arrow-down" => "m9 13.5 3 3m0 0 3-3m-3 3v-6m1.06-4.19-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z" + "folder-arrow-down" => "m9 13.5 3 3m0 0 3-3m-3 3v-6m1.06-4.19-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z", + "flag" => "M3 3v1.5M3 21v-6m0 0 2.77-.693a9 9 0 0 1 6.208.682l.108.054a9 9 0 0 0 6.086.71l3.114-.732a48.524 48.524 0 0 1-.005-10.499l-3.11.732a9 9 0 0 1-6.085-.711l-.108-.054a9 9 0 0 0-6.208-.682L3 4.5M3 15V4.5" }.freeze def initialize(icon, classes: "", stroke_width: 1.5) diff --git a/app/controllers/admin/feature_flags_controller.rb b/app/controllers/admin/feature_flags_controller.rb new file mode 100644 index 000000000..15e4cf882 --- /dev/null +++ b/app/controllers/admin/feature_flags_controller.rb @@ -0,0 +1,26 @@ +class Admin::FeatureFlagsController < ApplicationController + before_action :set_tenant, only: %i[update] + + def index + # TODO: make feature flag policy + authorize([:admin, User]) + @feature_flags = Current.tenant.list_features + end + + def update + authorize([:admin, User]) + @tenant.feature_flags = feature_flags_params["feature_flags"].split(",") + @tenant.save! + redirect_to admin_tenant_feature_flags_path + end + + private + + def set_tenant + @tenant = Tenant.find(params[:tenant_id]) + end + + def feature_flags_params + params.require(:tenant).permit(:feature_flags) + end +end diff --git a/app/lib/sidebar_menu.rb b/app/lib/sidebar_menu.rb index 365bf319b..0c5703d90 100644 --- a/app/lib/sidebar_menu.rb +++ b/app/lib/sidebar_menu.rb @@ -11,7 +11,7 @@ def initialize(controller, action, parameters = nil) private def initial_structure(controller, _action) - return admin_menu + site_admin_menu if controller.in? %w[groups users tags tag_groups automation_rules boxes api_connections filters automation_webhooks] + return admin_menu + site_admin_menu if controller.in? %w[groups users tags tag_groups automation_rules boxes api_connections filters automation_webhooks feature_flags] default_main_menu end @@ -40,7 +40,8 @@ def admin_menu TW::SidebarMenuItemComponent.new(name: 'API Prepojenia', url: admin_tenant_api_connections_path(Current.tenant), icon: Icons::RectangleStackComponent.new), TW::SidebarMenuItemComponent.new(name: 'Skupiny', url: admin_tenant_groups_path(Current.tenant), icon: Icons::UserGroupsComponent.new), TW::SidebarMenuItemComponent.new(name: 'Štítky', url: admin_tenant_tags_path(Current.tenant), icon: Icons::TagComponent.new), - TW::SidebarMenuItemComponent.new(name: 'Integrácie', url: admin_tenant_automation_webhooks_path(Current.tenant), icon: Common::IconComponent.new("code-bracket")) + TW::SidebarMenuItemComponent.new(name: 'Integrácie', url: admin_tenant_automation_webhooks_path(Current.tenant), icon: Common::IconComponent.new("code-bracket")), + TW::SidebarMenuItemComponent.new(name: 'Feature flags', url: admin_tenant_feature_flags_path(Current.tenant), icon: Common::IconComponent.new("flag")) ] end diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 1b33c4ddf..622c952aa 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -51,7 +51,7 @@ def draft_tag! end def signed_externally_tag! - signed_externally_tag || raise(ActiveRecord::RecordNotFound, "`SignedExternallyTag` not found in tenant: #{self.id}") + signed_externally_tag || raise(ActiveRecord::RecordNotFound, "`SignedExternallyTag` not found in tenant: #{id}") end def signature_requested_tag! @@ -88,6 +88,10 @@ def disable_feature(feature) save! end + def list_features + AVAILABLE_FEATURE_FLAGS + end + def make_admins_see_everything! everything_tag.groups << admin_group end diff --git a/app/views/admin/feature_flags/index.html.erb b/app/views/admin/feature_flags/index.html.erb new file mode 100644 index 000000000..da664be78 --- /dev/null +++ b/app/views/admin/feature_flags/index.html.erb @@ -0,0 +1 @@ +<%= render Admin::FeatureFlags::FeatureFlagsListComponent.new(feature_flags: @feature_flags)%> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5e230a182..dee302a50 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,6 +37,8 @@ end resources :users + get "/feature_flags/", to: "feature_flags#index" + patch "/feature_flags/", to: "feature_flags#update" resources :boxes, only: :index namespace :boxes do From 1c2ac81871c52c76c4b757004d2243ad8426059e Mon Sep 17 00:00:00 2001 From: Risko986 Date: Sat, 23 Nov 2024 12:41:15 +0100 Subject: [PATCH 02/16] Merge main --- app/components/common/icon_component.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/components/common/icon_component.rb b/app/components/common/icon_component.rb index fbd68b13a..43ffbcc3c 100644 --- a/app/components/common/icon_component.rb +++ b/app/components/common/icon_component.rb @@ -32,7 +32,6 @@ class IconComponent < ViewComponent::Base "funnel-slash" => "M12 3c2.755 0 5.455.232 8.083.678.533.09.917.556.917 1.096v1.044a2.25 2.25 0 0 1-.659 1.591l-5.432 5.432a2.25 2.25 0 0 0-.659 1.591v2.927a2.25 2.25 0 0 1-1.244 2.013L9.75 21v-6.568a2.25 2.25 0 0 0-.659-1.591L3.659 7.409A2.25 2.25 0 0 1 3 5.818V4.774c0-.54.384-1.006.917-1.096A48.32 48.32 0 0 1 12 3ZM2 2l20 20", "tag-slash" => "M9.568 3H5.25A2.25 2.25 0 0 0 3 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 0 0 5.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 0 0 9.568 3Z M6 6h.008v.008H6V6ZM3 21l18-18", "inbox-stack" => "m7.875 14.25 1.214 1.942a2.25 2.25 0 0 0 1.908 1.058h2.006c.776 0 1.497-.4 1.908-1.058l1.214-1.942M2.41 9h4.636a2.25 2.25 0 0 1 1.872 1.002l.164.246a2.25 2.25 0 0 0 1.872 1.002h2.092a2.25 2.25 0 0 0 1.872-1.002l.164-.246A2.25 2.25 0 0 1 16.954 9h4.636M2.41 9a2.25 2.25 0 0 0-.16.832V12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 12V9.832c0-.287-.055-.57-.16-.832M2.41 9a2.25 2.25 0 0 1 .382-.632l3.285-3.832a2.25 2.25 0 0 1 1.708-.786h8.43c.657 0 1.281.287 1.709.786l3.284 3.832c.163.19.291.404.382.632M4.5 20.25h15A2.25 2.25 0 0 0 21.75 18v-2.625c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125V18a2.25 2.25 0 0 0 2.25 2.25Z", - "folder-arrow-down" => "m9 13.5 3 3m0 0 3-3m-3 3v-6m1.06-4.19-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z", "flag" => "M3 3v1.5M3 21v-6m0 0 2.77-.693a9 9 0 0 1 6.208.682l.108.054a9 9 0 0 0 6.086.71l3.114-.732a48.524 48.524 0 0 1-.005-10.499l-3.11.732a9 9 0 0 1-6.085-.711l-.108-.054a9 9 0 0 0-6.208-.682L3 4.5M3 15V4.5" }.freeze From a493cb2385c6fb7c1314514b2c125503bdac523f Mon Sep 17 00:00:00 2001 From: Risko986 Date: Sat, 23 Nov 2024 13:00:22 +0100 Subject: [PATCH 03/16] create feature flag policy --- .../admin/feature_flags_controller.rb | 5 ++-- app/policies/admin/feature_flag_policy.rb | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 app/policies/admin/feature_flag_policy.rb diff --git a/app/controllers/admin/feature_flags_controller.rb b/app/controllers/admin/feature_flags_controller.rb index 15e4cf882..5c252df7d 100644 --- a/app/controllers/admin/feature_flags_controller.rb +++ b/app/controllers/admin/feature_flags_controller.rb @@ -2,13 +2,12 @@ class Admin::FeatureFlagsController < ApplicationController before_action :set_tenant, only: %i[update] def index - # TODO: make feature flag policy - authorize([:admin, User]) + authorize([:admin, :feature_flag]) @feature_flags = Current.tenant.list_features end def update - authorize([:admin, User]) + authorize([:admin, :feature_flag]) @tenant.feature_flags = feature_flags_params["feature_flags"].split(",") @tenant.save! redirect_to admin_tenant_feature_flags_path diff --git a/app/policies/admin/feature_flag_policy.rb b/app/policies/admin/feature_flag_policy.rb new file mode 100644 index 000000000..46c0b47bb --- /dev/null +++ b/app/policies/admin/feature_flag_policy.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class Admin::FeatureFlagPolicy < ApplicationPolicy + attr_reader :user, :tenant + + def initialize(user, tenant) + @user = user + @tenant = tenant + end + + class Scope < Scope + def resolve + scope.where(tenant: @user.tenant) + end + end + + def index? + @user.admin? + end + + def update? + @user.admin? + end +end From 4f7f6200303c189aad8ae3b290ec22fdf193a438 Mon Sep 17 00:00:00 2001 From: Risko986 Date: Sat, 23 Nov 2024 14:49:25 +0100 Subject: [PATCH 04/16] Fixes based on review --- .../admin/feature_flags/feature_flag_component.html.erb | 1 - .../admin/feature_flags/feature_flag_component.rb | 8 -------- .../feature_flags_list_row_component.html.erb | 6 +++++- .../feature_flags/visibility_toggle_component.html.erb | 6 +++--- .../admin/feature_flags/visibility_toggle_component.rb | 1 - app/controllers/admin/feature_flags_controller.rb | 6 +++--- app/models/tenant.rb | 7 ++++++- app/policies/admin/feature_flag_policy.rb | 2 +- app/views/admin/feature_flags/index.html.erb | 2 +- config/routes.rb | 1 + 10 files changed, 20 insertions(+), 20 deletions(-) delete mode 100644 app/components/admin/feature_flags/feature_flag_component.html.erb delete mode 100644 app/components/admin/feature_flags/feature_flag_component.rb diff --git a/app/components/admin/feature_flags/feature_flag_component.html.erb b/app/components/admin/feature_flags/feature_flag_component.html.erb deleted file mode 100644 index bfc4ee6fd..000000000 --- a/app/components/admin/feature_flags/feature_flag_component.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render Common::BadgeComponent.new( @label, @color, @icon, @classes) %> diff --git a/app/components/admin/feature_flags/feature_flag_component.rb b/app/components/admin/feature_flags/feature_flag_component.rb deleted file mode 100644 index 1178ecaa8..000000000 --- a/app/components/admin/feature_flags/feature_flag_component.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Admin::FeatureFlags::FeatureFlagComponent < ViewComponent::Base - def initialize(feature_flag, classes: "", color: nil) - @label = feature_flag.to_s - @classes = classes - @color = "gray" - @icon = nil - end -end diff --git a/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb b/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb index 39999c3f3..c4b39ea2e 100644 --- a/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb +++ b/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb @@ -1,7 +1,11 @@
- <%= render Admin::FeatureFlags::FeatureFlagComponent.new(@feature_flag) %> +
+
+ <%= @feature_flag[:name] %> +
+
<%= render Admin::FeatureFlags::VisibilityToggleComponent.new(@feature_flag) %> diff --git a/app/components/admin/feature_flags/visibility_toggle_component.html.erb b/app/components/admin/feature_flags/visibility_toggle_component.html.erb index aadc90ba3..88a51098f 100644 --- a/app/components/admin/feature_flags/visibility_toggle_component.html.erb +++ b/app/components/admin/feature_flags/visibility_toggle_component.html.erb @@ -1,7 +1,7 @@ <%= form_with model: Current.tenant, url: admin_tenant_feature_flags_path(Current.tenant), title: "Toggle feature state", method: :patch do |form| %> - <%= form.hidden_field :feature_flags, value: @includes ? (Current.tenant.feature_flags - [@feature_flag.to_s]).join(",") : (Current.tenant.feature_flags + [@feature_flag.to_s]).join(",") %> - <%= form.button class: "#{@includes ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @includes.to_s } do %> + <%= form.hidden_field :feature_flags, value: @feature_flag[:enabled] ? @feature_flag[:features_excluding] : @feature_flag[:features_including] %> + <%= form.button class: "#{@feature_flag[:enabled] ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @feature_flag[:enabled] } do %> Use setting - + <% end %> <% end %> \ No newline at end of file diff --git a/app/components/admin/feature_flags/visibility_toggle_component.rb b/app/components/admin/feature_flags/visibility_toggle_component.rb index 7eeab989a..332882c53 100644 --- a/app/components/admin/feature_flags/visibility_toggle_component.rb +++ b/app/components/admin/feature_flags/visibility_toggle_component.rb @@ -1,6 +1,5 @@ class Admin::FeatureFlags::VisibilityToggleComponent < ViewComponent::Base def initialize(feature_flag) @feature_flag = feature_flag - @includes = Current.tenant.feature_flags.include?(feature_flag.to_s) end end diff --git a/app/controllers/admin/feature_flags_controller.rb b/app/controllers/admin/feature_flags_controller.rb index 5c252df7d..ff9c054ad 100644 --- a/app/controllers/admin/feature_flags_controller.rb +++ b/app/controllers/admin/feature_flags_controller.rb @@ -1,9 +1,9 @@ class Admin::FeatureFlagsController < ApplicationController - before_action :set_tenant, only: %i[update] + before_action :set_tenant def index authorize([:admin, :feature_flag]) - @feature_flags = Current.tenant.list_features + @feature_flags = @tenant.list_features end def update @@ -16,7 +16,7 @@ def update private def set_tenant - @tenant = Tenant.find(params[:tenant_id]) + @tenant = policy_scope([:admin, :feature_flag]).find(params[:tenant_id]) end def feature_flags_params diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 6f84e5881..aa4054c6a 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -89,7 +89,12 @@ def disable_feature(feature) end def list_features - AVAILABLE_FEATURE_FLAGS + AVAILABLE_FEATURE_FLAGS.map do |feature| + { name: feature.to_s, + enabled: feature_enabled?(feature), + features_including: (feature_flags + [feature.to_s]).join(","), + features_excluding: (feature_flags - [feature.to_s]).join(",") } + end end def make_admins_see_everything! diff --git a/app/policies/admin/feature_flag_policy.rb b/app/policies/admin/feature_flag_policy.rb index 46c0b47bb..40d493140 100644 --- a/app/policies/admin/feature_flag_policy.rb +++ b/app/policies/admin/feature_flag_policy.rb @@ -10,7 +10,7 @@ def initialize(user, tenant) class Scope < Scope def resolve - scope.where(tenant: @user.tenant) + Tenant.where(id: @user.tenant) end end diff --git a/app/views/admin/feature_flags/index.html.erb b/app/views/admin/feature_flags/index.html.erb index da664be78..18d60e919 100644 --- a/app/views/admin/feature_flags/index.html.erb +++ b/app/views/admin/feature_flags/index.html.erb @@ -1 +1 @@ -<%= render Admin::FeatureFlags::FeatureFlagsListComponent.new(feature_flags: @feature_flags)%> \ No newline at end of file +<%= render Admin::FeatureFlags::FeatureFlagsListComponent.new(feature_flags: @feature_flags) %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index dee302a50..9d8cc224d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,6 +37,7 @@ end resources :users + get "/feature_flags/", to: "feature_flags#index" patch "/feature_flags/", to: "feature_flags#update" From c293f80badc90406abf1a7ed951021c4cbc0d81b Mon Sep 17 00:00:00 2001 From: Risko986 Date: Sat, 23 Nov 2024 19:33:21 +0100 Subject: [PATCH 05/16] Feature flags system test --- ...=> feature_flag_toggle_component.html.erb} | 2 +- .../feature_flag_toggle_component.rb | 5 +++++ .../feature_flags_list_row_component.html.erb | 2 +- .../visibility_toggle_component.rb | 5 ----- .../admin/feature_flags_management_test.rb | 19 +++++++++++++++++++ 5 files changed, 26 insertions(+), 7 deletions(-) rename app/components/admin/feature_flags/{visibility_toggle_component.html.erb => feature_flag_toggle_component.html.erb} (60%) create mode 100644 app/components/admin/feature_flags/feature_flag_toggle_component.rb delete mode 100644 app/components/admin/feature_flags/visibility_toggle_component.rb create mode 100644 test/system/admin/feature_flags_management_test.rb diff --git a/app/components/admin/feature_flags/visibility_toggle_component.html.erb b/app/components/admin/feature_flags/feature_flag_toggle_component.html.erb similarity index 60% rename from app/components/admin/feature_flags/visibility_toggle_component.html.erb rename to app/components/admin/feature_flags/feature_flag_toggle_component.html.erb index 88a51098f..d2955a45d 100644 --- a/app/components/admin/feature_flags/visibility_toggle_component.html.erb +++ b/app/components/admin/feature_flags/feature_flag_toggle_component.html.erb @@ -1,6 +1,6 @@ <%= form_with model: Current.tenant, url: admin_tenant_feature_flags_path(Current.tenant), title: "Toggle feature state", method: :patch do |form| %> <%= form.hidden_field :feature_flags, value: @feature_flag[:enabled] ? @feature_flag[:features_excluding] : @feature_flag[:features_including] %> - <%= form.button class: "#{@feature_flag[:enabled] ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @feature_flag[:enabled] } do %> + <%= form.button name: @feature_flag[:name], class: "#{@feature_flag[:enabled] ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @feature_flag[:enabled] } do %> Use setting <% end %> diff --git a/app/components/admin/feature_flags/feature_flag_toggle_component.rb b/app/components/admin/feature_flags/feature_flag_toggle_component.rb new file mode 100644 index 000000000..4ba404143 --- /dev/null +++ b/app/components/admin/feature_flags/feature_flag_toggle_component.rb @@ -0,0 +1,5 @@ +class Admin::FeatureFlags::FeatureFlagToggleComponent < ViewComponent::Base + def initialize(feature_flag) + @feature_flag = feature_flag + end +end diff --git a/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb b/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb index c4b39ea2e..886678ed8 100644 --- a/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb +++ b/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb @@ -8,5 +8,5 @@
- <%= render Admin::FeatureFlags::VisibilityToggleComponent.new(@feature_flag) %> + <%= render Admin::FeatureFlags::FeatureFlagToggleComponent.new(@feature_flag) %> diff --git a/app/components/admin/feature_flags/visibility_toggle_component.rb b/app/components/admin/feature_flags/visibility_toggle_component.rb deleted file mode 100644 index 332882c53..000000000 --- a/app/components/admin/feature_flags/visibility_toggle_component.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Admin::FeatureFlags::VisibilityToggleComponent < ViewComponent::Base - def initialize(feature_flag) - @feature_flag = feature_flag - end -end diff --git a/test/system/admin/feature_flags_management_test.rb b/test/system/admin/feature_flags_management_test.rb new file mode 100644 index 000000000..67825cea2 --- /dev/null +++ b/test/system/admin/feature_flags_management_test.rb @@ -0,0 +1,19 @@ +require "application_system_test_case" + +class FeatureFlagsManagementTest < ApplicationSystemTestCase + setup do + sign_in_as(:admin) + visit root_path + click_link "Nastavenia" + click_link "Feature flags" + end + + test "admin can enable and disable a feature" do + available_features = users(:admin).tenant.list_features.pluck(:name) + enabled = users(:admin).tenant.feature_enabled?(available_features[0].to_sym) + click_button available_features[0] + assert_button available_features[0] + users(:admin).tenant.reload + assert_not_equal enabled, users(:admin).tenant.feature_enabled?(available_features[0].to_sym) + end +end From f3235b33ce3139141f6abde5b3bc10a106a565e4 Mon Sep 17 00:00:00 2001 From: Risko986 Date: Sat, 23 Nov 2024 19:40:27 +0100 Subject: [PATCH 06/16] .env.test remove unwanted changes --- .env.test | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.test b/.env.test index 9b5f06bf3..9dcc9fb65 100644 --- a/.env.test +++ b/.env.test @@ -11,5 +11,6 @@ ZwIDAQAB ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=1 ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=2 ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=3 + GROVER_NO_SANDBOX=true # must be true for running chromium as root in Docker container -PDF_DISPLAY_URL= +PDF_DISPLAY_URL= \ No newline at end of file From 915f55cd25b8146b2b54030b12fb2637e78ab0a5 Mon Sep 17 00:00:00 2001 From: Risko986 Date: Sat, 23 Nov 2024 19:48:28 +0100 Subject: [PATCH 07/16] .env.test remove unwanted changes --- .env.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.test b/.env.test index 9dcc9fb65..d32d7f7b9 100644 --- a/.env.test +++ b/.env.test @@ -13,4 +13,4 @@ ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=2 ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=3 GROVER_NO_SANDBOX=true # must be true for running chromium as root in Docker container -PDF_DISPLAY_URL= \ No newline at end of file +PDF_DISPLAY_URL= From adb1bf9f1285ca672bb1b54685d52222b548ed55 Mon Sep 17 00:00:00 2001 From: Risko986 Date: Sun, 24 Nov 2024 15:06:17 +0100 Subject: [PATCH 08/16] Fixes --- .../feature_flag_toggle_component.html.erb | 7 ------- .../feature_flag_toggle_component.rb | 5 ----- .../feature_flags_list_component.html.erb | 12 ----------- .../feature_flags_list_component.rb | 5 ----- .../feature_flags_list_row_component.html.erb | 15 ++++++++++--- .../feature_flags_list_row_component.rb | 4 +++- app/components/common/icon_component.rb | 4 +++- .../admin/feature_flags_controller.rb | 1 + app/lib/sidebar_menu.rb | 2 +- app/models/tenant.rb | 7 +------ app/views/admin/feature_flags/index.html.erb | 13 +++++++++++- config/locales/sk.yml | 21 ++++++++++++++++++- .../admin/feature_flags_management_test.rb | 2 +- 13 files changed, 54 insertions(+), 44 deletions(-) delete mode 100644 app/components/admin/feature_flags/feature_flag_toggle_component.html.erb delete mode 100644 app/components/admin/feature_flags/feature_flag_toggle_component.rb delete mode 100644 app/components/admin/feature_flags/feature_flags_list_component.html.erb delete mode 100644 app/components/admin/feature_flags/feature_flags_list_component.rb diff --git a/app/components/admin/feature_flags/feature_flag_toggle_component.html.erb b/app/components/admin/feature_flags/feature_flag_toggle_component.html.erb deleted file mode 100644 index d2955a45d..000000000 --- a/app/components/admin/feature_flags/feature_flag_toggle_component.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -<%= form_with model: Current.tenant, url: admin_tenant_feature_flags_path(Current.tenant), title: "Toggle feature state", method: :patch do |form| %> - <%= form.hidden_field :feature_flags, value: @feature_flag[:enabled] ? @feature_flag[:features_excluding] : @feature_flag[:features_including] %> - <%= form.button name: @feature_flag[:name], class: "#{@feature_flag[:enabled] ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @feature_flag[:enabled] } do %> - Use setting - - <% end %> -<% end %> \ No newline at end of file diff --git a/app/components/admin/feature_flags/feature_flag_toggle_component.rb b/app/components/admin/feature_flags/feature_flag_toggle_component.rb deleted file mode 100644 index 4ba404143..000000000 --- a/app/components/admin/feature_flags/feature_flag_toggle_component.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Admin::FeatureFlags::FeatureFlagToggleComponent < ViewComponent::Base - def initialize(feature_flag) - @feature_flag = feature_flag - end -end diff --git a/app/components/admin/feature_flags/feature_flags_list_component.html.erb b/app/components/admin/feature_flags/feature_flags_list_component.html.erb deleted file mode 100644 index 128c82822..000000000 --- a/app/components/admin/feature_flags/feature_flags_list_component.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -
-
-
-
Feature flags
-
- <% @feature_flags.each do |flag| %> -
- <%= render Admin::FeatureFlags::FeatureFlagsListRowComponent.new(flag) %> -
- <% end %> -
-
diff --git a/app/components/admin/feature_flags/feature_flags_list_component.rb b/app/components/admin/feature_flags/feature_flags_list_component.rb deleted file mode 100644 index 7cd4c0d48..000000000 --- a/app/components/admin/feature_flags/feature_flags_list_component.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Admin::FeatureFlags::FeatureFlagsListComponent < ViewComponent::Base - def initialize(feature_flags:) - @feature_flags = feature_flags - end -end diff --git a/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb b/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb index 886678ed8..f6e4120ef 100644 --- a/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb +++ b/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb @@ -1,12 +1,21 @@ -
+
- <%= @feature_flag[:name] %> + <%= t "feature_flags.#{@feature_flag}.name"%> +
+
+ <%= t "feature_flags.#{@feature_flag}.description"%>
- <%= render Admin::FeatureFlags::FeatureFlagToggleComponent.new(@feature_flag) %> + <%= form_with model: Current.tenant, url: admin_tenant_feature_flags_path(Current.tenant), title: "Toggle feature state", method: :patch do |form| %> + <%= form.hidden_field :feature_flags, value: @features_changed.join(",") %> + <%= form.button name: @feature_flag, class: "#{@enabled ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @enabled } do %> + Use setting + + <% end %> + <% end %>
diff --git a/app/components/admin/feature_flags/feature_flags_list_row_component.rb b/app/components/admin/feature_flags/feature_flags_list_row_component.rb index 26950e49e..87aef4805 100644 --- a/app/components/admin/feature_flags/feature_flags_list_row_component.rb +++ b/app/components/admin/feature_flags/feature_flags_list_row_component.rb @@ -1,5 +1,7 @@ class Admin::FeatureFlags::FeatureFlagsListRowComponent < ViewComponent::Base - def initialize(flag) + def initialize(flag, enabled_features) @feature_flag = flag + @enabled = enabled_features.include?(flag) + @features_changed = enabled_features.include?(flag) ? enabled_features - [flag] : enabled_features + [flag] end end diff --git a/app/components/common/icon_component.rb b/app/components/common/icon_component.rb index 43ffbcc3c..22274b45e 100644 --- a/app/components/common/icon_component.rb +++ b/app/components/common/icon_component.rb @@ -32,7 +32,9 @@ class IconComponent < ViewComponent::Base "funnel-slash" => "M12 3c2.755 0 5.455.232 8.083.678.533.09.917.556.917 1.096v1.044a2.25 2.25 0 0 1-.659 1.591l-5.432 5.432a2.25 2.25 0 0 0-.659 1.591v2.927a2.25 2.25 0 0 1-1.244 2.013L9.75 21v-6.568a2.25 2.25 0 0 0-.659-1.591L3.659 7.409A2.25 2.25 0 0 1 3 5.818V4.774c0-.54.384-1.006.917-1.096A48.32 48.32 0 0 1 12 3ZM2 2l20 20", "tag-slash" => "M9.568 3H5.25A2.25 2.25 0 0 0 3 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 0 0 5.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 0 0 9.568 3Z M6 6h.008v.008H6V6ZM3 21l18-18", "inbox-stack" => "m7.875 14.25 1.214 1.942a2.25 2.25 0 0 0 1.908 1.058h2.006c.776 0 1.497-.4 1.908-1.058l1.214-1.942M2.41 9h4.636a2.25 2.25 0 0 1 1.872 1.002l.164.246a2.25 2.25 0 0 0 1.872 1.002h2.092a2.25 2.25 0 0 0 1.872-1.002l.164-.246A2.25 2.25 0 0 1 16.954 9h4.636M2.41 9a2.25 2.25 0 0 0-.16.832V12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 12V9.832c0-.287-.055-.57-.16-.832M2.41 9a2.25 2.25 0 0 1 .382-.632l3.285-3.832a2.25 2.25 0 0 1 1.708-.786h8.43c.657 0 1.281.287 1.709.786l3.284 3.832c.163.19.291.404.382.632M4.5 20.25h15A2.25 2.25 0 0 0 21.75 18v-2.625c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125V18a2.25 2.25 0 0 0 2.25 2.25Z", - "flag" => "M3 3v1.5M3 21v-6m0 0 2.77-.693a9 9 0 0 1 6.208.682l.108.054a9 9 0 0 0 6.086.71l3.114-.732a48.524 48.524 0 0 1-.005-10.499l-3.11.732a9 9 0 0 1-6.085-.711l-.108-.054a9 9 0 0 0-6.208-.682L3 4.5M3 15V4.5" + "flag" => "M3 3v1.5M3 21v-6m0 0 2.77-.693a9 9 0 0 1 6.208.682l.108.054a9 9 0 0 0 6.086.71l3.114-.732a48.524 48.524 0 0 1-.005-10.499l-3.11.732a9 9 0 0 1-6.085-.711l-.108-.054a9 9 0 0 0-6.208-.682L3 4.5M3 15V4.5", + "puzzle-piece" => "M14.25 6.087c0-.355.186-.676.401-.959.221-.29.349-.634.349-1.003 0-1.036-1.007-1.875-2.25-1.875s-2.25.84-2.25 1.875c0 .369.128.713.349 1.003.215.283.401.604.401.959v0a.64.64 0 0 1-.657.643 48.39 48.39 0 0 1-4.163-.3c.186 1.613.293 3.25.315 4.907a.656.656 0 0 1-.658.663v0c-.355 0-.676-.186-.959-.401a1.647 1.647 0 0 0-1.003-.349c-1.036 0-1.875 1.007-1.875 2.25s.84 2.25 1.875 2.25c.369 0 .713-.128 1.003-.349.283-.215.604-.401.959-.401v0c.31 0 .555.26.532.57a48.039 48.039 0 0 1-.642 5.056c1.518.19 3.058.309 4.616.354a.64.64 0 0 0 .657-.643v0c0-.355-.186-.676-.401-.959a1.647 1.647 0 0 1-.349-1.003c0-1.035 1.008-1.875 2.25-1.875 1.243 0 2.25.84 2.25 1.875 0 .369-.128.713-.349 1.003-.215.283-.4.604-.4.959v0c0 .333.277.599.61.58a48.1 48.1 0 0 0 5.427-.63 48.05 48.05 0 0 0 .582-4.717.532.532 0 0 0-.533-.57v0c-.355 0-.676.186-.959.401-.29.221-.634.349-1.003.349-1.035 0-1.875-1.007-1.875-2.25s.84-2.25 1.875-2.25c.37 0 .713.128 1.003.349.283.215.604.401.96.401v0a.656.656 0 0 0 .658-.663 48.422 48.422 0 0 0-.37-5.36c-1.886.342-3.81.574-5.766.689a.578.578 0 0 1-.61-.58v0Z" + }.freeze def initialize(icon, classes: "", stroke_width: 1.5) diff --git a/app/controllers/admin/feature_flags_controller.rb b/app/controllers/admin/feature_flags_controller.rb index ff9c054ad..70713c7c7 100644 --- a/app/controllers/admin/feature_flags_controller.rb +++ b/app/controllers/admin/feature_flags_controller.rb @@ -4,6 +4,7 @@ class Admin::FeatureFlagsController < ApplicationController def index authorize([:admin, :feature_flag]) @feature_flags = @tenant.list_features + @enabled_features = @tenant.feature_flags end def update diff --git a/app/lib/sidebar_menu.rb b/app/lib/sidebar_menu.rb index 2024308ee..112291a9c 100644 --- a/app/lib/sidebar_menu.rb +++ b/app/lib/sidebar_menu.rb @@ -41,7 +41,7 @@ def admin_menu TW::SidebarMenuItemComponent.new(name: 'Skupiny', url: admin_tenant_groups_path(Current.tenant), icon: Icons::UserGroupsComponent.new), TW::SidebarMenuItemComponent.new(name: 'Štítky', url: admin_tenant_tags_path(Current.tenant), icon: Icons::TagComponent.new), TW::SidebarMenuItemComponent.new(name: 'Integrácie', url: admin_tenant_automation_webhooks_path(Current.tenant), icon: Common::IconComponent.new("code-bracket")), - TW::SidebarMenuItemComponent.new(name: 'Feature flags', url: admin_tenant_feature_flags_path(Current.tenant), icon: Common::IconComponent.new("flag")) + TW::SidebarMenuItemComponent.new(name: 'Aktivácia rozšírení', url: admin_tenant_feature_flags_path(Current.tenant), icon: Common::IconComponent.new("puzzle-piece")) ] end diff --git a/app/models/tenant.rb b/app/models/tenant.rb index aa4054c6a..6f84e5881 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -89,12 +89,7 @@ def disable_feature(feature) end def list_features - AVAILABLE_FEATURE_FLAGS.map do |feature| - { name: feature.to_s, - enabled: feature_enabled?(feature), - features_including: (feature_flags + [feature.to_s]).join(","), - features_excluding: (feature_flags - [feature.to_s]).join(",") } - end + AVAILABLE_FEATURE_FLAGS end def make_admins_see_everything! diff --git a/app/views/admin/feature_flags/index.html.erb b/app/views/admin/feature_flags/index.html.erb index 18d60e919..f89f26bd2 100644 --- a/app/views/admin/feature_flags/index.html.erb +++ b/app/views/admin/feature_flags/index.html.erb @@ -1 +1,12 @@ -<%= render Admin::FeatureFlags::FeatureFlagsListComponent.new(feature_flags: @feature_flags) %> \ No newline at end of file +
+
+
+
Aktivácia rozšírení
+
+ <% @feature_flags.each do |flag| %> +
+ <%= render Admin::FeatureFlags::FeatureFlagsListRowComponent.new(flag.to_s, @enabled_features) %> +
+ <% end %> +
+
diff --git a/config/locales/sk.yml b/config/locales/sk.yml index a4ea6b47c..e7c7dab93 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -337,4 +337,23 @@ sk: description: 'Zatiaľ nie sú vytvorené žiadne schránky.' not_found: header: "Žiadne správy" - description: "Zvolenému vyhľadávaniu nevyhovuje žiadna správa, skúste vybrať iný štítok alebo zmeniť vyhľadávací výraz." \ No newline at end of file + description: "Zvolenému vyhľadávaniu nevyhovuje žiadna správa, skúste vybrať iný štítok alebo zmeniť vyhľadávací výraz." + feature_flags: + api: + name: "API" + description: "Prístup k vybraným funkciám systému a dátam cez API" + archive: + name: "Archive" + description: "Archivácia správ" + audit_log: + name: "Audit log" + description: "Zaznamenávanie a prezeranie auditných záznamov o činnosti používateľov" + fs_api: + name: "API finančnej správy" + description: "Funkčnosť prepojenia s finančnou správou" + fs_sync: + name: "Synchronizácia schránky z finančnej správy" + description: "Synchronizácia schránky z finančnej správy" + message_draft_import: + name: "Import správ" + description: "Funkcionalita pre hromadné zasielanie správ" \ No newline at end of file diff --git a/test/system/admin/feature_flags_management_test.rb b/test/system/admin/feature_flags_management_test.rb index 67825cea2..69ea79f87 100644 --- a/test/system/admin/feature_flags_management_test.rb +++ b/test/system/admin/feature_flags_management_test.rb @@ -5,7 +5,7 @@ class FeatureFlagsManagementTest < ApplicationSystemTestCase sign_in_as(:admin) visit root_path click_link "Nastavenia" - click_link "Feature flags" + click_link "Aktivácia rozšírení" end test "admin can enable and disable a feature" do From d8e99453435935b84ffb1367e236f851ac58ec87 Mon Sep 17 00:00:00 2001 From: Risko986 Date: Sun, 24 Nov 2024 15:26:12 +0100 Subject: [PATCH 09/16] fix test --- test/system/admin/feature_flags_management_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/admin/feature_flags_management_test.rb b/test/system/admin/feature_flags_management_test.rb index 69ea79f87..b9098c506 100644 --- a/test/system/admin/feature_flags_management_test.rb +++ b/test/system/admin/feature_flags_management_test.rb @@ -9,7 +9,7 @@ class FeatureFlagsManagementTest < ApplicationSystemTestCase end test "admin can enable and disable a feature" do - available_features = users(:admin).tenant.list_features.pluck(:name) + available_features = users(:admin).tenant.list_features enabled = users(:admin).tenant.feature_enabled?(available_features[0].to_sym) click_button available_features[0] assert_button available_features[0] From 815bbca8465169d609a83db0a201602d77f92fe6 Mon Sep 17 00:00:00 2001 From: Risko986 Date: Sun, 1 Dec 2024 12:49:28 +0100 Subject: [PATCH 10/16] feature flag routing fix --- .../feature_flags/feature_flags_list_row_component.html.erb | 4 ++-- .../admin/feature_flags/feature_flags_list_row_component.rb | 1 - app/controllers/admin/feature_flags_controller.rb | 4 ++-- config/routes.rb | 4 +--- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb b/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb index f6e4120ef..310de9247 100644 --- a/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb +++ b/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb @@ -11,8 +11,8 @@
- <%= form_with model: Current.tenant, url: admin_tenant_feature_flags_path(Current.tenant), title: "Toggle feature state", method: :patch do |form| %> - <%= form.hidden_field :feature_flags, value: @features_changed.join(",") %> + <%= form_with model: Current.tenant, url: admin_tenant_feature_flag_path(Current.tenant, @feature_flag), title: "Toggle feature state", method: :patch do |form| %> + <%= form.hidden_field :enabled, value: !@enabled %> <%= form.button name: @feature_flag, class: "#{@enabled ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @enabled } do %> Use setting diff --git a/app/components/admin/feature_flags/feature_flags_list_row_component.rb b/app/components/admin/feature_flags/feature_flags_list_row_component.rb index 87aef4805..65e5d154f 100644 --- a/app/components/admin/feature_flags/feature_flags_list_row_component.rb +++ b/app/components/admin/feature_flags/feature_flags_list_row_component.rb @@ -2,6 +2,5 @@ class Admin::FeatureFlags::FeatureFlagsListRowComponent < ViewComponent::Base def initialize(flag, enabled_features) @feature_flag = flag @enabled = enabled_features.include?(flag) - @features_changed = enabled_features.include?(flag) ? enabled_features - [flag] : enabled_features + [flag] end end diff --git a/app/controllers/admin/feature_flags_controller.rb b/app/controllers/admin/feature_flags_controller.rb index 70713c7c7..c52acfaf7 100644 --- a/app/controllers/admin/feature_flags_controller.rb +++ b/app/controllers/admin/feature_flags_controller.rb @@ -9,7 +9,7 @@ def index def update authorize([:admin, :feature_flag]) - @tenant.feature_flags = feature_flags_params["feature_flags"].split(",") + @tenant.feature_flags = feature_flags_params[:enabled] == "true" ? @tenant.feature_flags.union([params[:id]]) : @tenant.feature_flags - [params[:id]] @tenant.save! redirect_to admin_tenant_feature_flags_path end @@ -21,6 +21,6 @@ def set_tenant end def feature_flags_params - params.require(:tenant).permit(:feature_flags) + params.require(:tenant).permit(:enabled) end end diff --git a/config/routes.rb b/config/routes.rb index 9d8cc224d..ead461a48 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,9 +37,7 @@ end resources :users - - get "/feature_flags/", to: "feature_flags#index" - patch "/feature_flags/", to: "feature_flags#update" + resources :feature_flags, only: [:index, :update] resources :boxes, only: :index namespace :boxes do From e4cab6815ac87c11d1dd90a421669ce6626343c3 Mon Sep 17 00:00:00 2001 From: Richard Lences Date: Wed, 4 Dec 2024 21:15:28 +0100 Subject: [PATCH 11/16] show only available features --- app/controllers/admin/feature_flags_controller.rb | 12 ++++++++++-- app/models/tenant.rb | 7 ++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/feature_flags_controller.rb b/app/controllers/admin/feature_flags_controller.rb index c52acfaf7..3e48de7ff 100644 --- a/app/controllers/admin/feature_flags_controller.rb +++ b/app/controllers/admin/feature_flags_controller.rb @@ -3,13 +3,21 @@ class Admin::FeatureFlagsController < ApplicationController def index authorize([:admin, :feature_flag]) - @feature_flags = @tenant.list_features + if params.include?(:labs) + @feature_flags = @tenant.list_all_features + else + @feature_flags = @tenant.list_available_features + end @enabled_features = @tenant.feature_flags end def update authorize([:admin, :feature_flag]) - @tenant.feature_flags = feature_flags_params[:enabled] == "true" ? @tenant.feature_flags.union([params[:id]]) : @tenant.feature_flags - [params[:id]] + if feature_flags_params[:enabled] == "true" + @tenant.feature_flags << params[:id] + else + @tenant.feature_flags.delete(params[:id]) + end @tenant.save! redirect_to admin_tenant_feature_flags_path end diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 6f84e5881..9ef42ec79 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -45,6 +45,7 @@ class Tenant < ApplicationRecord validates_presence_of :name AVAILABLE_FEATURE_FLAGS = [:audit_log, :archive, :api, :message_draft_import, :fs_api, :fs_sync] + ALL_FEATURE_FLAGS = [:audit_log, :archive, :api, :message_draft_import, :fs_api, :fs_sync] def draft_tag! draft_tag || raise(ActiveRecord::RecordNotFound, "`DraftTag` not found in tenant: #{id}") @@ -88,10 +89,14 @@ def disable_feature(feature) save! end - def list_features + def list_available_features AVAILABLE_FEATURE_FLAGS end + def list_all_features + ALL_FEATURE_FLAGS + end + def make_admins_see_everything! everything_tag.groups << admin_group end From eb98bc6e42725b5d54daae449328f0edb53d6755 Mon Sep 17 00:00:00 2001 From: Richard Lences Date: Wed, 4 Dec 2024 21:20:02 +0100 Subject: [PATCH 12/16] test fix --- test/system/admin/feature_flags_management_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/admin/feature_flags_management_test.rb b/test/system/admin/feature_flags_management_test.rb index b9098c506..0c4fb6756 100644 --- a/test/system/admin/feature_flags_management_test.rb +++ b/test/system/admin/feature_flags_management_test.rb @@ -9,7 +9,7 @@ class FeatureFlagsManagementTest < ApplicationSystemTestCase end test "admin can enable and disable a feature" do - available_features = users(:admin).tenant.list_features + available_features = users(:admin).tenant.list_available_features enabled = users(:admin).tenant.feature_enabled?(available_features[0].to_sym) click_button available_features[0] assert_button available_features[0] From 9c129bf2321f59a64d71745c8f7b5578ce03c4c1 Mon Sep 17 00:00:00 2001 From: Richard Lences Date: Thu, 5 Dec 2024 16:01:30 +0100 Subject: [PATCH 13/16] Make only some features visible --- .erblint-rubocop20241205-23566-fnt2fo | 19 +++++++++++++++++++ app/models/tenant.rb | 4 ++-- .../admin/feature_flags_management_test.rb | 4 ++-- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 .erblint-rubocop20241205-23566-fnt2fo diff --git a/.erblint-rubocop20241205-23566-fnt2fo b/.erblint-rubocop20241205-23566-fnt2fo new file mode 100644 index 000000000..a64caf695 --- /dev/null +++ b/.erblint-rubocop20241205-23566-fnt2fo @@ -0,0 +1,19 @@ +--- +inherit_from: +- ".rubocop.yml" +Layout/InitialIndentation: + Enabled: false +Layout/LineLength: + Enabled: false +Layout/TrailingEmptyLines: + Enabled: false +Layout/TrailingWhitespace: + Enabled: false +Naming/FileName: + Enabled: false +Style/FrozenStringLiteralComment: + Enabled: false +Lint/UselessAssignment: + Enabled: false +Rails/OutputSafety: + Enabled: false diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 9ef42ec79..1ba3c7958 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -44,7 +44,7 @@ class Tenant < ApplicationRecord validates_presence_of :name - AVAILABLE_FEATURE_FLAGS = [:audit_log, :archive, :api, :message_draft_import, :fs_api, :fs_sync] + AVAILABLE_FEATURE_FLAGS = [:audit_log, :archive, :api, :fs_sync] ALL_FEATURE_FLAGS = [:audit_log, :archive, :api, :message_draft_import, :fs_api, :fs_sync] def draft_tag! @@ -68,7 +68,7 @@ def user_signature_tags end def feature_enabled?(feature) - raise "Unknown feature #{feature}" unless feature.in? AVAILABLE_FEATURE_FLAGS + raise "Unknown feature #{feature}" unless feature.in? ALL_FEATURE_FLAGS feature.to_s.in? feature_flags end diff --git a/test/system/admin/feature_flags_management_test.rb b/test/system/admin/feature_flags_management_test.rb index 0c4fb6756..307b7e38a 100644 --- a/test/system/admin/feature_flags_management_test.rb +++ b/test/system/admin/feature_flags_management_test.rb @@ -10,10 +10,10 @@ class FeatureFlagsManagementTest < ApplicationSystemTestCase test "admin can enable and disable a feature" do available_features = users(:admin).tenant.list_available_features - enabled = users(:admin).tenant.feature_enabled?(available_features[0].to_sym) + enabled = users(:admin).tenant.feature_enabled?(available_features[0]) click_button available_features[0] assert_button available_features[0] users(:admin).tenant.reload - assert_not_equal enabled, users(:admin).tenant.feature_enabled?(available_features[0].to_sym) + assert_not_equal enabled, users(:admin).tenant.feature_enabled?(available_features[0]) end end From 36f949263796505c0004bddae236231a49edcfa9 Mon Sep 17 00:00:00 2001 From: Richard Lences Date: Thu, 5 Dec 2024 16:20:13 +0100 Subject: [PATCH 14/16] delete unwandet file --- .erblint-rubocop20241205-23566-fnt2fo | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .erblint-rubocop20241205-23566-fnt2fo diff --git a/.erblint-rubocop20241205-23566-fnt2fo b/.erblint-rubocop20241205-23566-fnt2fo deleted file mode 100644 index a64caf695..000000000 --- a/.erblint-rubocop20241205-23566-fnt2fo +++ /dev/null @@ -1,19 +0,0 @@ ---- -inherit_from: -- ".rubocop.yml" -Layout/InitialIndentation: - Enabled: false -Layout/LineLength: - Enabled: false -Layout/TrailingEmptyLines: - Enabled: false -Layout/TrailingWhitespace: - Enabled: false -Naming/FileName: - Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Lint/UselessAssignment: - Enabled: false -Rails/OutputSafety: - Enabled: false From 0820efd0e25c390bac100ceb9bca8952398f2bd8 Mon Sep 17 00:00:00 2001 From: Jano Suchal Date: Thu, 5 Dec 2024 17:50:47 +0100 Subject: [PATCH 15/16] Update test/system/admin/feature_flags_management_test.rb --- test/system/admin/feature_flags_management_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/admin/feature_flags_management_test.rb b/test/system/admin/feature_flags_management_test.rb index 307b7e38a..dbbc5434c 100644 --- a/test/system/admin/feature_flags_management_test.rb +++ b/test/system/admin/feature_flags_management_test.rb @@ -5,7 +5,7 @@ class FeatureFlagsManagementTest < ApplicationSystemTestCase sign_in_as(:admin) visit root_path click_link "Nastavenia" - click_link "Aktivácia rozšírení" + click_link "Funkcie" end test "admin can enable and disable a feature" do From c65435b3ea5f253e8f190c4a358483fee51e155b Mon Sep 17 00:00:00 2001 From: Jano Suchal Date: Thu, 5 Dec 2024 17:50:57 +0100 Subject: [PATCH 16/16] Rename --- app/lib/sidebar_menu.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/sidebar_menu.rb b/app/lib/sidebar_menu.rb index 112291a9c..0dd7dc4e1 100644 --- a/app/lib/sidebar_menu.rb +++ b/app/lib/sidebar_menu.rb @@ -41,7 +41,7 @@ def admin_menu TW::SidebarMenuItemComponent.new(name: 'Skupiny', url: admin_tenant_groups_path(Current.tenant), icon: Icons::UserGroupsComponent.new), TW::SidebarMenuItemComponent.new(name: 'Štítky', url: admin_tenant_tags_path(Current.tenant), icon: Icons::TagComponent.new), TW::SidebarMenuItemComponent.new(name: 'Integrácie', url: admin_tenant_automation_webhooks_path(Current.tenant), icon: Common::IconComponent.new("code-bracket")), - TW::SidebarMenuItemComponent.new(name: 'Aktivácia rozšírení', url: admin_tenant_feature_flags_path(Current.tenant), icon: Common::IconComponent.new("puzzle-piece")) + TW::SidebarMenuItemComponent.new(name: 'Funkcie', url: admin_tenant_feature_flags_path(Current.tenant), icon: Common::IconComponent.new("puzzle-piece")) ] end