From fb79fea0eae02f25ec022acb0cc5a4bd56f613b5 Mon Sep 17 00:00:00 2001 From: Nils Rauch Date: Thu, 24 Jun 2021 14:23:24 +0200 Subject: [PATCH 1/5] Search by favourite, refs: #458 --- app/presenters/filtered_list.rb | 1 + app/presenters/teams/filtered_list.rb | 14 ++++++++------ frontend/app/routes/teams/index.js | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/presenters/filtered_list.rb b/app/presenters/filtered_list.rb index ce1cd2aef..92b3a2b62 100644 --- a/app/presenters/filtered_list.rb +++ b/app/presenters/filtered_list.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class FilteredList + include ParamConverters def initialize(current_user, params) @current_user = current_user diff --git a/app/presenters/teams/filtered_list.rb b/app/presenters/teams/filtered_list.rb index 18a0eb3fe..378b2d387 100644 --- a/app/presenters/teams/filtered_list.rb +++ b/app/presenters/teams/filtered_list.rb @@ -4,12 +4,14 @@ module ::Teams class FilteredList < ::FilteredList def fetch_entries - return filter_by_query if query_present? - return filter_by_id if team_id.present? - return filter_by_favourite if favourite.present? - return filter_by_last_teammember if only_teammember_user.present? + filtered_teams = teams - teams + filtered_teams = filter_by_favourite if favourite.present? && true?(favourite) + filtered_teams = filter_by_query(filtered_teams) if query_present? + filtered_teams = filter_by_id if team_id.present? + filtered_teams = filter_by_last_teammember if only_teammember_user.present? + + filtered_teams end private @@ -44,7 +46,7 @@ def limit @params[:limit] end - def filter_by_query + def filter_by_query(teams) teams.includes(:folders, folders: [:accounts]).where( 'lower(accounts.description) LIKE :query OR lower(accounts.accountname) LIKE :query diff --git a/frontend/app/routes/teams/index.js b/frontend/app/routes/teams/index.js index 23b7461e9..fc3cf4b68 100644 --- a/frontend/app/routes/teams/index.js +++ b/frontend/app/routes/teams/index.js @@ -25,6 +25,7 @@ export default class TeamsIndexRoute extends BaseRoute { model(params) { params["limit"] = 10; + params["favourite"] = this.navService.isShowingFavourites; return this.store.query("team", params); } } From 42b33dfafea164b99fc6b4f1cb8d52bd18ea82ba Mon Sep 17 00:00:00 2001 From: Nils Rauch Date: Fri, 25 Jun 2021 13:59:57 +0200 Subject: [PATCH 2/5] Adjust placeholder for searchbar if searching in favorites --- frontend/app/templates/components/nav-bar.hbs | 2 +- frontend/translations/ch_be.yml | 4 +++- frontend/translations/de.yml | 4 +++- frontend/translations/en.yml | 4 +++- frontend/translations/fr.yml | 4 +++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/frontend/app/templates/components/nav-bar.hbs b/frontend/app/templates/components/nav-bar.hbs index 1ee438606..f7aaf9f16 100644 --- a/frontend/app/templates/components/nav-bar.hbs +++ b/frontend/app/templates/components/nav-bar.hbs @@ -20,7 +20,7 @@
+{{/if}} + +{{#if this.isEditing}} + +{{/if}} diff --git a/frontend/app/templates/profile.hbs b/frontend/app/templates/profile.hbs index 1af4c837d..f631eeac1 100644 --- a/frontend/app/templates/profile.hbs +++ b/frontend/app/templates/profile.hbs @@ -1,6 +1,12 @@
-

{{t "profile.index.title"}}

- +
+
+

{{t "profile.index.title"}}

+
+
+ +
+
diff --git a/frontend/app/validations/user-human/passwordEdit.js b/frontend/app/validations/user-human/passwordEdit.js new file mode 100644 index 000000000..e4f43d279 --- /dev/null +++ b/frontend/app/validations/user-human/passwordEdit.js @@ -0,0 +1,13 @@ +import { + validatePresence, + validateConfirmation +} from "ember-changeset-validations/validators"; + +export default { + oldPassword: [validatePresence(true)], + newPassword1: [validatePresence(true)], + newPassword2: [ + validatePresence(true), + validateConfirmation({ on: "newPassword1" }) + ] +}; diff --git a/frontend/tests/integration/components/profile/password-update-test.js b/frontend/tests/integration/components/profile/password-update-test.js new file mode 100644 index 000000000..96d14aa39 --- /dev/null +++ b/frontend/tests/integration/components/profile/password-update-test.js @@ -0,0 +1,38 @@ +import { module, test } from "qunit"; +import { setupRenderingTest } from "ember-qunit"; +import { render } from "@ember/test-helpers"; +import { hbs } from "ember-cli-htmlbars"; +import { setLocale } from "ember-intl/test-support"; +import ENV from "../../../../config/environment"; + +module("Integration | Component | profile/password-update", function (hooks) { + setupRenderingTest(hooks); + + hooks.beforeEach(function () { + setLocale("en"); + }); + + test("it renders for user with db as auth provider", async function (assert) { + let tempUserAuth = ENV.currentUserAuth; + ENV.currentUserAuth = "db"; + + await render(hbs``); + + const text = this.element.textContent.trim(); + assert.ok(text.includes("Manage password")); + + ENV.currentUserAuth = tempUserAuth; + }); + + test("it does not render for user with ldap or oidc auth provider", async function (assert) { + let tempUserAuth = ENV.currentUserAuth; + ENV.currentUserAuth = "oidc"; + + await render(hbs``); + + const text = this.element.textContent.trim(); + assert.notOk(text.includes("Manage password")); + + ENV.currentUserAuth = tempUserAuth; + }); +}); diff --git a/frontend/translations/ch_be.yml b/frontend/translations/ch_be.yml index e02624654..136708830 100644 --- a/frontend/translations/ch_be.yml +++ b/frontend/translations/ch_be.yml @@ -413,6 +413,11 @@ ch_be: succeed: D Wartigsufgab isch erfougrich düregfüehrt worde failed: D Wartigsufgab isch gschiteret. Lueg i de Logs für me Details nache. + profile: + changePassword: + success: Ds Passwort isch erfougrich gänderet worde. + new_passwords_not_equal: Di nöie Passwörter si nid glich. + user-humen: created: Dr nöi Benutzer isch erfougrich ersteut worde. updated: Dr Benutzer isch erfougrich aktualisiert worde. @@ -448,7 +453,6 @@ ch_be: auth_failed: Irgendöppis vo dine Logindate isch fautsch only_local: Nume lokali Benutzer dörfe ires Passwort ändere. new_password_set: Ds nöie Passwort isch erfougrich gsetzt worde. - new_passwords_not_equal: Di nöie Passwörter si nid glich. not_local: Du bisch ke lokale Benutzer! locked: Dr Benutzer isch momentan gsperrt. Bitte probiers speter nomau oder kontaktier dr Administrator. weak_password: Um d Sicherheit z verbessere, söttisch es komplizierteres Passwort wähle @@ -476,6 +480,12 @@ ch_be: givenname: Vorname surname: Nachname submit: Ersteue + managePassword: Passwortverwautig + updatePassword: Ds Passwort ernöiere + oldPassword: "Ds aute Passwort:" + newPassword1: "Ds nöie Passwort:" + newPassword2: "Ds nöie Passwort bestätige:" + wrongPassword: Fautsches passwort account: account: Account account_name: Accountname @@ -615,3 +625,10 @@ ch_be: present: Dr Vorname muess vorhande si password: present: Ds Passwort muess vorhande si + "old password": + present: Ds aktuelle Passwort ihgäh + "new password1": + present: Ds nöie Passwort ihgäh + "new password2": + present: Ds nöie Passwort bestätige + confirmation: Di nöie Passwörter stimme nid überiih diff --git a/frontend/translations/de.yml b/frontend/translations/de.yml index 04ae87ed6..81835ebac 100644 --- a/frontend/translations/de.yml +++ b/frontend/translations/de.yml @@ -393,6 +393,11 @@ de: ldap_connection: failed: Kein konfigurierter Ldap-Server konnte erreicht werden. + profile: + changePassword: + success: Das Passwort wurde erfolgreich geändert. + new_passwords_not_equal: Die neuen Passwörter sind nicht gleich. + user-humen: created: Der neue Benutzer wurde erfolgreich erstellt. updated: Der Benutzer wurde erfolgreich aktualisiert. @@ -428,7 +433,6 @@ de: auth_failed: Ungültiger Benutzername / Passwort. only_local: Nur lokale Benutzer dürfen ihr Passwort ändern. new_password_set: Das neue Passwort wurde erfolgreich gesetzt. - new_passwords_not_equal: Die neuen Passwörter sind nicht gleich. not_local: Sie sind kein lokaler Benutzer! locked: Der Benutzer ist momentan gesperrt. Bitte versuchen Sie es später nocheinmal oder kontaktiern Sie den Administrator. weak_password: Um die Sicherheit zu verbessern, sollten Sie ein komplexeres Passwort wählen @@ -457,6 +461,12 @@ de: givenname: Vorname surname: Nachname submit: Erstellen + managePassword: Passwort verwalten + updatePassword: Passwort erneuern + oldPassword: "Altes Passwort:" + newPassword1: "Neues Passwort:" + newPassword2: "Neues Passwort bestätigen:" + wrongPassword: Falsches Passwort account: account: Account account_name: Accountname @@ -603,3 +613,10 @@ de: present: Der Vorname muss vorhanden sein password: present: Das Passwort muss vorhanden sein + "old password": + present: Aktuelles Passwort eingeben + "new password1": + present: Neues Passwort eingeben + "new password2": + present: Neues Passwort bestätigen + confirmation: Die Passwörter stimmen nicht überein diff --git a/frontend/translations/en.yml b/frontend/translations/en.yml index 1a7b701fd..a51a025ca 100644 --- a/frontend/translations/en.yml +++ b/frontend/translations/en.yml @@ -391,6 +391,11 @@ en: failed: Task failed. See logs for more information. ldap_connection: failed: No configured Ldap Server could be reached. + + profile: + changePassword: + success: Successfully changed password. + new_passwords_not_equal: New passwords not equal user-humen: created: Successfully created a new user. @@ -429,7 +434,6 @@ en: auth_failed: Authentication failed! Enter a correct username and password. only_local: Only local users are allowed to change their password. new_password_set: You successfully set the new password - new_passwords_not_equal: New passwords not equal wrong_password: Invalid user / password wrong_root: Login as root only from private IP accessible not_local: You are not a local user! @@ -500,8 +504,16 @@ en: user: username: Username password: Password + admin: Admin givenname: Given name surname: Surname + submit: Submit + managePassword: Manage password + updatePassword: Update password + oldPassword: "Enter old password:" + newPassword1: "Enter new password:" + newPassword2: "Confirm new password:" + wrongPassword: Wrong password account: account_name: Accountname team: @@ -537,3 +549,10 @@ en: present: Givenname must be present password: present: Password must be present + "old password": + present: Please enter current password + "new password1": + present: Please enter new password + "new password2": + present: Please confirm new password + confirmation: New passwords don't match diff --git a/frontend/translations/fr.yml b/frontend/translations/fr.yml index 5f35e8e06..a8ff78931 100644 --- a/frontend/translations/fr.yml +++ b/frontend/translations/fr.yml @@ -394,6 +394,11 @@ fr: ldap_connection: failed: Aucunt serveur LDAP configuré n'a pu être atteint. + profile: + changePassword: + success: Le mot de passe a été modifié avec succès. + new_passwords_not_equal: Nouveaux mots de passe n'est pas égal. + user-humen: created: Utilisateur créé avec succès. updated: Utilisateur modifiée avec succès. @@ -429,7 +434,6 @@ fr: auth_failed: L'authentification a échoué! Saisissez un nom d'utilisateur et mot de passe. only_local: Only local users are allowed to change their password. new_password_set: Vous mis à jour avec succès le nouveau mot de passe. - new_passwords_not_equal: Nouveaux mots de passe n'est pas égal. wrong_password: Mot de passe incorrect. weak_password: Pour améliorer la sécurité vous devez déterminer un mot de passe utilisateur plus complexe. not_local: Vous n'êtes pas un utilisateur local! @@ -459,6 +463,13 @@ fr: admin: Admin givenname: Prénom surname: Nom de famille + submit: Soumettre + managePassword: Gérer le mot de passe + updatePassword: Changer le mot de passe + oldPassword: "Entrez le mot de passe actuel:" + newPassword1: "Entrez un nouveau mot de passe:" + newPassword2: "Confirmer le nouveau mot de passe:" + wrongPassword: Mauvais mot de passe account: account: Compte account_name: Nom du compte @@ -606,3 +617,10 @@ fr: present: Le prénom doit être présent password: present: Le mot de passe doit être présent + "old password": + present: Entrer le mot de passe actuel + "new password1": + present: Entrer le nouveau mot de passe + "new password2": + present: Confirmer le nouveau mot de passe + confirmation: Les mots de passe ne correspondent pas diff --git a/spec/controllers/api/profile/password_controller_spec.rb b/spec/controllers/api/profile/password_controller_spec.rb new file mode 100644 index 000000000..eec731069 --- /dev/null +++ b/spec/controllers/api/profile/password_controller_spec.rb @@ -0,0 +1,114 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Api::Profile::PasswordController do + include ControllerHelpers + + let(:api_user) { users(:alice).api_users.create! } + + context 'POST update_password' do + it 'updates password' do + login_as(:bob) + password_params = { + data: { + attributes: { old_password: 'password', + new_password1: 'test', + new_password2: 'test' } + } + } + patch :update, params: password_params + + expect(json['info']).to include('flashes.profile.changePassword.success') + expect(users(:bob).authenticate_db('test')).to eq true + end + + it 'updates password, error if oldpassword not match' do + login_as(:bob) + password_params = { + data: { + attributes: { old_password: 'wrong_password', + new_password1: 'test', + new_password2: 'test' } + } + } + patch :update, params: password_params + + expect(json['errors']).to include('helpers.label.user.wrongPassword') + expect(users(:bob).authenticate_db('test')).to be false + end + + it 'updates password, error if new passwords not match' do + login_as(:bob) + password_params = { + data: { + attributes: { old_password: 'password', + new_password1: 'test', + new_password2: 'wrong_password' } + } + } + patch :update, params: password_params + + expect(json['errors']).to include('flashes.profile.changePassword.new_passwords_not_equal') + expect(users(:bob).authenticate_db('test')).to eq false + end + + it 'returns unauthorized if ldap user tries to update password' do + users(:bob).update!(auth: 'ldap') + login_as(:bob) + password_params = { + data: { + attributes: { old_password: 'password', + new_password1: 'test', + new_password2: 'test' } + } + } + patch :update, params: password_params + + expect(response).to have_http_status(403) + end + + it 'returns unauthorized if oidc user tries to update password' do + users(:bob).update!(auth: 'oidc') + login_as(:bob) + password_params = { + data: { + attributes: { old_password: 'password', + new_password1: 'test', + new_password2: 'test' } + } + } + patch :update, params: password_params + + expect(response).to have_http_status(403) + end + + it 'returns unauthorized if api user tries to update password' do + login_as_api_user + password_params = { + data: { + attributes: { old_password: api_user_token, + new_password1: 'test', + new_password2: 'test' } + } + } + patch :update, params: password_params + + expect(response).to have_http_status(403) + end + end + + private + + def login_as_api_user + api_user.update!(valid_until: Time.zone.now + 5.minutes) + request.headers['Authorization-User'] = api_user.username + request.headers['Authorization-Password'] = api_user_token + end + + def api_user_token + private_key = users(:alice).decrypt_private_key('password') + decrypted_token = api_user.send(:decrypt_token, private_key) + Base64.encode64(decrypted_token) + end +end diff --git a/spec/controllers/session_controller_spec.rb b/spec/controllers/session_controller_spec.rb index f1708165c..e311d4bd6 100644 --- a/spec/controllers/session_controller_spec.rb +++ b/spec/controllers/session_controller_spec.rb @@ -5,37 +5,6 @@ describe SessionController do include ControllerHelpers - context 'GET show_update_password' do - it 'does not authorize previously authorized source ip' do - source_ip = '102.20.2.1' - expect_any_instance_of(Authentication::SourceIpChecker) - .to receive(:ip_authorized?) - .and_return(true) - expect_any_instance_of(ActionController::TestRequest) - .to receive(:remote_ip) - .exactly(3).times - .and_return(source_ip) - session[:authorized_ip] = source_ip - session[:user_id] = users(:bob).id - session[:private_key] = 'fookey' - - expect_any_instance_of(Authentication::SourceIpChecker).to receive(:previously_authorized?) - expect_any_instance_of(Authentication::SourceIpChecker).to receive(:ip_authorized?).never - - get :show_update_password - - expect(response).to have_http_status(200) - end - - it 'redirects if ldap user tries to access update password site' do - users(:bob).update!(auth: 'ldap') - login_as(:bob) - get :show_update_password - - expect(response).to redirect_to root_path - end - end - context 'GET new' do it 'should show 401 if ip address is unauthorized' do @@ -144,49 +113,4 @@ post :create, params: { password: 'password', username: 'bob' } end end - - context 'POST update_password' do - it 'updates password' do - login_as(:bob) - post :update_password, params: { old_password: 'password', new_password1: 'test', - new_password2: 'test' } - - expect(flash[:notice]).to match(/new password/) - expect(users(:bob).authenticate_db('test')).to eq true - end - - it 'updates password, error if oldpassword not match' do - login_as(:bob) - post :update_password, params: { old_password: 'wrong_password', new_password1: 'test', - new_password2: 'test' } - - expect(flash[:error]).to match(/Invalid user \/ password/) - expect(users(:bob).authenticate_db('test')).to be false - end - - it 'updates password, error if new passwords not match' do - login_as(:bob) - post :update_password, params: { old_password: 'password', new_password1: 'test', - new_password2: 'wrong_password' } - - expect(flash[:error]).to match(/New passwords not equal/) - expect(users(:bob).authenticate_db('test')).to eq false - end - - it 'redirects if ldap user tries to update password' do - users(:bob).update!(auth: 'ldap') - login_as(:bob) - post :update_password, params: { old_password: 'password', new_password1: 'test', - new_password2: 'test' } - expect(response).to redirect_to root_path - end - - it 'redirects if oidc user tries to update password' do - users(:bob).update!(auth: 'oidc') - login_as(:bob) - post :update_password, params: { old_password: 'password', new_password1: 'test', - new_password2: 'test' } - expect(response).to redirect_to root_path - end - end end diff --git a/spec/policies/session_policy_spec.rb b/spec/policies/session_policy_spec.rb index 507a7ffd6..14d394ffd 100644 --- a/spec/policies/session_policy_spec.rb +++ b/spec/policies/session_policy_spec.rb @@ -17,18 +17,6 @@ it 'may not logout' do refute_permit nil, :session, :destroy? end - - it 'may not change locale' do - refute_permit nil, :session, :changelocale? - end - - it 'may not update password' do - refute_permit nil, :session, :update_password? - end - - it 'may not show update password form' do - refute_permit nil, :session, :show_update_password? - end end context 'already logged in user' do @@ -43,29 +31,5 @@ it 'may logout' do assert_permit bob, :session, :destroy? end - - it 'may change locale' do - assert_permit bob, :session, :changelocale? - end - - it 'may update password' do - assert_permit bob, :session, :update_password? - end - - it 'may show update password form' do - assert_permit bob, :session, :show_update_password? - end - end - - context 'ldap user' do - it 'may not change password' do - bob.update!(auth: 'ldap') - refute_permit bob, :session, :update_password? - end - - it 'may not show change password form' do - bob.update!(auth: 'ldap') - refute_permit bob, :session, :show_update_password? - end end end From 547fc560b1889c8b4ca1ba6977ba1d6d331ac27b Mon Sep 17 00:00:00 2001 From: e517589 Date: Mon, 28 Jun 2021 13:48:53 +0200 Subject: [PATCH 4/5] Hide side nav bar on profile, refs: #456 --- frontend/app/services/nav-service.js | 6 +- frontend/app/templates/admin.hbs | 6 +- .../app/templates/components/index-button.hbs | 5 ++ frontend/app/templates/profile.hbs | 62 ++++++++++--------- 4 files changed, 43 insertions(+), 36 deletions(-) create mode 100644 frontend/app/templates/components/index-button.hbs diff --git a/frontend/app/services/nav-service.js b/frontend/app/services/nav-service.js index 64b91557f..f6480b34e 100644 --- a/frontend/app/services/nav-service.js +++ b/frontend/app/services/nav-service.js @@ -21,7 +21,11 @@ export default class NavService extends Service { } get showSideNavBar() { - const sideNavBarDisabledRoutes = ["admin.settings", "admin.users"]; + const sideNavBarDisabledRoutes = [ + "admin.settings", + "admin.users", + "profile" + ]; return !sideNavBarDisabledRoutes.includes(this.router.currentRouteName); } diff --git a/frontend/app/templates/admin.hbs b/frontend/app/templates/admin.hbs index 652d42b81..d5fb2fd26 100644 --- a/frontend/app/templates/admin.hbs +++ b/frontend/app/templates/admin.hbs @@ -1,8 +1,4 @@
- - - - - + {{outlet}}
diff --git a/frontend/app/templates/components/index-button.hbs b/frontend/app/templates/components/index-button.hbs new file mode 100644 index 000000000..825872bcb --- /dev/null +++ b/frontend/app/templates/components/index-button.hbs @@ -0,0 +1,5 @@ + + + + + diff --git a/frontend/app/templates/profile.hbs b/frontend/app/templates/profile.hbs index f631eeac1..df9051d84 100644 --- a/frontend/app/templates/profile.hbs +++ b/frontend/app/templates/profile.hbs @@ -1,34 +1,36 @@
-
-
-

{{t "profile.index.title"}}

-
-
- + +
+
+
+

{{t "profile.index.title"}}

+
+
+ +
+ + +
+ + + + + + + + + + + + +
{{t "profile.info.last_login_at"}} {{t "profile.info.last_login_from"}}
{{moment-format @model.info.lastLoginAt "DD.MM.YYYY hh:mm"}}{{@model.info.lastLoginFrom}}
+
+ +
+ +
+
+
- - - - - - - - - - - - - - - -
{{t "profile.info.last_login_at"}} {{t "profile.info.last_login_from"}}
{{moment-format @model.info.lastLoginAt "DD.MM.YYYY hh:mm"}}{{@model.info.lastLoginFrom}}
-
- - -
- -
-
-
From 9a4ed8fe34fd16f14ae73702bdf2283471701845 Mon Sep 17 00:00:00 2001 From: miosidler <78365253+miosidler@users.noreply.github.com> Date: Tue, 29 Jun 2021 09:50:42 +0200 Subject: [PATCH 5/5] Move created/last updated below account title (#476) --- frontend/app/templates/components/account/show.hbs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/app/templates/components/account/show.hbs b/frontend/app/templates/components/account/show.hbs index a564e8190..8312ac2a2 100644 --- a/frontend/app/templates/components/account/show.hbs +++ b/frontend/app/templates/components/account/show.hbs @@ -4,7 +4,7 @@ {{#if this.isFileEntryCreating}} {{/if}} -