Skip to content

Commit fedd96c

Browse files
committed
managing email subscriptions for whole org
1 parent 22f7893 commit fedd96c

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

lib/travis/api/v3/queries/email_subscription.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,17 @@ def unsubscribe(user, repository)
77
def resubscribe(user, repository)
88
repository.email_unsubscribes.where(user: user).destroy_all
99
end
10+
11+
def unsubscribe_organization(user, organization)
12+
organization.repositories.each do |repo|
13+
repo.email_unsubscribes.find_or_create_by!(user: user) #if repo.permissions.find_by(user_id: user.id)
14+
end
15+
end
16+
17+
def resubscribe_organization(user, organization)
18+
organization.repositories.each do |repo|
19+
repo.email_unsubscribes.where(user: user).destroy_all
20+
end
21+
end
1022
end
1123
end

lib/travis/api/v3/routes.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ module Routes
113113
get :find_for_organization
114114
patch :update_for_organization
115115
end
116+
117+
resource :email_subscription do
118+
route '/email_subscription'
119+
delete :unsubscribe
120+
post :resubscribe
121+
end
116122
end
117123

118124
resource :organizations do
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
module Travis::API::V3
22
class Services::EmailSubscription::Resubscribe < Service
33
def run!
4+
return run_for_org if params.include?('organization.id')
5+
46
repository = check_login_and_find(:repository)
57
return repo_migrated if migrated?(repository)
68

79
query.resubscribe(access_control.user, repository)
810
no_content
911
end
12+
13+
def run_for_org
14+
organization = check_login_and_find(:organization)
15+
16+
query.resubscribe_organization(access_control.user, organization)
17+
no_content
18+
end
1019
end
1120
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
module Travis::API::V3
22
class Services::EmailSubscription::Unsubscribe < Service
33
def run!
4+
return run_for_org if params.include?('organization.id')
5+
46
repository = check_login_and_find(:repository)
57
return repo_migrated if migrated?(repository)
68

79
query.unsubscribe(access_control.user, repository)
810
no_content
911
end
12+
13+
def run_for_org
14+
organization = check_login_and_find(:organization)
15+
16+
query.unsubscribe_organization(access_control.user, organization)
17+
no_content
18+
end
1019
end
1120
end

0 commit comments

Comments
 (0)