Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernize addon: moved from webuniversum to appuniversum, converted to glimmer components #4

Merged
merged 13 commits into from Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .editorconfig
Expand Up @@ -4,7 +4,6 @@

root = true


[*]
end_of_line = lf
charset = utf-8
Expand Down
2 changes: 2 additions & 0 deletions .eslintignore
Expand Up @@ -13,6 +13,8 @@
# misc
/coverage/
!.*
.*/
.eslintcache

# ember-try
/.node_modules.ember-try/
Expand Down
41 changes: 22 additions & 19 deletions .eslintrc.js
@@ -1,56 +1,59 @@
'use strict';

module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true
}
legacyDecorators: true,
},
},
plugins: [
'ember'
],
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
'plugin:ember/recommended',
'plugin:prettier/recommended',
],
env: {
browser: true
},
rules: {
'ember/no-jquery': 'error'
browser: true,
},
rules: {},
overrides: [
// node files
{
files: [
'.eslintrc.js',
'.prettierrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'index.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'tests/dummy/config/**/*.js'
'tests/dummy/config/**/*.js',
],
excludedFiles: [
'addon/**',
'addon-test-support/**',
'app/**',
'tests/dummy/app/**'
'tests/dummy/app/**',
],
parserOptions: {
sourceType: 'script'
sourceType: 'script',
},
env: {
browser: false,
node: true
node: true,
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
})
}
]
extends: ['plugin:node/recommended'],
},
{
// Test files:
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
},
],
};
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,6 +12,7 @@
/.env*
/.pnp*
/.sass-cache
/.eslintcache
/connect.lock
/coverage/
/libpeerconnection.log
Expand Down
6 changes: 5 additions & 1 deletion .npmignore
Expand Up @@ -8,12 +8,15 @@
# misc
/.bowerrc
/.editorconfig
/.ember-cli.js
/.ember-cli
/.env*
/.eslintcache
/.eslintignore
/.eslintrc.js
/.git/
/.gitignore
/.prettierignore
/.prettierrc.js
/.template-lintrc.js
/.travis.yml
/.watchmanconfig
Expand All @@ -23,6 +26,7 @@
/ember-cli-build.js
/testem.js
/tests/
/yarn-error.log
/yarn.lock
.gitkeep

Expand Down
21 changes: 21 additions & 0 deletions .prettierignore
@@ -0,0 +1,21 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.eslintcache

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
5 changes: 5 additions & 0 deletions .prettierrc.js
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
singleQuote: true,
};
2 changes: 1 addition & 1 deletion .template-lintrc.js
@@ -1,5 +1,5 @@
'use strict';

module.exports = {
extends: 'recommended'
extends: 'recommended',
};
28 changes: 17 additions & 11 deletions .travis.yml
Expand Up @@ -3,10 +3,9 @@ language: node_js
node_js:
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- "8"
- "10"

sudo: false
dist: trusty
dist: xenial

addons:
chrome: stable
Expand All @@ -27,29 +26,36 @@ branches:
- /^v\d+\.\d+\.\d+/

jobs:
fail_fast: true
fast_finish: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary

include:
# runs linting and tests with current locked deps

- stage: "Tests"
name: "Tests"
script:
- npm run lint:hbs
- npm run lint:js
- npm test
- npm run lint
- npm run test:ember

- stage: "Additional Tests"
name: "Floating Dependencies"
install:
- npm install --no-package-lock
script:
- npm run test:ember

# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- stage: "Additional Tests"
env: EMBER_TRY_SCENARIO=ember-lts-3.4
- env: EMBER_TRY_SCENARIO=ember-lts-3.8
- env: EMBER_TRY_SCENARIO=ember-lts-3.20
- env: EMBER_TRY_SCENARIO=ember-lts-3.24
- env: EMBER_TRY_SCENARIO=ember-release
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery
- env: EMBER_TRY_SCENARIO=ember-classic
- env: EMBER_TRY_SCENARIO=embroider-safe
- env: EMBER_TRY_SCENARIO=embroider-optimized

script:
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO
7 changes: 3 additions & 4 deletions CONTRIBUTING.md
Expand Up @@ -8,9 +8,8 @@

## Linting

* `npm run lint:hbs`
* `npm run lint:js`
* `npm run lint:js -- --fix`
* `npm run lint`
* `npm run lint:fix`

## Running tests

Expand All @@ -23,4 +22,4 @@
* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).

For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -7,9 +7,9 @@ Ember addon providing an Ember Simple Auth authenticator for ACM/IDM and a simpl
Compatibility
------------------------------------------------------------------------------

* Ember.js v3.4 or above
* Ember CLI v2.13 or above
* Node.js v8 or above
* Ember.js v3.20 or above
* Ember CLI v3.20 or above
* Node.js v10 or above


Installation
Expand Down
37 changes: 17 additions & 20 deletions addon/authenticators/torii.js
Expand Up @@ -5,23 +5,22 @@ import fetch, { Headers } from 'fetch';
const basePath = '/sessions';
const toriiProvider = 'acmidm-oauth2';


