mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch '2116-retrieve-admin-and-moderators' into 1973-List-open-contribution-links-in-the-wallet
This commit is contained in:
commit
1ce2aec998
@ -31,6 +31,7 @@ export enum RIGHTS {
|
|||||||
LIST_ALL_CONTRIBUTIONS = 'LIST_ALL_CONTRIBUTIONS',
|
LIST_ALL_CONTRIBUTIONS = 'LIST_ALL_CONTRIBUTIONS',
|
||||||
UPDATE_CONTRIBUTION = 'UPDATE_CONTRIBUTION',
|
UPDATE_CONTRIBUTION = 'UPDATE_CONTRIBUTION',
|
||||||
LIST_CONTRIBUTION_LINKS = 'LIST_CONTRIBUTION_LINKS',
|
LIST_CONTRIBUTION_LINKS = 'LIST_CONTRIBUTION_LINKS',
|
||||||
|
SEARCH_ADMIN_USERS = 'SEARCH_ADMIN_USERS',
|
||||||
// Admin
|
// Admin
|
||||||
SEARCH_USERS = 'SEARCH_USERS',
|
SEARCH_USERS = 'SEARCH_USERS',
|
||||||
SET_USER_ROLE = 'SET_USER_ROLE',
|
SET_USER_ROLE = 'SET_USER_ROLE',
|
||||||
|
|||||||
@ -28,6 +28,7 @@ export const ROLE_USER = new Role('user', [
|
|||||||
RIGHTS.LIST_CONTRIBUTIONS,
|
RIGHTS.LIST_CONTRIBUTIONS,
|
||||||
RIGHTS.LIST_ALL_CONTRIBUTIONS,
|
RIGHTS.LIST_ALL_CONTRIBUTIONS,
|
||||||
RIGHTS.UPDATE_CONTRIBUTION,
|
RIGHTS.UPDATE_CONTRIBUTION,
|
||||||
|
RIGHTS.SEARCH_ADMIN_USERS,
|
||||||
RIGHTS.LIST_CONTRIBUTION_LINKS,
|
RIGHTS.LIST_CONTRIBUTION_LINKS,
|
||||||
])
|
])
|
||||||
export const ROLE_ADMIN = new Role('admin', Object.values(RIGHTS)) // all rights
|
export const ROLE_ADMIN = new Role('admin', Object.values(RIGHTS)) // all rights
|
||||||
|
|||||||
25
backend/src/graphql/model/AdminUser.ts
Normal file
25
backend/src/graphql/model/AdminUser.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { User } from '@entity/User'
|
||||||
|
import { Field, Int, ObjectType } from 'type-graphql'
|
||||||
|
|
||||||
|
@ObjectType()
|
||||||
|
export class AdminUser {
|
||||||
|
constructor(user: User) {
|
||||||
|
this.firstName = user.firstName
|
||||||
|
this.lastName = user.lastName
|
||||||
|
}
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
firstName: string
|
||||||
|
|
||||||
|
@Field(() => String)
|
||||||
|
lastName: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@ObjectType()
|
||||||
|
export class SearchAdminUsersResult {
|
||||||
|
@Field(() => Int)
|
||||||
|
userCount: number
|
||||||
|
|
||||||
|
@Field(() => [AdminUser])
|
||||||
|
userList: AdminUser[]
|
||||||
|
}
|
||||||
@ -3,7 +3,7 @@ import { backendLogger as logger } from '@/server/logger'
|
|||||||
|
|
||||||
import { Context, getUser } from '@/server/context'
|
import { Context, getUser } from '@/server/context'
|
||||||
import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql'
|
import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql'
|
||||||
import { getConnection } from '@dbTools/typeorm'
|
import { getConnection, getCustomRepository, IsNull, Not } from '@dbTools/typeorm'
|
||||||
import CONFIG from '@/config'
|
import CONFIG from '@/config'
|
||||||
import { User } from '@model/User'
|
import { User } from '@model/User'
|
||||||
import { User as DbUser } from '@entity/User'
|
import { User as DbUser } from '@entity/User'
|
||||||
@ -32,6 +32,10 @@ import {
|
|||||||
EventSendConfirmationEmail,
|
EventSendConfirmationEmail,
|
||||||
} from '@/event/Event'
|
} from '@/event/Event'
|
||||||
import { getUserCreation } from './util/creations'
|
import { getUserCreation } from './util/creations'
|
||||||
|
import { UserRepository } from '@/typeorm/repository/User'
|
||||||
|
import { SearchAdminUsersResult } from '@model/AdminUser'
|
||||||
|
import Paginated from '@arg/Paginated'
|
||||||
|
import { Order } from '@enum/Order'
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const sodium = require('sodium-native')
|
const sodium = require('sodium-native')
|
||||||
@ -734,6 +738,46 @@ export class UserResolver {
|
|||||||
logger.debug(`has ElopageBuys = ${elopageBuys}`)
|
logger.debug(`has ElopageBuys = ${elopageBuys}`)
|
||||||
return elopageBuys
|
return elopageBuys
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Authorized([RIGHTS.SEARCH_ADMIN_USERS])
|
||||||
|
@Query(() => SearchAdminUsersResult)
|
||||||
|
async searchAdminUsers(
|
||||||
|
@Args()
|
||||||
|
{ currentPage = 1, pageSize = 25, order = Order.DESC }: Paginated,
|
||||||
|
): Promise<SearchAdminUsersResult> {
|
||||||
|
const userRepository = getCustomRepository(UserRepository)
|
||||||
|
|
||||||
|
const [users, count] = await userRepository.findAndCount({
|
||||||
|
where: {
|
||||||
|
isAdmin: Not(IsNull()),
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
createdAt: order,
|
||||||
|
},
|
||||||
|
skip: (currentPage - 1) * pageSize,
|
||||||
|
take: pageSize,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (users.length === 0) {
|
||||||
|
return {
|
||||||
|
userCount: 0,
|
||||||
|
userList: [],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const adminUsers = await Promise.all(
|
||||||
|
users.map((user) => {
|
||||||
|
return {
|
||||||
|
firstName: user.firstName,
|
||||||
|
lastName: user.lastName,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
userCount: count,
|
||||||
|
userList: adminUsers,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isTimeExpired = (optIn: LoginEmailOptIn, duration: number): boolean => {
|
const isTimeExpired = (optIn: LoginEmailOptIn, duration: number): boolean => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user