Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/assets/images/icons/folder-open.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 1 addition & 23 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class ApplicationController < ActionController::Base

helper_method :current_account

helper_method :is_channel_dashboard?

rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized

require 'httparty'
Expand Down Expand Up @@ -79,26 +77,6 @@ def truthy_param?(key)
end

def current_account
return @current_account if defined?(@current_account)

@current_account = current_user&.account
end

def is_channel_dashboard?
if Rails.env.development?
return true
end

mastodon_url = ENV['MASTODON_INSTANCE_URL']
return false if mastodon_url.nil?

case mastodon_url
when /channel/
true
when /staging\.patchwork\.online/
true
else
false
end
@current_account ||= current_user&.account
end
end
2 changes: 1 addition & 1 deletion app/controllers/concerns/api_response_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def render_success(data = {}, message_key = 'api.messages.success', status = :ok
end

def render_created(data = {}, message_key = 'api.messages.created')
render_success(data, message_key, :created)
render_success(data, message_key, :ok)
end

def render_updated(data = {}, message_key = 'api.messages.updated')
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/server_settings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class ServerSettingsController < ApplicationController
include ApplicationHelper

before_action :authorize_master_admin!
before_action :set_keyword_filter_group, only: [:index]

def index
@server_settings = prepare_server_setting
end
Expand Down
72 changes: 52 additions & 20 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,44 @@ def sidebar_menu_items
newsmast_active = params[:channel_type] == 'newsmast' || @community&.newsmast? ? 'communities' : nil

if master_admin?
[
links = [
{ path: '/homepage', id: 'homepage-link', header: 'Homepage', icon: 'home.svg', text: 'Home', active_if: 'homepage' },
{ path: server_settings_path, id: 'server-settings-link', header: 'Server settings', icon: 'sliders.svg', text: 'Server settings', active_if: ['server_settings', 'keyword_filter_groups', 'keyword_filters'] },
{ path: '/installation', id: 'installation-link', header: 'Installation', icon: 'screwdriver-wrench.svg', text: 'Installation', active_if: 'installation' },
{ path: communities_path(channel_type: 'channel'), id: 'communities-link', header: 'Communities', icon: 'speech.svg', text: 'Communities', active_if: channel_active },
{ path: communities_path(channel_type: 'channel_feed'), id: 'communities-link', header: 'Channels', icon: 'channel-feed.svg', text: 'Channels', active_if: channel_feed_active },
{ path: communities_path(channel_type: 'hub'), id: 'communities-link', header: 'Hubs', icon: 'hub.svg', text: 'Hubs', active_if: hub_active },
{ path: communities_path(channel_type: 'newsmast'), id: 'communities-link', header: 'Newsmast channels', icon: 'newsmast.svg', text: 'Newsmast channels', active_if: newsmast_active },
{ path: collections_path, id: 'collections-link', header: 'Collections', icon: 'collection.svg', text: 'Collections', active_if: 'collections' },
{ path: master_admins_path, id: 'master_admins-link', header: 'Master admin', icon: 'administrator.svg', text: 'Master admins', active_if: 'master_admins' },
{ path: community_filter_keywords_path(community_id: nil), id: 'global_filters-link', header: 'Global filters', icon: 'globe-white.svg', text: 'Global filters', active_if: 'global_filters' },
{ path: '/installation', id: 'installation-link', header: 'Installation', icon: 'screwdriver-wrench.svg', text: 'Installation', active_if: 'installation' }
]

if is_channel_dashboard?
links += [
{ path: communities_path(channel_type: 'channel'), id: 'communities-link', header: 'Communities', icon: 'speech.svg', text: 'Communities', active_if: channel_active },
{ path: communities_path(channel_type: 'channel_feed'), id: 'communities-link', header: 'Channels', icon: 'channel-feed.svg', text: 'Channels', active_if: channel_feed_active },
{ path: communities_path(channel_type: 'hub'), id: 'communities-link', header: 'Hubs', icon: 'hub.svg', text: 'Hubs', active_if: hub_active },
{ path: communities_path(channel_type: 'newsmast'), id: 'communities-link', header: 'Newsmast channels', icon: 'newsmast.svg', text: 'Newsmast channels', active_if: newsmast_active },
{ path: collections_path, id: 'collections-link', header: 'Collections', icon: 'collection.svg', text: 'Collections', active_if: 'collections' }
]
end
links << { path: master_admins_path, id: 'master_admins-link', header: 'Master admin', icon: 'administrator.svg', text: 'Master admins', active_if: 'master_admins' }

if is_channel_dashboard?
links << { path: community_filter_keywords_path(community_id: nil), id: 'global_filters-link', header: 'Global filters', icon: 'globe-white.svg', text: 'Global filters', active_if: 'global_filters' }
end
links += [
# { path: accounts_path, id: 'accounts-link', header: 'Users', icon: 'users.svg', text: 'Users', active_if: 'accounts' },
{ path: resources_path, id: 'resources-link', header: 'Resources', icon: 'folder.svg', text: 'Resources', active_if: 'resources' },
{ path: api_keys_path, id: 'resources-link', header: 'API Key', icon: 'key.svg', text: 'API Key', active_if: 'api_keys' },
{ path: wait_lists_path, id: 'invitation-codes-link', header: 'Invitation codes', icon: 'invitation_code.svg', text: 'Invitation codes', active_if: 'wait_lists' },
{ path: app_versions_path(app_name: AppVersion.app_names['patchwork']), id: 'app-versions-link', header: 'App versions', icon: 'sliders.svg', text: 'App versions', active_if: 'app_versions' },
*(
if ["patchwork.io", "mo-me.social", "newsmast.social"].any? { |domain| ENV['MASTODON_INSTANCE_URL']&.include?(domain) }
[
{ path: "#{ENV['MASTODON_INSTANCE_URL']}/admin/dashboard", id: 'administration-link', header: 'Administration', icon: 'administrator.svg', text: 'Administration', target: '_blank' },
{ path: "#{ENV['MASTODON_INSTANCE_URL']}/admin/reports", id: 'moderation-link', header: 'Moderation', icon: 'users.svg', text: 'Moderation', target: '_blank' },
]
end
),
{ path: api_keys_path, id: 'resources-link', header: 'API Key', icon: 'key.svg', text: 'API Key', active_if: 'api_keys' }
]

if is_channel_dashboard?
links << { path: wait_lists_path, id: 'invitation-codes-link', header: 'Invitation codes', icon: 'invitation_code.svg', text: 'Invitation codes', active_if: 'wait_lists' }
end
links << { path: app_versions_path(app_name: AppVersion.app_names['patchwork']), id: 'app-versions-link', header: 'App versions', icon: 'sliders.svg', text: 'App versions', active_if: 'app_versions' }

unless is_channel_dashboard?
links += [
{ path: "#{ENV['MASTODON_INSTANCE_URL']}/admin/dashboard", id: 'administration-link', header: 'Administration', icon: 'administrator.svg', text: 'Administration', target: '_blank' },
{ path: "#{ENV['MASTODON_INSTANCE_URL']}/admin/reports", id: 'moderation-link', header: 'Moderation', icon: 'users.svg', text: 'Moderation', target: '_blank' }
]
end
links += [
{ path: "/sidekiq", id: 'sidekiq-link', header: 'Sidekiq', icon: 'smile-1.svg', text: 'Sidekiq', target: '_blank' },
{ path: '#', id: 'help-support-link', header: 'Help & Support', icon: 'question.svg', text: 'Help & Support', active_if: 'help_support' }
]
Expand Down Expand Up @@ -113,4 +127,22 @@ def render_custom_emojis(text)
end
end.html_safe
end

def is_channel_dashboard?
if Rails.env.development?
return false
end

mastodon_url = ENV['MASTODON_INSTANCE_URL']
return false if mastodon_url.nil?

case mastodon_url
when /channel/
true
when /staging\.patchwork\.online/
true
else
false
end
end
end
27 changes: 5 additions & 22 deletions app/services/channel_bluesky_bridge_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,7 @@ def process_did_value(community, token, account)
def create_dns_record(did_value, community)
route53 = Aws::Route53::Client.new
hosted_zones = route53.list_hosted_zones

env = ENV.fetch('RAILS_ENV', nil)
channel_zone = case env
when 'staging'
hosted_zones.hosted_zones.find { |zone| zone.name == ENV['LOCAL_DOMAIN'] }
when 'production'
hosted_zones.hosted_zones.find { |zone| zone.name == ENV['LOCAL_DOMAIN'] }
else
hosted_zones.hosted_zones.find { |zone| zone.name == ENV['LOCAL_DOMAIN'] }
end
channel_zone = hosted_zones.hosted_zones.find { |zone| zone.name == "#{ENV['LOCAL_DOMAIN']}." }

if channel_zone
name = if community&.is_custom_domain?
Expand All @@ -113,7 +104,7 @@ def create_dns_record(did_value, community)
end

# Determine the correct domain based on environment and custom domain
domain_name = determine_domain_name(community, env)
domain_name = determine_domain_name(community)
name = "_atproto.#{domain_name}"

route53.change_resource_record_sets({
Expand All @@ -140,8 +131,7 @@ def create_dns_record(did_value, community)
end

def create_direct_message(token, community)
env = ENV.fetch('RAILS_ENV', nil)
domain_name = determine_domain_name(community, env)
domain_name = determine_domain_name(community)

status_params = {
"in_reply_to_id": nil,
Expand All @@ -161,18 +151,11 @@ def handle_relationship(account, target_account_id)
AccountRelationshipsService.new.call(account, target_account_id)
end

def determine_domain_name(community, env)
def determine_domain_name(community)
if community&.is_custom_domain?
community&.slug
else
case env
when 'staging'
"#{community&.slug}.#{ENV['LOCAL_DOMAIN']}"
when 'production'
"#{community&.slug}.#{ENV['LOCAL_DOMAIN']}"
else
"#{community&.slug}.#{ENV['LOCAL_DOMAIN']}"
end
"#{community&.slug}.#{ENV['LOCAL_DOMAIN']}"
end
end
end
10 changes: 1 addition & 9 deletions app/services/non_channel_bluesky_bridge_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,7 @@ def create_dns_record(did_value, account)
route53 = Aws::Route53::Client.new
hosted_zones = route53.list_hosted_zones

env = ENV.fetch('RAILS_ENV', nil)
channel_zone = case env
when 'staging'
hosted_zones.hosted_zones.find { |zone| zone.name == ENV['LOCAL_DOMAIN'] }
when 'production'
hosted_zones.hosted_zones.find { |zone| zone.name == ENV['LOCAL_DOMAIN'] }
else
hosted_zones.hosted_zones.find { |zone| zone.name == ENV['LOCAL_DOMAIN'] }
end
channel_zone = hosted_zones.hosted_zones.find { |zone| zone.name == "#{ENV['LOCAL_DOMAIN']}." }

if channel_zone
name = "_atproto.#{account&.username}.#{ENV['LOCAL_DOMAIN']}"
Expand Down
112 changes: 14 additions & 98 deletions app/views/homepage/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- content_for :title do
= 'Homepage'
- title = application_name(0)

.row
.col-12
Expand All @@ -8,7 +9,7 @@
.row.d-flex.align-items-center
.col-9
%h2
Welcome to the Patchwork dashboard
Welcome to the #{title} dashboard
%p.text-light
Here, you can oversee your server settings enhanced by Patchwork
%br
Expand All @@ -21,124 +22,39 @@
.logo
= image_tag("patchwork-logo.svg", class: "large-logo")

.row.ml-1.d-flex.justify-content-between
.col-4
.row
.card.small-card
.card-header
%div.d-flex.justify-content-between
%div
%h5.card-title Total server users
%div
= image_tag("icons/users-black.svg", class: "mr-2", width: "16", height: "16")
.card-body.mb-1.d-flex.align-items-center.justify-content-between
.col-5.ml-4.d-flex.flex-column.justify-content-center
%h3 18,928
%p Since 23 July, 2024
.col-2.d-flex.justify-content-center.align-items-center
= image_tag("icons/circle-up.svg", class: "mr-2", width: "16", height: "16")
.col-5.d-flex.align-items-center
%h3 31.24%

.row
.card.small-card
.card-header
%div.d-flex.justify-content-between
%div
%h5.card-title Visits
%div
= image_tag("icons/eye.svg", class: "mr-2", width: "16", height: "16")
.card-body.d-flex.align-items-center.justify-content-between
.col-5.ml-4
%h3 201
%p Every 24 hours
.col-2.d-flex.align-items-center.justify-content-center
= image_tag("icons/circle-up.svg", class: "mr-2", width: "16", height: "16")
.col-5
%h3 31.24%

.col-4
.card.small-card
.card-header
%div.d-flex.justify-content-between
%h5.card-title Most popular channels on this server
= image_tag("icons/chart-line-up.svg", class: "mr-2", width: "16", height: "16")
.card-body.mb-3
- channels = [["Local channel 1", "10K"], ["Local channel 2", "1.2K"], ["Local channel 3", "1.3K"], ["Local channel 4", "1.4K"], ["Local channel 5", "1.5K"]]
- channels.each do |community, followers|
.d-flex.align-items-center.mb-1
%img{ alt: "profile picture", src: asset_path('patchwork-logo.svg'), class: "rounded-circle", style: "width: 35px; height: 35px; border: 2px solid white;" }
%div.ml-3
%div= community
%div.text-muted= "#{followers} Followers"
%div.ml-auto
= image_tag("icons/chevron-right.svg", width: "16", height: "16")

.col-4
.card.small-card
.card-header
%div.d-flex.justify-content-between
%div
%h5.card-title Most active contributors
%div
= image_tag("icons/users-black.svg", class: "mr-2", width: "16", height: "16")
.card-body
.row.d-flex.justify-content-between.my-2
.col-6
.d-flex.flex-column.align-items-center
%img{ alt: "profile picture", src: asset_path('patchwork-logo.svg'), class: "rounded-circle", style: "width: 60px; height: 60px; border: 2px solid white;" }
%div Profile Name
%div.text-muted @profilename
.col-6
.d-flex.flex-column.align-items-center
%img{ alt: "profile picture", src: asset_path('patchwork-logo.svg'), class: "rounded-circle", style: "width: 60px; height: 60px; border: 2px solid white;" }
%div Profile Name
%div.text-muted @profilename
.row.d-flex.justify-content-between.my-4
.col-6
.d-flex.flex-column.align-items-center
%img{ alt: "profile picture", src: asset_path('patchwork-logo.svg'), class: "rounded-circle", style: "width: 60px; height: 60px; border: 2px solid white;" }
%div Profile Name
%div.text-muted @profilename
.col-6
.d-flex.flex-column.align-items-center
%img{ alt: "profile picture", src: asset_path('patchwork-logo.svg'), class: "rounded-circle", style: "width: 60px; height: 60px; border: 2px solid white;" }
%div Profile Name
%div.text-muted @profilename

%div.text-center.my-3 Use our quick actions to get started:

%div.d-flex.flex-row.align-items-stretch
.col-4.d-flex.justify-content-between
.card.small-card
.card-body.d-flex{style: 'flex-direction: column;'}
%div.d-flex.justify-content-center.my-2
= image_tag("icons/setting.svg", width: "20", height: "20")
= image_tag("icons/tool.svg", width: "20", height: "20")
%div.d-flex.justify-content-center.my-2
%h5 Server settings
%h5 Installation
%p.text-muted.small.my-2
Update the settings for your server to ensure content is being moderated correctly and spam filters are in place.
Install Patchwork patches to enable new features and controls.
%div.d-grid.gap-2.mt-auto.my-2
%a.btn.btn-danger.btn-block{ href: server_settings_path } View server settings
%a.btn.btn-danger.btn-block{ href: '/installation' } View installation panel
.col-4.d-flex.justify-content-between
.card.small-card
.card-body.d-flex{style: 'flex-direction: column;'}
%div.d-flex.justify-content-center.my-2
= image_tag("icons/chat.svg", width: "20", height: "20")
= image_tag("icons/setting.svg", width: "20", height: "20")
%div.d-flex.justify-content-center.my-2
%h5 Local channels
%h5 Server settings
%p.text-muted.small.my-2
See a list of all your local channels and easily import, manage or create new channels in one place.
Update the settings for your server to ensure content is being moderated correctly and spam filters are in place.
%div.d-grid.gap-2.mt-auto.my-2
%a.btn.btn-danger.btn-block{ href: communities_path } View all local channels
%a.btn.btn-danger.btn-block{ href: server_settings_path } View server settings
.col-4.d-flex.justify-content-between
.card.small-card
.card-body.d-flex{style: 'flex-direction: column;'}
%div.d-flex.justify-content-center.my-2
= image_tag("icons/tool.svg", width: "20", height: "20")
= image_tag("icons/folder-open.svg", width: "20", height: "20")
%div.d-flex.justify-content-center.my-2
%h5 Installation
%h5 Resources
%p.text-muted.small.my-2
Install Patchwork patches to enable new features and controls.
Documentation, specifications and source code for Patchwork.
%div.d-grid.gap-2.mt-auto.my-2
%a.btn.btn-danger.btn-block{ href: '/installation' } View installation panel
%a.btn.btn-danger.btn-block{ href: resources_path } View resources