/**
* ACM/IDM OAuth2 authenticator
*/
export default ToriiAuthenticator.extend({
torii: service(),
*/
export default class AcmIdmOAuth2Authenticator extends ToriiAuthenticator {
@service torii;

async authenticate() {
const data = await this._super(...arguments); // get authorization code through Torii
const data = await super.authenticate(...arguments); // get authorization code through Torii
const result = await fetch(basePath, {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/vnd.api+json'
'Content-Type': 'application/vnd.api+json',
}),
body: JSON.stringify({
authorizationCode: data.authorizationCode
})
authorizationCode: data.authorizationCode,
}),
});

if (result.ok) {
Expand All @@ -31,29 +30,27 @@ export default ToriiAuthenticator.extend({
} else {
throw result;
}
},
}

async invalidate() {
const result = await fetch(`${basePath}/current`, {
method: 'DELETE',
headers: new Headers({
'Content-Type': 'application/vnd.api+json'
})
'Content-Type': 'application/vnd.api+json',
}),
});

if (result.ok)
return result;
else
throw result;
},
if (result.ok) return result;
else throw result;
}

async restore() {
await this._super(...arguments);
await super.restore(...arguments);
const result = await fetch(`${basePath}/current`, {
method: 'GET',
headers: new Headers({
'Content-Type': 'application/vnd.api+json'
})
'Content-Type': 'application/vnd.api+json',
}),
});

if (result.ok) {
Expand All @@ -64,4 +61,4 @@ export default ToriiAuthenticator.extend({
throw result;
}
}
});
}
6 changes: 6 additions & 0 deletions addon/components/acmidm-login.hbs
@@ -0,0 +1,6 @@
<AuButton @loading={{this.isAuthenticating}} @disabled={{this.isAuthenticating}} {{on "click" this.login}}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using (and depending on) Appuniversum, it might be nice to keep these components styling agnostic?

I think this can easily be achieved by yielding state instead of outputting html. That way projects can decide which components to use.

Depending on appuniversum will also create an extra maintenance burden since it will need to be bumped from time to time (especially since it's a 0.x release).

Copy link
Contributor

@Windvis Windvis Aug 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most projects also seem to implement a "compact" version (which duplicates the logic) of this component for the main header. That would then no longer be needed either.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a great idea, but would keep this for backwards compatibility. perhaps adding a deprecation warning in the constructor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the data-table we took the approach of a styling agnostic addon and another addon that extends it with Appuniversum, but that results in a heavier maintentance burden I must admit (and still makes it a breaking change for this addon atm).

I'm pro the deprecation warning in this PR. It paves the way to a styling agnostic version and thus a breaking release in the future. But I would implement that in a separate PR and not lump it on this one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only see now that there is a PR #5 already 🙈

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I created a follow-up PR as a quick POC of what a styling agnostic version could look like. I don't think the deprecation warnings should be added here since there are no alternatives yet, but I can add them to that PR as well.

Meld u aan
</AuButton>
{{#if this.errorMessage}}
<AuAlert @alertIcon="alert-triangle" @alertTitle={{this.errorMessage}} />
{{/if}}
45 changes: 25 additions & 20 deletions addon/components/acmidm-login.js
@@ -1,26 +1,31 @@
import Component from '@glimmer/component';
import { warn } from '@ember/debug';
import Component from '@ember/component';
import layout from '../templates/components/acmidm-login';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';

export default Component.extend({
layout,
session: service('session'),
actions: {
login() {
this.set('errorMessage', '');
this.set('isAuthenticating', true);
this.session.authenticate('authenticator:torii', 'acmidm-oauth2').catch((reason) => {
warn(reason.error || reason, { id: 'authentication.failure' });
export default class AcmidmLoginComponent extends Component {
@tracked errorMessage = '';
@tracked isAuthenticating = false;
@service session;

if (reason.status == 403)
this.set('errorMessage', 'U heeft geen toegang tot deze applicatie.');
else
this.set('errorMessage', 'Fout bij het aanmelden. Gelieve opnieuw te proberen.');
})
.finally(() => {
this.set('isAuthenticating', false);
});
@action
async login() {
this.errorMessage = '';
this.isAuthenticating = true;

try {
await this.session.authenticate('authenticator:torii', 'acmidm-oauth2');
} catch (reason) {
warn(reason.error || reason, { id: 'authentication.failure' });

if (reason.status == 403)
this.errorMessage = 'U heeft geen toegang tot deze applicatie.';
else
this.errorMessage =
'Fout bij het aanmelden. Gelieve opnieuw te proberen.';
} finally {
this.isAuthenticating = false;
}
}
});
}
7 changes: 7 additions & 0 deletions addon/components/acmidm-logout.hbs
@@ -0,0 +1,7 @@
<button ...attributes type="button" {{on "click" this.logout}}>
{{#if (has-block)}}
{{yield}}
{{else}}
Meld u af
{{/if}}
</button>