예제 #1
0
 /**
  * this should not be part of the setUp method because the database connection
  * has NOT been setUp properly at that moment.
  */
 private function initDB()
 {
     Brand::where('id', '!=', 1)->delete();
     $this->brands = factory(Brand::class, 10)->create();
     $this->name1 = $this->brands->first()->name;
     $this->name2 = $this->brands->get(1)->name;
 }
 /**
  * Add the default branding.
  */
 public function addDefaultBrand()
 {
     // Always recreate the default branding for the system
     DB::table('brands')->where('id', '=', '1')->delete();
     $brands = [['id' => 1, 'name' => 'AbuseIO', 'company_name' => 'AbuseIO', 'introduction_text' => 'Open Source abusemanagement', 'creator_id' => 1, 'logo' => file_get_contents(Brand::getDefaultLogo()->getPathname()), 'systembrand' => true, 'created_at' => new DateTime(), 'updated_at' => new DateTime()]];
     DB::table('brands')->insert($brands);
 }
예제 #3
0
 /**
  * Method to add a note to a ticket.
  *
  * @param int    $ticketID
  * @param string $token
  *
  * @return \Illuminate\Http\Response
  */
 public function addNote($ticketID, $token)
 {
     $submittor = false;
     $ticket = Ticket::find($ticketID);
     $AshAuthorisedBy = Request::get('AshAuthorisedBy');
     if ($AshAuthorisedBy == 'TokenIP') {
         $account = Account::find($ticket->ip_contact_account_ip);
         $submittor = trans('ash.basic.ip') . ' ' . trans('ash.communication.contact');
     }
     if ($AshAuthorisedBy == 'TokenDomain') {
         $account = Account::find($ticket->domain_contact_account_id);
         $submittor = trans('ash.basic.domain') . ' ' . trans('ash.communication.contact');
     }
     $brand = empty($account) ? Brand::getSystemBrand() : $account->brand;
     if (empty($brand) || empty($submittor)) {
         abort(500);
     }
     $changeStatus = Input::get('changeStatus');
     if ($changeStatus == 'IGNORED' || $changeStatus == 'RESOLVED') {
         $ticket->contact_status_id = $changeStatus;
         $ticket->save();
     }
     $text = Input::get('text');
     if (empty($text) || strlen($text) < 1) {
         $message = 'noteEmpty';
     } else {
         $message = 'noteAdded';
         $note = new Note();
         $note->ticket_id = $ticket->id;
         $note->submitter = $submittor;
         $note->text = $text;
         $note->save();
     }
     return view('ash')->with('brand', $brand)->with('ticket', $ticket)->with('allowedChanges', $this->allowedStatusChanges($ticket))->with('token', $token)->with('message', $message);
 }
예제 #4
0
 public function testCompanyName()
 {
     $this->assertEquals('AbuseIO', Brand::find(1)->company_name);
     $exitCode = Artisan::call('brand:edit', ['id' => '1', '--company_name' => 'New name 1']);
     $this->assertEquals($exitCode, 0);
     $this->assertContains('The brand has been updated', Artisan::output());
     $brand = Brand::find(1);
     $this->assertEquals('New name 1', $brand->company_name);
     $brand->company_name = 'AbuseIO';
     $brand->save();
 }
예제 #5
0
 /**
  * return the logo as an image
  *
  * @param int $id
  * @return \Illuminate\Http\Response
  */
 public function logo($id)
 {
     $brand = Brand::find($id);
     // if the brand with the specified id doesn't exist return nothing
     if (!$brand) {
         return;
     }
     // get the mime type
     $finfo = new \finfo(FILEINFO_MIME_TYPE);
     $mimetype = $finfo->buffer($brand->logo);
     return response($brand->logo)->header('Content-Type', $mimetype);
 }
예제 #6
0
 /**
  * {@inheritdoc}.
  */
 protected function handleOptions($model)
 {
     $this->updateFieldWithOption($model, 'name');
     if ($this->option('brand_id')) {
         if (null === Brand::find($this->option('brand_id'))) {
             $this->error('Unable to find brand with this criteria');
             return false;
         }
     }
     $this->setSystemAccount($model);
     $this->updateFieldWithOption($model, 'brand_id');
     $this->updateBooleanFieldWithOption($model, 'disabled');
     return true;
 }
예제 #7
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     switch ($this->method) {
         case 'GET':
             break;
         case 'DELETE':
             break;
         case 'POST':
             return Brand::createRules();
         case 'PUT':
             break;
         case 'PATCH':
             return Brand::updateRules($this);
         default:
             break;
     }
     return [];
 }
예제 #8
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param Account $account
  *
  * @return \Illuminate\Http\Response
  */
 public function edit(Account $account)
 {
     // may we edit this brand (is the brand connected to our account)
     if (!$account->mayEdit($this->auth_user)) {
         return Redirect::route('admin.accounts.show', $account->id)->with('message', 'User is not authorized to edit this account.');
     }
     $brands = Brand::lists('name', 'id');
     return view('accounts.edit')->with('account', $account)->with('brand_selection', $brands)->with('disabled_checked', $account->disabled)->with('selected', $account->brand_id)->with('auth_user', $this->auth_user);
 }
