Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit beta group access to all builds at creation #21478

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions spaceship/lib/spaceship/connect_api/models/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,16 @@ def get_beta_groups(client: nil, filter: {}, includes: nil, limit: nil, sort: ni
return resps.flat_map(&:to_models)
end

def create_beta_group(client: nil, group_name: nil, is_internal_group: false, public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false)
def create_beta_group(client: nil, group_name: nil, is_internal_group: false, public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false, has_access_to_all_builds: nil)
client ||= Spaceship::ConnectAPI
resps = client.create_beta_group(
app_id: id,
group_name: group_name,
is_internal_group: is_internal_group,
public_link_enabled: public_link_enabled,
public_link_limit: public_link_limit,
public_link_limit_enabled: public_link_limit_enabled
public_link_limit_enabled: public_link_limit_enabled,
has_access_to_all_builds: has_access_to_all_builds
).all_pages
return resps.flat_map(&:to_models).first
end
Expand Down
4 changes: 3 additions & 1 deletion spaceship/lib/spaceship/connect_api/models/beta_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BetaGroup
attr_accessor :public_link_limit
attr_accessor :public_link
attr_accessor :beta_testers
attr_accessor :has_access_to_all_builds

attr_mapping({
"name" => "name",
Expand All @@ -23,7 +24,8 @@ class BetaGroup
"publicLinkLimitEnabled" => "public_link_limit_enabled",
"publicLinkLimit" => "public_link_limit",
"publicLink" => "public_link",
"betaTesters" => "beta_testers"
"betaTesters" => "beta_testers",
"hasAccessToAllBuilds" => "has_access_to_all_builds",
})

def self.type
Expand Down
10 changes: 8 additions & 2 deletions spaceship/lib/spaceship/connect_api/testflight/testflight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,19 @@ def delete_beta_groups_from_build(build_id: nil, beta_group_ids: [])
test_flight_request_client.delete("builds/#{build_id}/relationships/betaGroups", nil, body)
end

def create_beta_group(app_id: nil, group_name: nil, is_internal_group: false, public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false)
def create_beta_group(app_id: nil, group_name: nil, is_internal_group: false, public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false, has_access_to_all_builds: nil)
if is_internal_group
has_access_to_all_builds = true if has_access_to_all_builds.nil?
else
# Access to all builds is only for internal groups
has_access_to_all_builds = nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked but creating a few beta groups on App Store Connect, and if isInternalGroup is false, the value of hasAccessToAllBuilds is ignored and in the response hasAccessToAllBuilds is set to nil. Of course I did also check that passing nil was fine on the real server.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a future PR, it might be nice to catch this and print a warning instead of silently ignoring the invalid parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make a new 1-line PR

end
body = {
data: {
attributes: {
name: group_name,
isInternalGroup: is_internal_group,
hasAccessToAllBuilds: is_internal_group ? true : false, # Undocumented of 2021-08-02 in ASC API docs and ASC Open API spec. This is the default behavior on App Store Connect and does work with both Apple ID and API Token
hasAccessToAllBuilds: has_access_to_all_builds, # Undocumented of 2021-08-02 in ASC API docs and ASC Open API spec. This is the default behavior on App Store Connect and does work with both Apple ID and API Token
publicLinkEnabled: public_link_enabled,
publicLinkLimit: public_link_limit,
publicLinkLimitEnabled: public_link_limit_enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"publicLinkId" : "abcd1234",
"publicLinkLimitEnabled" : false,
"publicLinkLimit" : 10000,
"publicLink" : "https://testflight.apple.com/join/abcd1234"
"publicLink" : "https://testflight.apple.com/join/abcd1234",
"hasAccessToAllBuilds" : null
}
}
}
20 changes: 20 additions & 0 deletions spaceship/spec/connect_api/models/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@

model = app.create_beta_group(group_name: "Brand New Group", public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false)
expect(model.id).to eq("123456789")
expect(model.is_internal_group).to eq(false)
expect(model.has_access_to_all_builds).to be_nil

# `has_access_to_all_builds` is ignored for external groups
model = app.create_beta_group(group_name: "Brand New Group", public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false, has_access_to_all_builds: true)
expect(model.id).to eq("123456789")
expect(model.is_internal_group).to eq(false)
expect(model.has_access_to_all_builds).to be_nil

# `has_access_to_all_builds` is set to `true` by default for internal groups
model = app.create_beta_group(group_name: "Brand New Group", is_internal_group: true, public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false)
expect(model.id).to eq("123456789")
expect(model.is_internal_group).to eq(true)
expect(model.has_access_to_all_builds).to eq(true)

# `has_access_to_all_builds` can be set to `false` for internal groups
model = app.create_beta_group(group_name: "Brand New Group", is_internal_group: true, public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false, has_access_to_all_builds: false)
expect(model.id).to eq("123456789")
expect(model.is_internal_group).to eq(true)
expect(model.has_access_to_all_builds).to eq(false)
end

it '#get_review_submissions' do
Expand Down
10 changes: 9 additions & 1 deletion spaceship/spec/connect_api/testflight/testflight_stubbing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,16 @@ def stub_beta_groups
stub_request(:get, "https://appstoreconnect.apple.com/iris/v1/betaGroups").
to_return(status: 200, body: read_fixture_file('beta_groups.json'), headers: { 'Content-Type' => 'application/json' })

created_beta_group = JSON.parse(read_fixture_file('beta_create_group.json'))
stub_request(:post, "https://appstoreconnect.apple.com/iris/v1/betaGroups").
to_return(status: 200, body: read_fixture_file('beta_create_group.json'), headers: { 'Content-Type' => 'application/json' })
to_return { |request|
request_body = JSON.parse(request.body)
response_body = created_beta_group.dup
%w{isInternalGroup hasAccessToAllBuilds}.each do |attribute|
response_body["data"]["attributes"][attribute] = request_body["data"]["attributes"][attribute]
end
{ status: 200, body: JSON.dump(response_body), headers: { 'Content-Type' => 'application/json' } }
}

stub_request(:delete, "https://appstoreconnect.apple.com/iris/v1/betaGroups/123456789").
to_return(status: 200, body: "", headers: {})
Expand Down