Skip to content

Commit

Permalink
Fixes #163 - accept acceptance + eula
Browse files Browse the repository at this point in the history
TODO: Language strings, check that the accepting user is the one that should be allowed to accept.
  • Loading branch information
snipe committed Feb 25, 2015
1 parent 4340d50 commit 097bb38
Show file tree
Hide file tree
Showing 18 changed files with 353 additions and 27 deletions.
49 changes: 49 additions & 0 deletions app/controllers/account/ViewAssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Location;
use View;
use Asset;
use Actionlog;
use Lang;

class ViewAssetsController extends AuthorizedController
{
Expand Down Expand Up @@ -55,6 +57,53 @@ public function getRequestAsset($assetId = null) {


}



// Get the acceptance screen
public function getAcceptAsset($assetId = null) {

// Check if the asset exists
if (is_null($asset = Asset::find($assetId))) {
// Redirect to the asset management page
return Redirect::to('account')->with('error', Lang::get('admin/hardware/message.does_not_exist'));
}

return View::make('frontend/account/accept-asset', compact('asset'));




}

// Save the acceptance
public function postAcceptAsset($assetId = null) {

// Check if the asset exists
if (is_null($asset = Asset::find($assetId))) {
// Redirect to the asset management page
return Redirect::to('account')->with('error', Lang::get('admin/hardware/message.does_not_exist'));
}

$user = Sentry::getUser();


$logaction = new Actionlog();
$logaction->asset_id = $assetId;
$logaction->checkedout_to = $asset->assigned_to;
$logaction->asset_type = 'hardware';
$logaction->note = e(Input::get('note'));
$logaction->user_id = $user->id;
$logaction->accepted_at = date("Y-m-d h:i:s");
$log = $logaction->logaction('accepted');

return Redirect::to('account/view-assets')->with('success', 'You have successfully accept this asset.');




}



}
24 changes: 20 additions & 4 deletions app/controllers/admin/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Config;
use Location;
use Log;
use Mail;

use BaconQrCode\Renderer\Image as QrImage;

Expand Down Expand Up @@ -432,7 +433,7 @@ public function postCheckout($assetId)


// Check if the user exists
if (is_null($assigned_to = User::find($assigned_to))) {
if (is_null($user = User::find($assigned_to))) {
// Redirect to the asset management page with error
return Redirect::to('hardware')->with('error', Lang::get('admin/hardware/message.user_does_not_exist'));
}
Expand All @@ -446,10 +447,23 @@ public function postCheckout($assetId)
$logaction->asset_id = $asset->id;
$logaction->checkedout_to = $asset->assigned_to;
$logaction->asset_type = 'hardware';
$logaction->location_id = $assigned_to->location_id;
$logaction->location_id = $user->location_id;
$logaction->user_id = Sentry::getUser()->id;
$logaction->note = e(Input::get('note'));
$log = $logaction->logaction('checkout');

$data['asset_id'] = $asset->id;
$data['eula'] = $asset->getEula();
$data['first_name'] = $user->first_name;


if ($asset->requireAcceptance()=='1') {

Mail::send('emails.accept-asset', $data, function ($m) use ($user) {
$m->to($user->email, $user->first_name . ' ' . $user->last_name);
$m->subject('Confirm asset delivery');
});
}

// Redirect to the new asset page
return Redirect::to("hardware")->with('success', Lang::get('admin/hardware/message.checkout.success'));
Expand Down Expand Up @@ -866,6 +880,8 @@ public function postBulkSave($assets = null)
return Redirect::to("hardware");

}






}
10 changes: 8 additions & 2 deletions app/controllers/admin/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ public function postCreate()
else{

// Update the category data
$category->name = e(Input::get('name'));
$category->user_id = Sentry::getId();
$category->name = e(Input::get('name'));
$category->eula_text = e(Input::get('eula_text'));
$category->use_default_eula = e(Input::get('use_default_eula', '1'));
$category->require_acceptance = e(Input::get('require_acceptance', '0'));
$category->user_id = Sentry::getId();

// Was the asset created?
if($category->save()) {
Expand Down Expand Up @@ -133,6 +136,9 @@ public function postEdit($categoryId = null)

// Update the category data
$category->name = e(Input::get('name'));
$category->eula_text = e(Input::get('eula_text'));
$category->use_default_eula = e(Input::get('use_default_eula', '1'));
$category->require_acceptance = e(Input::get('require_acceptance', '0'));

// Was the asset created?
if($category->save()) {
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function postEdit()
$setting->alert_email = e(Input::get('alert_email'));
$setting->alerts_enabled = e(Input::get('alerts_enabled', '0'));
$setting->header_color = e(Input::get('header_color'));
$setting->default_eula_text = e(Input::get('default_eula_text'));


// Was the asset updated?
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ public function postImport()
return Redirect::route('users')->with('duplicates',$duplicates)->with('success', 'Success');

}




Expand Down
69 changes: 69 additions & 0 deletions app/database/migrations/2015_02_25_022931_add_eula_fields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddEulaFields extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::table('settings', function ($table) {
$table->longText('default_eula_text');
});

Schema::table('categories', function ($table) {
$table->longText('eula_text');
$table->boolean('use_default_eula')->default(0);
$table->boolean('require_acceptance')->default(0);
});

Schema::table('asset_logs', function ($table) {
$table->dateTime('requested_at')->nullable()->default(NULL);
$table->dateTime('accepted_at')->nullable()->default(NULL);
});


Schema::create('requested_assets', function ($table) {
$table->increments('id');
$table->integer('asset_id')->default(NULL);
$table->integer('user_id')->default(NULL);
$table->dateTime('accepted_at')->nullable()->default(NULL);
$table->dateTime('denied_at')->nullable()->default(NULL);
$table->string('notes')->default(NULL);
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::table('settings', function ($table) {
$table->dropColumn('default_eula_text');
});

Schema::table('categories', function ($table) {
$table->dropColumn('eula_text');
$table->dropColumn('use_default_eula');
$table->dropColumn('require_acceptance');
});

Schema::table('asset_logs', function ($table) {
$table->dropColumn('requested_at');
$table->dropColumn('accepted_at');
});

Schema::drop('requested_assets');
}

}
10 changes: 10 additions & 0 deletions app/database/seeds/CategoriesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public function run()
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 1,
'use_default_eula' = 0;
'require_acceptance' = 0;
'deleted_at' => NULL,
);

Expand All @@ -21,6 +23,8 @@ public function run()
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 1,
'use_default_eula' = 0;
'require_acceptance' = 0;
'deleted_at' => NULL,
);