예제 #9
0
 protected function getObjectByArguments()
 {
     return Brand::find($this->argument("id"));
 }
예제 #10
0
 /**
  * {@inheritdoc}.
  */
 protected function findAll()
 {
     return Brand::all();
 }
예제 #11
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit(Account $account)
 {
     $brands = Brand::lists('name', 'id');
     return view('accounts.edit')->with('account', $account)->with('brand_selection', $brands)->with('selected', $account->brand_id)->with('user', $this->user);
 }
예제 #12
0
 /**
  * {@inherit docs}.
  */
 protected function getCollectionWithArguments()
 {
     return Brand::where('name', 'like', '%' . $this->argument('brand') . '%')->orWhere('id', $this->argument('brand'))->get($this->getFields());
 }
예제 #13
0
 /**
  * Remove the specified resource from storage.
  *
  * @param Brand $brand
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy(Brand $brand)
 {
     if ($brand->canDelete()) {
         $brand->delete();
     } else {
         return Redirect::back()->with('message', "Can't delete an active and/or system brand.");
     }
     return Redirect::route('admin.brands.index')->with('message', 'Brand has been deleted.');
 }
예제 #14
0
 /**
  * {@inherit docs}
  */
 protected function getCollectionWithArguments()
 {
     return Brand::where("name", "like", "%" . $this->argument("brand") . "%")->orWhere("id", $this->argument("brand"));
 }
예제 #15
0
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(AbuseIO\Models\Account::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'description' => $faker->sentence(rand(6, 10)), 'disabled' => rand(0, 1), 'systemaccount' => 0, 'brand_id' => 1];
});
$factory->define(AbuseIO\Models\Brand::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'company_name' => $faker->company, 'logo' => file_get_contents(\AbuseIO\Models\Brand::getDefaultLogo()->getPathname()), 'introduction_text' => $faker->realText(), 'creator_id' => 1];
});
$factory->define(AbuseIO\Models\Contact::class, function (Faker\Generator $faker) {
    global $contact_reference_counter;
    if (!$contact_reference_counter) {
        $contact_reference_counter = 1;
    } else {
        $contact_reference_counter++;
    }
    return ['reference' => sprintf('reference_%d', $contact_reference_counter), 'name' => $faker->name, 'email' => $faker->email, 'api_host' => 'api_host', 'auto_notify' => $faker->boolean(), 'enabled' => $faker->boolean(), 'account_id' => AbuseIO\Models\Account::all()->first()->id];
});
$factory->define(AbuseIO\Models\Domain::class, function (Faker\Generator $faker) {
    return ['name' => $faker->domainName, 'contact_id' => AbuseIO\Models\Contact::all()->first()->id, 'enabled' => $faker->boolean()];
});
$factory->define(AbuseIO\Models\Event::class, function (Faker\Generator $faker) {
    $evidence = factory(\AbuseIO\Models\Evidence::class)->create();
예제 #16
0
 /**
  * {@inheritdoc}.
  */
 protected function getValidator($model)
 {
     $data = $this->getModelAsArrayForDirtyAttributes($model);
     $updateRules = $this->getUpdateRulesForDirtyAttributes(Brand::updateRules($model));
     return Validator::make($data, $updateRules);
 }
예제 #17
0
 /**
  * {@inheritdoc}.
  */
 protected function getValidator($model)
 {
     return Validator::make($model->toArray(), Brand::createRules());
 }
예제 #18
0
 /**
  * Update the specified resource in storage.
  *
  * @param BrandFormRequest $brandForm
  * @param Brand $brand
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update(BrandFormRequest $brandForm, Brand $brand)
 {
     // may we edit this brand
     if (!$brand->mayEdit($this->auth_user)) {
         return Redirect::route('admin.brands.show', $brand->id)->with('message', 'User is not authorized to edit this brand.');
     }
     $input = $brandForm->all();
     if ($brandForm->hasFile('logo') && $brandForm->file('logo')->isValid()) {
         $errors = [];
         if (!Brand::checkUploadedLogo($brandForm->file('logo'), $errors)) {
             return Redirect::route('admin.brands.edit', $brand->id)->withErrors(['logo' => $errors]);
         }
         // all ok
         $filesystem = new Filesystem();
         $input['logo'] = $filesystem->get($brandForm->file('logo')->getRealPath());
     }
     $brand->update($input);
     return Redirect::route('admin.brands.show', $brand->id)->with('message', 'Brands has been updated.');
 }
예제 #19
0
 public function testModelFactory()
 {
     $account = factory(Brand::class)->create();
     $accountFromDB = Brand::where('name', $account->name)->first();
     $this->assertEquals($account->name, $accountFromDB->name);
 }