github.com/outbrain/consul@v1.4.5/ui-v2/app/mixins/acl/with-actions.js (about)

     1  import Mixin from '@ember/object/mixin';
     2  import { get } from '@ember/object';
     3  import { inject as service } from '@ember/service';
     4  import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions';
     5  
     6  export default Mixin.create(WithBlockingActions, {
     7    settings: service('settings'),
     8    actions: {
     9      use: function(item) {
    10        return get(this, 'feedback').execute(() => {
    11          // old style legacy ACLs don't have AccessorIDs
    12          // therefore set it to null, this way the frontend knows
    13          // to use legacy ACLs
    14          return get(this, 'settings')
    15            .persist({
    16              token: {
    17                AccessorID: null,
    18                SecretID: get(item, 'ID'),
    19              },
    20            })
    21            .then(() => {
    22              return this.transitionTo('dc.services');
    23            });
    24        }, 'use');
    25      },
    26      // TODO: This is also used in tokens, probably an opportunity to dry this out
    27      logout: function(item) {
    28        return get(this, 'feedback').execute(() => {
    29          return get(this, 'settings')
    30            .delete('token')
    31            .then(() => {
    32              // in this case we don't do the same as delete as we want to go to the new
    33              // dc.acls.tokens page. If we get there via the dc.acls redirect/rewrite
    34              // then we lose the flash message
    35              return this.transitionTo('dc.acls.tokens');
    36            });
    37        }, 'logout');
    38      },
    39      clone: function(item) {
    40        return get(this, 'feedback').execute(() => {
    41          return get(this, 'repo')
    42            .clone(item)
    43            .then(item => {
    44              // cloning is similar to delete in that
    45              // if you clone from the listing page, stay on the listing page
    46              // whereas if you clone form another token, take me back to the listing page
    47              // so I can see it
    48              return this.afterDelete(...arguments);
    49            });
    50        }, 'clone');
    51      },
    52    },
    53  });