Skip to content

Commit

Permalink
Rely on CAPI org creation endpoint to set user roles
Browse files Browse the repository at this point in the history
[#175042021]

Co-authored-by: Sarah Weinstein <sweinstein@pivotal.io>
Co-authored-by: Teal Stannard <tstannard@pivotal.io>
  • Loading branch information
sweinstein22 and Teal Stannard committed Nov 30, 2020
1 parent 6166079 commit bb6076f
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 53 deletions.
13 changes: 0 additions & 13 deletions command/v7/create_org_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v7

import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/command/flag"
)

Expand Down Expand Up @@ -62,18 +61,6 @@ func (cmd CreateOrgCommand) Execute(args []string) error {
cmd.UI.DisplayOK()
}

cmd.UI.DisplayTextWithFlavor("Assigning role OrgManager to user {{.User}} in org {{.Organization}} as {{.User}}...",
map[string]interface{}{
"User": user.Name,
"Organization": orgName,
})
warnings, err = cmd.Actor.CreateOrgRole(constant.OrgManagerRole, org.GUID, user.Name, user.Origin, user.IsClient)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
cmd.UI.DisplayOK()

cmd.UI.DisplayText(`TIP: Use 'cf target -o "{{.Organization}}"' to target new org`,
map[string]interface{}{
"Organization": orgName,
Expand Down
34 changes: 0 additions & 34 deletions command/v7/create_org_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/command/flag"
"code.cloudfoundry.org/cli/resources"
"code.cloudfoundry.org/cli/util/configv3"
Expand Down Expand Up @@ -147,28 +146,11 @@ var _ = Describe("create-org Command", func() {
})
})

When("assigning the org manager role errors", func() {
BeforeEach(func() {
fakeActor.CreateOrganizationReturns(resources.Organization{Name: orgName, GUID: "some-org-guid"}, v7action.Warnings{"warnings-1", "warnings-2"}, nil)
fakeActor.CreateOrgRoleReturns(
v7action.Warnings{"role-create-warning-1"},
errors.New("err-create-role"))
})

It("returns an error and displays warnings", func() {
Expect(executeErr).To(MatchError("err-create-role"))
Expect(testUI.Err).To(Say("role-create-warning-1"))
})
})

When("creating the org is successful", func() {
var orgGUID = "some-org-guid"
BeforeEach(func() {
fakeActor.CreateOrganizationReturns(resources.Organization{Name: orgName, GUID: orgGUID}, v7action.Warnings{"warnings-1", "warnings-2"}, nil)
fakeActor.ApplyOrganizationQuotaByNameReturns(v7action.Warnings{"quota-warnings-1", "quota-warnings-2"}, nil)
fakeActor.CreateOrgRoleReturns(
v7action.Warnings{"role-create-warning-1"},
nil)
})

It("prints all warnings, text indicating creation completion, ok and then a tip", func() {
Expand All @@ -184,10 +166,6 @@ var _ = Describe("create-org Command", func() {
Expect(testUI.Err).To(Say("quota-warnings-2"))
Expect(testUI.Out).To(Say("OK"))

Expect(testUI.Out).To(Say(`Assigning role OrgManager to user %s in org %s as %s\.\.\.`, currentUsername, orgName, currentUsername))
Expect(testUI.Err).To(Say("role-create-warning-1"))
Expect(testUI.Out).To(Say("OK"))

Expect(testUI.Out).To(Say(`TIP: Use 'cf target -o "%s"' to target new org`, orgName))
})

Expand All @@ -198,21 +176,9 @@ var _ = Describe("create-org Command", func() {
})

It("applies he quota to the org", func() {
Expect(fakeActor.CreateOrgRoleCallCount()).To(Equal(1))
passedQuotaName, passedGuid := fakeActor.ApplyOrganizationQuotaByNameArgsForCall(0)
Expect(passedQuotaName).To(Equal(quotaName))
Expect(passedGuid).To(Equal(orgGUID))
})

It("assigns org manager to the admin", func() {
Expect(testUI.Out).To(Say(`Assigning role OrgManager to user %s in org %s as %s\.\.\.`, currentUsername, orgName, currentUsername))
Expect(fakeActor.CreateOrgRoleCallCount()).To(Equal(1))
givenRoleType, givenOrgGuid, givenUserName, givenOrigin, givenIsClient := fakeActor.CreateOrgRoleArgsForCall(0)
Expect(givenRoleType).To(Equal(constant.OrgManagerRole))
Expect(givenOrgGuid).To(Equal("some-org-guid"))
Expect(givenUserName).To(Equal(currentUsername))
Expect(givenOrigin).To(Equal(""))
Expect(givenIsClient).To(BeFalse())
})
})
})
6 changes: 0 additions & 6 deletions integration/v7/isolated/create_org_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ var _ = Describe("create-org command", func() {
Eventually(session).Should(Say("Creating org %s as %s...", orgNameNew, userName))
Eventually(session).Should(Say("OK"))

Eventually(session).Should(Say("Assigning role OrgManager to user %s in org %s as %s...", userName, orgNameNew, userName))
Eventually(session).Should(Say("OK"))

Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s"' to target new org`, orgNameNew))
Eventually(session).Should(Exit(0))

Expand Down Expand Up @@ -143,9 +140,6 @@ var _ = Describe("create-org command", func() {
Eventually(session).Should(Say("Setting org quota %s to org %s as %s...", quotaName, orgNameNew, userName))
Eventually(session).Should(Say("OK"))

Eventually(session).Should(Say("Assigning role OrgManager to user %s in org %s as %s...", userName, orgNameNew, userName))
Eventually(session).Should(Say("OK"))

Eventually(session).Should(Say(`TIP: Use 'cf target -o "%s"' to target new org`, orgNameNew))
Eventually(session).Should(Exit(0))

Expand Down

0 comments on commit bb6076f

Please sign in to comment.