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

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorBenjamin Neff <benjamin@coding4coffee.ch>2022-11-01 23:16:12 +0300
committerBenjamin Neff <benjamin@coding4coffee.ch>2022-11-01 23:17:17 +0300
commit80c088817620b50a59eb9581e6bfd8da04da4e5a (patch)
tree6ad9d04674f94356c3e93b016a235a0d7dd9553a /app
parentacc76a383fb9a7f87e62ba0ad43c6a98247bbca5 (diff)
parent800f3948702be34a56ee5395b0ad1fa003e99372 (diff)
Merge pull request #8403 from SuperTux88/cleanup-duplicate-pods-for-real-this-time
Cleanup duplicate pods
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/app/views/pod_entry_view.js3
-rw-r--r--app/assets/templates/pod_table_entry_tpl.jst.hbs2
-rw-r--r--app/models/pod.rb28
3 files changed, 24 insertions, 9 deletions
diff --git a/app/assets/javascripts/app/views/pod_entry_view.js b/app/assets/javascripts/app/views/pod_entry_view.js
index 112b6708f..3d3d098ab 100644
--- a/app/assets/javascripts/app/views/pod_entry_view.js
+++ b/app/assets/javascripts/app/views/pod_entry_view.js
@@ -27,12 +27,13 @@ app.views.PodEntry = app.views.Base.extend({
presenter: function() {
return _.extend({}, this.defaultPresenter(), {
/* jshint camelcase: false */
+ hasPort: (this.model.get("port") >= 0),
is_unchecked: (this.model.get("status")==="unchecked"),
has_no_errors: (this.model.get("status")==="no_errors"),
has_errors: (this.model.get("status")!=="no_errors"),
status_text: Diaspora.I18n.t("admin.pods.states."+this.model.get("status")),
pod_url: (this.model.get("ssl") ? "https" : "http") + "://" + this.model.get("host") +
- (this.model.get("port") ? ":" + this.model.get("port") : ""),
+ (this.model.get("port") >= 0 ? ":" + this.model.get("port") : ""),
response_time_fmt: this._fmtResponseTime()
/* jshint camelcase: true */
});
diff --git a/app/assets/templates/pod_table_entry_tpl.jst.hbs b/app/assets/templates/pod_table_entry_tpl.jst.hbs
index 3c2bb0605..76940a4a5 100644
--- a/app/assets/templates/pod_table_entry_tpl.jst.hbs
+++ b/app/assets/templates/pod_table_entry_tpl.jst.hbs
@@ -7,7 +7,7 @@
{{/if}}
</i>
</td>
-<td class="pod-title" title="{{host}}">{{host}}</td>
+<td class="pod-title" title="{{host}}">{{host}}{{#if hasPort}}:{{port}}{{/if}}</td>
<td class="added">
<small><time datetime="{{created_at}}" title="{{localTime created_at}}"></time></small>
</td>
diff --git a/app/models/pod.rb b/app/models/pod.rb
index 1edc4e899..0f3177c2b 100644
--- a/app/models/pod.rb
+++ b/app/models/pod.rb
@@ -22,7 +22,7 @@ class Pod < ApplicationRecord
ConnectionTester::SSLFailure => :ssl_failed,
ConnectionTester::HTTPFailure => :http_failed,
ConnectionTester::NodeInfoFailure => :version_failed
- }
+ }.freeze
# this are only the most common errors, the rest will be +unknown_error+
CURL_ERROR_MAP = {
@@ -34,7 +34,13 @@ class Pod < ApplicationRecord
redirected_to_other_hostname: :http_failed
}.freeze
- DEFAULT_PORTS = [URI::HTTP::DEFAULT_PORT, URI::HTTPS::DEFAULT_PORT]
+ # use -1 as port for default ports
+ # we can't use the real default port (80/443) because we need to handle them
+ # like both are the same and not both can exist at the same time.
+ # we also can't use nil, because databases don't handle NULL in unique indexes
+ # (except postgres >= 15 with "NULLS NOT DISTINCT").
+ DEFAULT_PORT = -1
+ DEFAULT_PORTS = [URI::HTTP::DEFAULT_PORT, URI::HTTPS::DEFAULT_PORT].freeze
has_many :people
@@ -51,8 +57,8 @@ class Pod < ApplicationRecord
class << self
def find_or_create_by(opts) # Rename this method to not override an AR method
uri = URI.parse(opts.fetch(:url))
- port = DEFAULT_PORTS.include?(uri.port) ? nil : uri.port
- find_or_initialize_by(host: uri.host, port: port).tap do |pod|
+ port = DEFAULT_PORTS.include?(uri.port) ? DEFAULT_PORT : uri.port
+ find_or_initialize_by(host: uri.host.downcase, port: port).tap do |pod|
pod.ssl ||= (uri.scheme == "https")
pod.save
end
@@ -147,13 +153,21 @@ class Pod < ApplicationRecord
# @return [URI]
def uri
- @uri ||= (ssl ? URI::HTTPS : URI::HTTP).build(host: host, port: port)
+ @uri ||= (ssl ? URI::HTTPS : URI::HTTP).build(host: host, port: real_port)
@uri.dup
end
+ def real_port
+ if port == DEFAULT_PORT
+ ssl ? URI::HTTPS::DEFAULT_PORT : URI::HTTP::DEFAULT_PORT
+ else
+ port
+ end
+ end
+
def not_own_pod
pod_uri = AppConfig.pod_uri
- pod_port = DEFAULT_PORTS.include?(pod_uri.port) ? nil : pod_uri.port
- errors.add(:base, "own pod not allowed") if pod_uri.host == host && pod_port == port
+ pod_port = DEFAULT_PORTS.include?(pod_uri.port) ? DEFAULT_PORT : pod_uri.port
+ errors.add(:base, "own pod not allowed") if pod_uri.host.downcase == host && pod_port == port
end
end