Added ability to delete campaign from campaign results - needs some cleanup, but it works

pull/24/head
unknown 2015-02-21 01:27:32 -06:00
parent 66dbe2e799
commit be9064f718
4 changed files with 111 additions and 56 deletions

View File

@ -99,7 +99,6 @@ func GetGroupByName(n string, uid int64) (Group, error) {
// PostGroup creates a new group in the database.
func PostGroup(g *Group) error {
Logger.Printf("%v", g.Targets)
if err := g.Validate(); err != nil {
return err
}

View File

@ -5,17 +5,17 @@ import (
"testing"
"github.com/jordan-wright/gophish/config"
"launchpad.net/gocheck"
"gopkg.in/check.v1"
)
// Hook up gocheck into the "go test" runner.
func Test(t *testing.T) { gocheck.TestingT(t) }
func Test(t *testing.T) { check.TestingT(t) }
type ModelsSuite struct{}
var _ = gocheck.Suite(&ModelsSuite{})
var _ = check.Suite(&ModelsSuite{})
func (s *ModelsSuite) SetUpSuite(c *gocheck.C) {
func (s *ModelsSuite) SetUpSuite(c *check.C) {
config.Conf.DBPath = "../gophish_test.db"
err := Setup()
if err != nil {
@ -23,22 +23,48 @@ func (s *ModelsSuite) SetUpSuite(c *gocheck.C) {
}
}
func (s *ModelsSuite) TestGetUser(c *gocheck.C) {
func (s *ModelsSuite) TestGetUser(c *check.C) {
u, err := GetUser(1)
c.Assert(err, gocheck.Equals, nil)
c.Assert(u.Username, gocheck.Equals, "admin")
c.Assert(err, check.Equals, nil)
c.Assert(u.Username, check.Equals, "admin")
}
func (s *ModelsSuite) TestPutUser(c *gocheck.C) {
func (s *ModelsSuite) TestPostGroup(c *check.C) {
g := Group{Name: "Test Group"}
g.Targets = []Target{Target{Email: "test@example.com"}}
g.UserId = 1
err := PostGroup(&g)
c.Assert(err, check.Equals, nil)
c.Assert(g.Name, check.Equals, "Test Group")
c.Assert(g.Targets[0].Email, check.Equals, "test@example.com")
}
func (s *ModelsSuite) TestPostGroupNoName(c *check.C) {
g := Group{Name: ""}
g.Targets = []Target{Target{Email: "test@example.com"}}
g.UserId = 1
err := PostGroup(&g)
c.Assert(err, check.Equals, ErrGroupNameNotSpecified)
}
func (s *ModelsSuite) TestPostGroupNoTargets(c *check.C) {
g := Group{Name: "No Target Group"}
g.Targets = []Target{}
g.UserId = 1
err := PostGroup(&g)
c.Assert(err, check.Equals, ErrNoTargetsSpecified)
}
func (s *ModelsSuite) TestPutUser(c *check.C) {
u, err := GetUser(1)
u.Username = "admin_changed"
err = PutUser(&u)
c.Assert(err, gocheck.Equals, nil)
c.Assert(err, check.Equals, nil)
u, err = GetUser(1)
c.Assert(u.Username, gocheck.Equals, "admin_changed")
c.Assert(u.Username, check.Equals, "admin_changed")
}
func (s *ModelsSuite) TearDownSuite(c *gocheck.C) {
func (s *ModelsSuite) TearDownSuite(c *check.C) {
db.DB().Close()
err := os.Remove(config.Conf.DBPath)
if err != nil {

View File

@ -290,6 +290,22 @@ app.controller('CampaignResultsCtrl', function($scope, $filter, CampaignService,
"icon": "fa-check-circle"
})
}
$scope.delete = function(campaign) {
if (confirm("Delete campaign?")) {
var deleteCampaign = new CampaignService(campaign);
deleteCampaign.$delete({
id: deleteCampaign.id
}, function(response) {
if (response.success) {
$scope.successFlash(response.message)
} else {
$scope.errorFlash(response.message)
}
$scope.mainTableParams.reload();
});
}
}
$scope.mainTableParams = new ngTableParams({
page: 1, // show first page
count: 10, // count per page

View File

@ -21,6 +21,12 @@
</div>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" ng-controller="CampaignResultsCtrl">
<div ng-show="campaign">
<div class="row">
<div class="alert alert-info">
No groups created yet. Let's create one!
</div>
</div>
<div class="row">
<h1 class="page-header">Results for {{campaign.name}}</h1>
</div>
@ -37,7 +43,7 @@
</li>
</ul>
</div>
<button type="button" class="btn btn-danger" tooltip="Delete Campaign" tooltip-placement="right"><i class="fa fa-times fa-lg"></i>
<button type="button" class="btn btn-danger" tooltip="Delete Campaign" tooltip-placement="right" ng-click="delete(campaign)" ng-href="#/dashboard"><i class="fa fa-times fa-lg"></i>
</button>
</div>
<br />
@ -69,4 +75,12 @@
</tbody>
</table>
</div>
</div>
<div ng-show="!campaign">
<div class="row">
<div class="alert alert-danger">
<i class="fa fa-exclamation-circle"></i> Campaign not found!
</div>
</div>
</div>
</div>