github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/app/tests/helpers/stub-audit.js (about)

     1  // Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
     2  //
     3  // This software (Documize Community Edition) is licensed under 
     4  // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
     5  //
     6  // You can operate outside the AGPL restrictions by purchasing
     7  // Documize Enterprise Edition and obtaining a commercial license
     8  // by contacting <sales@documize.com>. 
     9  //
    10  // https://documize.com
    11  
    12  import Ember from 'ember';
    13  // import netUtil from 'documize/utils/net';
    14  
    15  const Audit = Ember.Service.extend({
    16  	sessionService: Ember.inject.service('session'),
    17  	ready: false,
    18  	enabled: true,
    19  
    20  	init() {
    21  		this.start();
    22  	},
    23  
    24  	record(id) {
    25  		if (!this.get('enabled')) {
    26  			return;
    27  		}
    28  
    29  		if (!this.get('ready')) {
    30  			this.start();
    31  		}
    32  
    33  		return id;
    34  
    35  	},
    36  
    37  	stop() {},
    38  
    39  	start() {
    40  		let session = this.get('sessionService');
    41  
    42  		if (!this.get('enabled') || !session.authenticated || this.get('ready')) {
    43  			return;
    44  		}
    45  
    46  		this.set('ready', true);
    47  	},
    48  });
    49  
    50  export default Ember.Test.registerAsyncHelper('stubAudit', function (app, test, attrs = {}) {
    51  	test.register('service:audit', Audit.extend(attrs));
    52  });