Skip to content

Commit

Permalink
feat(client/plugins): add getUser to helpers
Browse files Browse the repository at this point in the history
Let plugins access the user object.

closes #6355
  • Loading branch information
kontrollanten committed Apr 26, 2024
1 parent 712f7d1 commit ac7e2f8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 46 deletions.
4 changes: 4 additions & 0 deletions client/src/app/core/plugins/plugin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ export class PluginService implements ClientHook {
return firstValueFrom(obs)
},

getUser: () => {
return this.authService.getUser()
},

getServerConfig: () => {
const obs = this.server.getConfig()
.pipe(catchError(res => this.restExtractor.handleError(res)))
Expand Down
50 changes: 4 additions & 46 deletions client/src/app/core/users/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,54 +74,12 @@ export class User implements UserServerModel {
createdAt: Date

constructor (hash: Partial<UserServerModel>) {
this.id = hash.id
this.username = hash.username
this.email = hash.email
const { account, ...mergeProps }: Partial<UserServerModel> = hash

this.role = hash.role
Object.assign(this, mergeProps)

this.videoChannels = hash.videoChannels

this.videoQuota = hash.videoQuota
this.videoQuotaDaily = hash.videoQuotaDaily
this.videoQuotaUsed = hash.videoQuotaUsed
this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
this.videosCount = hash.videosCount
this.abusesCount = hash.abusesCount
this.abusesAcceptedCount = hash.abusesAcceptedCount
this.abusesCreatedCount = hash.abusesCreatedCount
this.videoCommentsCount = hash.videoCommentsCount

this.nsfwPolicy = hash.nsfwPolicy
this.p2pEnabled = hash.p2pEnabled
this.autoPlayVideo = hash.autoPlayVideo
this.autoPlayNextVideo = hash.autoPlayNextVideo
this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
this.videosHistoryEnabled = hash.videosHistoryEnabled
this.videoLanguages = hash.videoLanguages

this.theme = hash.theme

this.adminFlags = hash.adminFlags

this.blocked = hash.blocked
this.blockedReason = hash.blockedReason

this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
this.noWelcomeModal = hash.noWelcomeModal
this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal

this.notificationSettings = hash.notificationSettings

this.twoFactorEnabled = hash.twoFactorEnabled

this.createdAt = hash.createdAt

this.pluginAuth = hash.pluginAuth
this.lastLoginDate = hash.lastLoginDate

if (hash.account !== undefined) {
this.account = new Account(hash.account)
if (account !== undefined) {
this.account = new Account(account)
}
}

Expand Down
2 changes: 2 additions & 0 deletions client/src/standalone/videos/shared/peertube-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export class PeerTubePlugin {
.then((obj: PublicServerSetting) => obj.publicSettings)
},

getUser: unimplemented,

isLoggedIn: () => this.http.isLoggedIn(),
getAuthHeader: () => {
if (!this.http.isLoggedIn()) return undefined
Expand Down
3 changes: 3 additions & 0 deletions client/src/types/register-client-option.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AuthUser } from '@app/core'
import {
RegisterClientFormFieldOptions,
RegisterClientHookOptions,
Expand Down Expand Up @@ -35,6 +36,8 @@ export type RegisterClientHelpers = {

getSettings: () => Promise<SettingEntries>

getUser: () => AuthUser

getServerConfig: () => Promise<ServerConfig>

notifier: {
Expand Down

0 comments on commit ac7e2f8

Please sign in to comment.