Skip to content

Commit

Permalink
Merge branch 'pull-request/20'
Browse files Browse the repository at this point in the history
Closes #20
  • Loading branch information
cwarden committed Jan 15, 2021
2 parents c10e862 + ef83b26 commit 73dc15b
Show file tree
Hide file tree
Showing 10 changed files with 321 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ unchanged.
force-md profile object-permissions -o Account -e -D src/profiles/*
```

### Delete Visibility/Access Permissions

```
force profile flow delete -f MyFlow src/profiles/*
force profile apex delete -c MyClass src/profiles/*
force profile application delete -a MyApplication src/profiles/*
force profile visualforce delete -p MyPage src/profiles/*
```

## Developing

To add support for a new metadata type, [zek](https://github.com/miku/zek) can
Expand Down
4 changes: 4 additions & 0 deletions cmd/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ func init() {
profileCmd.AddCommand(profile.ObjectPermissionsCmd)
profileCmd.AddCommand(profile.TabCmd)
profileCmd.AddCommand(profile.UserPermissionsCmd)
profileCmd.AddCommand(profile.ApplicationCmd)
profileCmd.AddCommand(profile.FlowCmd)
profileCmd.AddCommand(profile.ApexCmd)
profileCmd.AddCommand(profile.VisualforceCmd)
rootCmd.AddCommand(profileCmd)
}

Expand Down
55 changes: 55 additions & 0 deletions cmd/profile/apex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package profile

import (
"fmt"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/octoberswimmer/force-md/internal"
"github.com/octoberswimmer/force-md/profile"
)

var apexClassName string

func init() {
deleteApexClassCmd.Flags().StringVarP(&apexClassName, "class", "c", "", "apex classname")
deleteApexClassCmd.MarkFlagRequired("class")

ApexCmd.AddCommand(deleteApexClassCmd)
}

var ApexCmd = &cobra.Command{
Use: "apex",
Short: "Manage apex class visibility",
}

var deleteApexClassCmd = &cobra.Command{
Use: "delete",
Short: "Delete apex class visibility",
Long: "Delete apex class visibility in profiles",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
for _, file := range args {
deleteApexClassVisibility(file, apexClassName)
}
},
}

func deleteApexClassVisibility(file string, apexClassName string) {
p, err := profile.Open(file)
if err != nil {
log.Warn("parsing profile failed: " + err.Error())
return
}
err = p.DeleteApexClassAccess(apexClassName)
if err != nil {
log.Warn(fmt.Sprintf("update failed for %s: %s", file, err.Error()))
return
}
err = internal.WriteToFile(p, file)
if err != nil {
log.Warn("update failed: " + err.Error())
return
}
}
55 changes: 55 additions & 0 deletions cmd/profile/applications.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package profile

import (
"fmt"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/octoberswimmer/force-md/internal"
"github.com/octoberswimmer/force-md/profile"
)

var applicationName string

func init() {
deleteApplicationCmd.Flags().StringVarP(&applicationName, "application", "a", "", "application name")
deleteApplicationCmd.MarkFlagRequired("application")

ApplicationCmd.AddCommand(deleteApplicationCmd)
}

var ApplicationCmd = &cobra.Command{
Use: "application",
Short: "Manage application visibility",
}

var deleteApplicationCmd = &cobra.Command{
Use: "delete",
Short: "Delete application visibility",
Long: "Delete application visibility in profiles",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
for _, file := range args {
deleteApplicationVisibility(file, applicationName)
}
},
}

func deleteApplicationVisibility(file string, applicationName string) {
p, err := profile.Open(file)
if err != nil {
log.Warn("parsing profile failed: " + err.Error())
return
}
err = p.DeleteApplicationVisibility(applicationName)
if err != nil {
log.Warn(fmt.Sprintf("update failed for %s: %s", file, err.Error()))
return
}
err = internal.WriteToFile(p, file)
if err != nil {
log.Warn("update failed: " + err.Error())
return
}
}
55 changes: 55 additions & 0 deletions cmd/profile/flows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package profile

import (
"fmt"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/octoberswimmer/force-md/internal"
"github.com/octoberswimmer/force-md/profile"
)

var flowName string

func init() {
deleteFlowCmd.Flags().StringVarP(&flowName, "flow", "f", "", "flow name")
deleteFlowCmd.MarkFlagRequired("flow")

FlowCmd.AddCommand(deleteFlowCmd)
}

var FlowCmd = &cobra.Command{
Use: "flow",
Short: "Manage flow visibility",
}

var deleteFlowCmd = &cobra.Command{
Use: "delete",
Short: "Delete flow access",
Long: "Delete flow access in profiles",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
for _, file := range args {
deleteFlowVisibility(file, flowName)
}
},
}

func deleteFlowVisibility(file string, flowName string) {
p, err := profile.Open(file)
if err != nil {
log.Warn("parsing profile failed: " + err.Error())
return
}
err = p.DeleteFlowAccess(flowName)
if err != nil {
log.Warn(fmt.Sprintf("update failed for %s: %s", file, err.Error()))
return
}
err = internal.WriteToFile(p, file)
if err != nil {
log.Warn("update failed: " + err.Error())
return
}
}
55 changes: 55 additions & 0 deletions cmd/profile/visualforce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package profile

import (
"fmt"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/octoberswimmer/force-md/internal"
"github.com/octoberswimmer/force-md/profile"
)

var pageName string

func init() {
deleteVisualforcePageCmd.Flags().StringVarP(&pageName, "page", "p", "", "visualforce page name")
deleteVisualforcePageCmd.MarkFlagRequired("page")

VisualforceCmd.AddCommand(deleteVisualforcePageCmd)
}

var VisualforceCmd = &cobra.Command{
Use: "visualforce",
Short: "Manage visualforce page visibility",
}

var deleteVisualforcePageCmd = &cobra.Command{
Use: "delete",
Short: "Delete visualforce page access",
Long: "Delete visualforce page access in profiles",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
for _, file := range args {
deleteVisualforceAccess(file, pageName)
}
},
}

func deleteVisualforceAccess(file string, pageName string) {
p, err := profile.Open(file)
if err != nil {
log.Warn("parsing profile failed: " + err.Error())
return
}
err = p.DeleteVisualforcePageAccess(pageName)
if err != nil {
log.Warn(fmt.Sprintf("update failed for %s: %s", file, err.Error()))
return
}
err = internal.WriteToFile(p, file)
if err != nil {
log.Warn("update failed: " + err.Error())
return
}
}
22 changes: 22 additions & 0 deletions profile/apex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package profile

import (
"github.com/pkg/errors"
)

func (p *Profile) DeleteApexClassAccess(apexClassName string) error {
found := false
newClasses := p.ClassAccesses[:0]
for _, f := range p.ClassAccesses {
if f.ApexClass.Text == apexClassName {
found = true
} else {
newClasses = append(newClasses, f)
}
}
if !found {
return errors.New("class not found")
}
p.ClassAccesses = newClasses
return nil
}
22 changes: 22 additions & 0 deletions profile/applications.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package profile

import (
"github.com/pkg/errors"
)

func (p *Profile) DeleteApplicationVisibility(applicationName string) error {
found := false
newApps := p.ApplicationVisibilities[:0]
for _, f := range p.ApplicationVisibilities {
if f.Application.Text == applicationName {
found = true
} else {
newApps = append(newApps, f)
}
}
if !found {
return errors.New("application not found")
}
p.ApplicationVisibilities = newApps
return nil
}
22 changes: 22 additions & 0 deletions profile/flows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package profile

import (
"github.com/pkg/errors"
)

func (p *Profile) DeleteFlowAccess(flowName string) error {
found := false
newFlows := p.FlowAccesses[:0]
for _, f := range p.FlowAccesses {
if f.Flow.Text == flowName {
found = true
} else {
newFlows = append(newFlows, f)
}
}
if !found {
return errors.New("flow not found")
}
p.FlowAccesses = newFlows
return nil
}
22 changes: 22 additions & 0 deletions profile/visualforce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package profile

import (
"github.com/pkg/errors"
)

func (p *Profile) DeleteVisualforcePageAccess(pageName string) error {
found := false
newPages := p.PageAccesses[:0]
for _, f := range p.PageAccesses {
if f.ApexPage.Text == pageName {
found = true
} else {
newPages = append(newPages, f)
}
}
if !found {
return errors.New("page not found")
}
p.PageAccesses = newPages
return nil
}

0 comments on commit 73dc15b

Please sign in to comment.