Expand All @@ -30,6 +34,8 @@ public function run()
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 1,
'use_default_eula' = 0;
'require_acceptance' = 0;
'deleted_at' => NULL,
);

Expand All @@ -39,6 +45,8 @@ public function run()
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 1,
'use_default_eula' = 0;
'require_acceptance' = 0;
'deleted_at' => NULL,
);

Expand All @@ -48,6 +56,8 @@ public function run()
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 1,
'use_default_eula' = 0;
'require_acceptance' = 0;
'deleted_at' => NULL,
);

Expand Down
6 changes: 6 additions & 0 deletions app/lang/en/admin/categories/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
'asset_categories' => 'Asset Categories',
'category_name' => 'Category Name',
'create' => 'Create Category',
'eula_text' => 'Category EULA',
'eula_text_help' => 'This field allows you to customize your EULAs for specific types of assets. If you only have one EULA for all of your assets, you can check the box below to use the primary default.',
'require_acceptance' => 'Require users to confirm acceptance of assets in this category.',
'no_default_eula' => 'No primary default EULA found. Add one in Settings.',
'update' => 'Update Category',
'use_default_eula' => 'Use the <a href="#" data-toggle="modal" data-target="#eulaModal">primary default EULA</a> instead.',
'use_default_eula_disabled' => '<del>Use the primary default EULA instead.</del> No primary default EULA is set. Please add one in Settings.',

);
9 changes: 5 additions & 4 deletions app/lang/en/admin/categories/table.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

return array(

'id' => 'ID',
'parent' => 'Parent',
'title' => 'Asset Category Name',
'eula_text' => 'EULA',
'id' => 'ID',
'parent' => 'Parent',
'require_acceptance' => 'Acceptance',
'title' => 'Asset Category Name',

);
4 changes: 3 additions & 1 deletion app/lang/en/admin/settings/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
'alerts_enabled' => 'Alerts enabled',
'auto_increment_assets' => 'Generate auto-incrementing asset IDs',
'auto_increment_prefix' => 'Prefix (optional)',
'auti_incrementing_help' => 'Enable auto-incrementing asset IDs first to set this',
'auto_incrementing_help' => 'Enable auto-incrementing asset IDs first to set this',
'default_eula_text' => 'Default EULA',
'default_eula_help_text' => 'You can also associate custom EULAs to specific asset categories.',
'display_asset_name' => 'Display Asset Name',
'display_checkout_date' => 'Display Checkout Date',
'display_eol' => 'Display EOL in table view',
Expand Down
19 changes: 19 additions & 0 deletions app/models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,25 @@ public static function autoincrement_asset()
return false;
}
}

public function requireAcceptance() {
return $this->model->category->require_acceptance;
}

public function getEula() {

if ($this->model->category->eula_text) {
return $this->model->category->eula_text;
} elseif (Setting::getSettings()->default_eula_text) {
return Setting::getSettings()->default_eula_text;
} else {
return null;
}

}





/**
Expand Down
13 changes: 9 additions & 4 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@

# Account Activation
Route::get('activate/{activationCode}', array('as' => 'activate', 'uses' => 'AuthController@getActivate'));

# Forgot Password
Route::get('forgot-password', array('as' => 'forgot-password', 'uses' => 'AuthController@getForgotPassword'));
Route::post('forgot-password', 'AuthController@postForgotPassword');
Expand All @@ -270,9 +270,7 @@

Route::group(array('prefix' => 'account', 'before' => 'auth', 'namespace' => 'Controllers\Account'), function () {

# Account Dashboard
Route::get('/', array('as' => 'account', 'uses' => 'DashboardController@getIndex'));


# Profile
Route::get('profile', array('as' => 'profile', 'uses' => 'ProfileController@getIndex'));
Route::post('profile', 'ProfileController@postIndex');
Expand All @@ -287,10 +285,17 @@
# Change Email
Route::get('change-email', array('as' => 'change-email', 'uses' => 'ChangeEmailController@getIndex'));
Route::post('change-email', 'ChangeEmailController@postIndex');

# Accept Asset
Route::get('accept-asset/{assetId}', array('as' => 'account/accept-assets', 'uses' => 'ViewAssetsController@getAcceptAsset'));
Route::post('accept-asset/{assetId}', array('as' => 'account/asset-accepted', 'uses' => 'ViewAssetsController@postAcceptAsset'));

# Profile
Route::get('requestable-assets', array('as' => 'requestable-assets', 'uses' => 'ViewAssetsController@getRequestableIndex'));
Route::get('request-asset/{assetId}', array('as' => 'account/request-asset', 'uses' => 'ViewAssetsController@getRequestAsset'));

# Account Dashboard
Route::get('/', array('as' => 'account', 'uses' => 'DashboardController@getIndex'));


});
Expand Down
Loading

0 comments on commit 097bb38

Please sign in to comment.