@things-factory/shell 6.0.0-zeta.40 → 6.0.0-zeta.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/shell",
3
- "version": "6.0.0-zeta.40",
3
+ "version": "6.0.0-zeta.43",
4
4
  "description": "Core module for framework",
5
5
  "bin": {
6
6
  "things-factory": "bin/things-factory",
@@ -131,5 +131,5 @@
131
131
  "pg": "^8.7.3",
132
132
  "sqlite3": "^5.0.8"
133
133
  },
134
- "gitHead": "8f2076b1512cc74d339c08577690a0c42fe4d3c3"
134
+ "gitHead": "f43b9c1e5447ff2d5739a057c7154e1e1adc31b0"
135
135
  }
@@ -12,7 +12,7 @@ import { DomainList, DomainPatch } from './domain-types'
12
12
 
13
13
  @Resolver(Domain)
14
14
  export class DomainResolver {
15
- @Directive('@privilege(category: "system", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)')
15
+ @Directive('@privilege(category: "system", privilege: "query", domainOwnerGranted: true, superUserGranted: true)')
16
16
  @Query(returns => Domain, { description: 'To fetch domain' })
17
17
  async domain(@Arg('id') id: string): Promise<Domain> {
18
18
  const repository = getRepository(Domain)
@@ -20,8 +20,8 @@ export class DomainResolver {
20
20
  return await repository.findOneBy({ id })
21
21
  }
22
22
 
23
- @Directive('@privilege(category: "system", privilege: "query", superUserGranted: true)')
24
- @Query(returns => DomainList, { description: 'To fetch multiple domain' })
23
+ @Directive('@privilege(superUserGranted: true)')
24
+ @Query(returns => DomainList, { description: 'To fetch all domains (Only superuser is granted this privilege.)' })
25
25
  async domains(@Args() params: ListParam, @Ctx() context: any): Promise<DomainList> {
26
26
  const queryBuilder = await getQueryBuilderFromListParams({
27
27
  repository: getRepository(Domain),
@@ -35,22 +35,22 @@ export class DomainResolver {
35
35
  return { items, total }
36
36
  }
37
37
 
38
- @Query(returns => Boolean, { description: 'To check if given domain is exist' })
39
- async checkExistsDomain(@Arg('name') name: string) {
40
- const domainRepository: Repository<Domain> = getRepository(Domain)
41
- const targetSubdomain: string = slugger(name)
38
+ // @Query(returns => Boolean, { description: 'To check if given domain is exist' })
39
+ // async checkExistsDomain(@Arg('name') name: string) {
40
+ // const domainRepository: Repository<Domain> = getRepository(Domain)
41
+ // const targetSubdomain: string = slugger(name)
42
42
 
43
- const oldDomain = await domainRepository.findOneBy({ subdomain: targetSubdomain })
44
- if (oldDomain) {
45
- throw new Error('domain is duplicated')
46
- }
43
+ // const oldDomain = await domainRepository.findOneBy({ subdomain: targetSubdomain })
44
+ // if (oldDomain) {
45
+ // throw new Error('domain is duplicated')
46
+ // }
47
47
 
48
- return true
49
- }
48
+ // return true
49
+ // }
50
50
 
51
51
  @Directive('@transaction')
52
- @Directive('@privilege(category: "system", privilege: "mutation", superUserGranted: true)')
53
- @Mutation(returns => Domain, { description: 'To create domain' })
52
+ @Directive('@privilege(superUserGranted: true)')
53
+ @Mutation(returns => Domain, { description: 'To create domain (Only superuser is granted this privilege.)' })
54
54
  async createDomain(@Arg('domainInput') domainInput: DomainPatch) {
55
55
  const { name, description } = domainInput
56
56
  const domainRepo: Repository<Domain> = getRepository(Domain)
@@ -65,15 +65,17 @@ export class DomainResolver {
65
65
  }
66
66
 
67
67
  @Directive('@transaction')
68
- @Directive('@privilege(category: "system", privilege: "mutation", superUserGranted: true)')
69
- @Mutation(returns => Domain, { description: 'To delete domain' })
68
+ @Directive('@privilege(superUserGranted: true)')
69
+ @Mutation(returns => Domain, { description: 'To delete domain (Only superuser is granted this privilege.)' })
70
70
  async deleteDomain(@Arg('name') name: string) {
71
71
  return await getRepository(Domain).delete({ name })
72
72
  }
73
73
 
74
74
  @Directive('@transaction')
75
- @Directive('@privilege(category: "system", privilege: "mutation", superUserGranted: true)')
76
- @Mutation(returns => Boolean, { description: 'To delete multiple domains' })
75
+ @Directive('@privilege(superUserGranted: true)')
76
+ @Mutation(returns => Boolean, {
77
+ description: 'To delete multiple domains (Only superuser is granted this privilege.)'
78
+ })
77
79
  async deleteDomains(@Arg('names', () => [String]) names: string[]) {
78
80
  const domains: Domain[] = await getRepository(Domain).find({ where: { name: In(names) } })
79
81
  const domainIds: string[] = domains.map(domain => domain.id)
@@ -82,25 +84,25 @@ export class DomainResolver {
82
84
  }
83
85
 
84
86
  @Directive('@transaction')
85
- @Directive('@privilege(category: "system", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)')
86
- @Mutation(returns => Domain, { description: 'To update domain' })
87
+ @Directive('@privilege(superUserGranted: true)')
88
+ @Mutation(returns => Domain, {
89
+ description: 'To update domain (Only superuser is granted this privilege.)'
90
+ })
87
91
  async updateDomain(@Arg('name') name: string, @Arg('patch', () => DomainPatch) patch: DomainPatch) {
88
92
  const repository = getRepository(Domain)
89
93
  const domain: Domain = await repository.findOneBy({ name })
90
94
 
91
- var owner = patch.ownerUser?.id
92
- delete patch.ownerUser
93
-
94
95
  return await repository.save({
95
96
  ...domain,
96
- ...patch,
97
- owner
97
+ ...patch
98
98
  } as any)
99
99
  }
100
100
 
101
101
  @Directive('@transaction')
102
- @Directive('@privilege(category: "system", privilege: "mutation", superUserGranted: true)')
103
- @Mutation(returns => Boolean, { description: 'To update multiple domains' })
102
+ @Directive('@privilege(superUserGranted: true)')
103
+ @Mutation(returns => Boolean, {
104
+ description: 'To update multiple domains (Only superuser is granted this privilege.)'
105
+ })
104
106
  async updateDomains(@Arg('patches', () => [DomainPatch]) patches: DomainPatch[]): Promise<boolean> {
105
107
  const domainRepo: Repository<Domain> = getRepository(Domain)
106
108
 
@@ -114,13 +116,9 @@ export class DomainResolver {
114
116
  updateRecord.subdomain = slugger(updateRecord.name)
115
117
  }
116
118
 
117
- var owner = updateRecord.ownerUser?.id
118
- delete updateRecord.ownerUser
119
-
120
119
  await domainRepo.save({
121
120
  ...domain,
122
- ...updateRecord,
123
- owner
121
+ ...updateRecord
124
122
  } as any)
125
123
  })
126
124
  }
@@ -42,9 +42,6 @@ export class DomainPatch {
42
42
 
43
43
  @Field({ nullable: true })
44
44
  theme?: string
45
-
46
- @Field(type => ObjectRef, { nullable: true })
47
- ownerUser?: ObjectRef
48
45
  }
49
46
 
50
47
  @ObjectType()
@@ -16,7 +16,8 @@ export class DataResolver {
16
16
  throw new Error('domain and tag required')
17
17
  }
18
18
 
19
- if (!user.domains?.find(d => d.subdomain === subdomain)) {
19
+ //@ts-ignore
20
+ if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
20
21
  throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)
21
22
  }
22
23