From 9e5cf66be7ad897e106f283bee73a165c72e74de Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 28 Oct 2022 16:15:04 +0200 Subject: Breaking API: Consistency with role id/label --- server/models/user/user.ts | 6 ++++-- server/tests/api/users/users.ts | 6 +++--- server/tests/plugins/external-auth.ts | 6 +++--- server/tests/plugins/id-and-pass-auth.ts | 8 ++++---- 4 files changed, 14 insertions(+), 12 deletions(-) (limited to 'server') diff --git a/server/models/user/user.ts b/server/models/user/user.ts index 34329580b..f70feed73 100644 --- a/server/models/user/user.ts +++ b/server/models/user/user.ts @@ -891,8 +891,10 @@ export class UserModel extends Model>> { autoPlayNextVideoPlaylist: this.autoPlayNextVideoPlaylist, videoLanguages: this.videoLanguages, - role: this.role, - roleLabel: USER_ROLE_LABELS[this.role], + role: { + id: this.role, + label: USER_ROLE_LABELS[this.role] + }, videoQuota: this.videoQuota, videoQuotaDaily: this.videoQuotaDaily, diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 3952a7aed..421b3ce16 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -219,7 +219,7 @@ describe('Test users', function () { expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('display') expect(user.videoQuota).to.equal(2 * 1024 * 1024) - expect(user.roleLabel).to.equal('User') + expect(user.role.label).to.equal('User') expect(user.id).to.be.a('number') expect(user.account.displayName).to.equal('user_1') expect(user.account.description).to.be.null @@ -277,7 +277,7 @@ describe('Test users', function () { const user = data[0] expect(user.username).to.equal('root') expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') - expect(user.roleLabel).to.equal('Administrator') + expect(user.role.label).to.equal('Administrator') expect(user.nsfwPolicy).to.equal('display') }) @@ -531,7 +531,7 @@ describe('Test users', function () { expect(user.emailVerified).to.be.true expect(user.nsfwPolicy).to.equal('do_not_list') expect(user.videoQuota).to.equal(42) - expect(user.roleLabel).to.equal('Moderator') + expect(user.role.label).to.equal('Moderator') expect(user.id).to.be.a('number') expect(user.adminFlags).to.equal(UserAdminFlag.NONE) expect(user.pluginAuth).to.equal('toto') diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index e08b83791..437777e90 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -155,7 +155,7 @@ describe('Test external auth plugins', function () { expect(body.username).to.equal('cyan') expect(body.account.displayName).to.equal('cyan') expect(body.email).to.equal('cyan@example.com') - expect(body.role).to.equal(UserRole.USER) + expect(body.role.id).to.equal(UserRole.USER) } }) @@ -177,7 +177,7 @@ describe('Test external auth plugins', function () { expect(body.username).to.equal('kefka') expect(body.account.displayName).to.equal('Kefka Palazzo') expect(body.email).to.equal('kefka@example.com') - expect(body.role).to.equal(UserRole.ADMINISTRATOR) + expect(body.role.id).to.equal(UserRole.ADMINISTRATOR) } }) @@ -237,7 +237,7 @@ describe('Test external auth plugins', function () { expect(body.username).to.equal('cyan') expect(body.account.displayName).to.equal('Cyan Garamonde') expect(body.account.description).to.equal('Retainer to the king of Doma') - expect(body.role).to.equal(UserRole.USER) + expect(body.role.id).to.equal(UserRole.USER) }) it('Should not update an external auth email', async function () { diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index 85faac5a8..fc24a5656 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -48,7 +48,7 @@ describe('Test id and pass auth plugins', function () { expect(body.username).to.equal('spyro') expect(body.account.displayName).to.equal('Spyro the Dragon') - expect(body.role).to.equal(UserRole.USER) + expect(body.role.id).to.equal(UserRole.USER) }) it('Should login Crash, create the user and use the token', async function () { @@ -63,7 +63,7 @@ describe('Test id and pass auth plugins', function () { expect(body.username).to.equal('crash') expect(body.account.displayName).to.equal('Crash Bandicoot') - expect(body.role).to.equal(UserRole.MODERATOR) + expect(body.role.id).to.equal(UserRole.MODERATOR) } }) @@ -79,7 +79,7 @@ describe('Test id and pass auth plugins', function () { expect(body.username).to.equal('laguna') expect(body.account.displayName).to.equal('laguna') - expect(body.role).to.equal(UserRole.USER) + expect(body.role.id).to.equal(UserRole.USER) } }) @@ -129,7 +129,7 @@ describe('Test id and pass auth plugins', function () { expect(body.username).to.equal('crash') expect(body.account.displayName).to.equal('Beautiful Crash') expect(body.account.description).to.equal('Mutant eastern barred bandicoot') - expect(body.role).to.equal(UserRole.MODERATOR) + expect(body.role.id).to.equal(UserRole.MODERATOR) }) it('Should reject token of laguna by the plugin hook', async function () { -- cgit v1.2.3