Skip to content

Commit 9aa9541

Browse files
committed
Add support for account and trends data sharing.
1 parent 53fbb8f commit 9aa9541

29 files changed

+322
-28
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
11
class AccountsController < ApplicationController
2+
before_action :load_account, only: [ :show, :destroy ]
3+
4+
def index
5+
@accounts = Account.all
6+
end
7+
8+
def show
9+
end
10+
11+
def destroy
12+
@account.destroy
13+
14+
redirect_to accounts_path, notice: t(".success")
15+
end
16+
17+
private
18+
19+
def load_account
20+
@account = Account.find(params[:id])
21+
end
222
end

debug_fasp/app/controllers/subscriptions_controller.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
class SubscriptionsController < ApplicationController
2+
helper_method :current_server
3+
24
def index
3-
@subscriptions = FaspDataSharing::Subscription.all
5+
@subscriptions = FaspDataSharing::Subscription
6+
.where(fasp_base_server: current_server).all
47
end
58

69
def create
7-
FaspDataSharing::Subscription.subscribe_to_content(current_user.servers.first)
10+
create_subscription
811

912
redirect_to subscriptions_path, notice: t(".success")
1013
end
@@ -15,4 +18,21 @@ def destroy
1518

1619
redirect_to subscriptions_path, notice: t(".success")
1720
end
21+
22+
private
23+
24+
def current_server
25+
@current_server ||= current_user.servers.first
26+
end
27+
28+
def create_subscription
29+
case params[:type]
30+
when "content"
31+
FaspDataSharing::Subscription.subscribe_to_content(current_server)
32+
when "account"
33+
FaspDataSharing::Subscription.subscribe_to_accounts(current_server)
34+
when "trends"
35+
FaspDataSharing::Subscription.subscribe_to_trends(current_server)
36+
end
37+
end
1838
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class TrendSignalsController < ApplicationController
2+
def index
3+
@trend_signals = TrendSignal
4+
.includes(:content)
5+
.order(created_at: :desc)
6+
end
7+
8+
def destroy
9+
trend_signal = TrendSignal.find(params[:id])
10+
trend_signal.destroy
11+
12+
redirect_to trend_signals_path, notice: t(".success")
13+
end
14+
end

debug_fasp/app/helpers/accounts_helper.rb

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
11
module ApplicationHelper
2+
DATA_SHARING_TABS = {
3+
subscriptions: :subscriptions_path,
4+
contents: :contents_path,
5+
accounts: :accounts_path,
6+
trend_signals: :trend_signals_path
7+
}.freeze
8+
9+
def content_subscription_absent?
10+
FaspDataSharing::Subscription
11+
.where(fasp_base_server: current_server)
12+
.content
13+
.lifecycle
14+
.none?
15+
end
16+
17+
def account_subscription_absent?
18+
FaspDataSharing::Subscription
19+
.where(fasp_base_server: current_server)
20+
.account
21+
.lifecycle
22+
.none?
23+
end
24+
25+
def trends_subscription_absent?
26+
FaspDataSharing::Subscription
27+
.where(fasp_base_server: current_server)
28+
.content
29+
.trends
30+
.none?
31+
end
232
end

debug_fasp/app/helpers/contents_helper.rb

Lines changed: 0 additions & 2 deletions
This file was deleted.

debug_fasp/app/helpers/subscriptions_helper.rb

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class FaspDataSharing::ProcessAccountDeletionJob < ApplicationJob
2+
queue_as :default
3+
4+
def perform(uri)
5+
Account.where(uri:).destroy_all
6+
end
7+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class FaspDataSharing::ProcessAccountUpdateJob < ApplicationJob
2+
queue_as :default
3+
4+
def perform(uri)
5+
object = fetch_object(uri)
6+
account = Account.find_or_initialize_by(uri:, object_type: object["type"])
7+
account.update(full_object: object)
8+
end
9+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class FaspDataSharing::ProcessNewAccountJob < ApplicationJob
2+
queue_as :default
3+
4+
def perform(uri)
5+
unless Account.where(uri:).exists?
6+
object = fetch_object(uri)
7+
Account.create!(
8+
uri: object["id"],
9+
object_type: object["type"],
10+
full_object: object
11+
)
12+
end
13+
end
14+
end

0 commit comments

Comments
 (0)