Beispiel #1
0
func (cmd *UnsetOrgRole) Execute(c flags.FlagContext) error {
	user := cmd.userReq.GetUser()
	org := cmd.orgReq.GetOrganization()
	roleStr := c.Args()[2]
	role, err := models.RoleFromString(roleStr)
	if err != nil {
		return err
	}

	cmd.ui.Say(T("Removing role {{.Role}} from user {{.TargetUser}} in org {{.TargetOrg}} as {{.CurrentUser}}...",
		map[string]interface{}{
			"Role":        terminal.EntityNameColor(roleStr),
			"TargetUser":  terminal.EntityNameColor(c.Args()[0]),
			"TargetOrg":   terminal.EntityNameColor(c.Args()[1]),
			"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
		}))

	if len(user.GUID) > 0 {
		err = cmd.userRepo.UnsetOrgRoleByGUID(user.GUID, org.GUID, role)
	} else {
		err = cmd.userRepo.UnsetOrgRoleByUsername(user.Username, org.GUID, role)
	}

	if err != nil {
		return err
	}

	cmd.ui.Ok()
	return nil
}
Beispiel #2
0
func (cmd *SetOrgRole) Execute(c flags.FlagContext) error {
	user := cmd.userReq.GetUser()
	org := cmd.orgReq.GetOrganization()
	roleStr := c.Args()[2]
	role, err := models.RoleFromString(roleStr)
	if err != nil {
		return err
	}

	cmd.ui.Say(T("Assigning role {{.Role}} to user {{.TargetUser}} in org {{.TargetOrg}} as {{.CurrentUser}}...",
		map[string]interface{}{
			"Role":        terminal.EntityNameColor(roleStr),
			"TargetUser":  terminal.EntityNameColor(user.Username),
			"TargetOrg":   terminal.EntityNameColor(org.Name),
			"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
		}))

	err = cmd.SetOrgRole(org.GUID, role, user.GUID, user.Username)
	if err != nil {
		return err
	}

	cmd.ui.Ok()
	return nil
}
Beispiel #3
0
func (cmd *SetSpaceRole) Execute(c flags.FlagContext) error {
	spaceName := c.Args()[2]
	roleStr := c.Args()[3]
	role, err := models.RoleFromString(roleStr)
	if err != nil {
		return err
	}

	userFields := cmd.userReq.GetUser()
	org := cmd.orgReq.GetOrganization()

	space, err := cmd.spaceRepo.FindByNameInOrg(spaceName, org.GUID)
	if err != nil {
		return err
	}

	err = cmd.SetSpaceRole(space, org.GUID, org.Name, role, userFields.GUID, userFields.Username)
	if err != nil {
		return err
	}
	return nil
}