forked from glitch-soc/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
369 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class BubbleDomainsController < BaseController | ||
before_action :set_bubble_domain, except: [:index, :new, :create] | ||
|
||
def index | ||
authorize :bubble_domain, :update? | ||
@bubble_domains = BubbleDomain.all | ||
end | ||
|
||
def new | ||
authorize :bubble_domain, :update? | ||
@bubble_domain = BubbleDomain.new(domain: params[:_domain]) | ||
end | ||
|
||
def create | ||
authorize :bubble_domain, :update? | ||
|
||
domain = TagManager.instance.normalize_domain(resource_params[:domain]) | ||
|
||
@bubble_domain = BubbleDomain.new(domain: domain) | ||
|
||
if @bubble_domain.save! | ||
log_action :create, @bubble_domain | ||
redirect_to admin_bubble_domains_path, notice: I18n.t('admin.bubble_domains.created_msg') | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def destroy | ||
authorize :bubble_domain, :update? | ||
@bubble_domain.destroy | ||
log_action :destroy, @bubble_domain | ||
redirect_to admin_bubble_domains_path | ||
end | ||
|
||
private | ||
|
||
def set_bubble_domain | ||
@bubble_domain = BubbleDomain.find(params[:id]) | ||
end | ||
|
||
def resource_params | ||
params.require(:bubble_domain).permit(:domain) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: bubble_domains | ||
# | ||
# id :bigint(8) not null, primary key | ||
# domain :string default(""), not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
|
||
class BubbleDomain < ApplicationRecord | ||
include Paginable | ||
include DomainNormalizable | ||
include DomainMaterializable | ||
|
||
validates :domain, presence: true, uniqueness: true, domain: true | ||
|
||
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) } | ||
|
||
def to_log_human_identifier | ||
domain | ||
end | ||
|
||
class << self | ||
def in_bubble?(domain) | ||
!rule_for(domain).nil? | ||
end | ||
|
||
def bubble_domains | ||
pluck(:domain) | ||
end | ||
|
||
def rule_for(domain) | ||
return if domain.blank? | ||
|
||
uri = Addressable::URI.new.tap { |u| u.host = domain.delete('/') } | ||
|
||
find_by(domain: uri.normalized_host) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class BubbleDomainPolicy < ApplicationPolicy | ||
def update? | ||
role.can?(:manage_federation) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%tr | ||
%td | ||
%samp= bubble_domain.domain | ||
%td | ||
= table_link_to 'close', t('admin.bubble_domains.delete'), admin_bubble_domain_path(bubble_domain), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } |
Oops, something went wrong.