Skip to content

Commit

Permalink
Merge pull request #225 from BIDMCDigitalPsychiatry/ignore-attachment…
Browse files Browse the repository at this point in the history
…list-for-admin

#fixes ignore tags with target-* for admins in the list
  • Loading branch information
avaidyam authored Mar 8, 2023
2 parents a47525d + 0c60052 commit cdac9c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 40 deletions.
29 changes: 9 additions & 20 deletions src/repository/couch/TypeRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,20 @@ export class TypeRepository implements TypeInterface {
public async _get(mode: any, type_id: string, attachment_key: string): Promise<any | undefined> {
const repo = new Repository()
const TypeRepository = repo.getTypeRepository()
const self_type = (type_id ===null) ? undefined : await TypeRepository._self_type(type_id)
const parents = (type_id ===null) ? new Array : Object.values(await TypeRepository._parent(type_id)).reverse()


const self_type = (type_id === null) ? undefined : await TypeRepository._self_type(type_id)
const parents = (type_id === null) ? new Array : [null,...Object.values(await TypeRepository._parent(type_id)).reverse()]

// All possible conditions to retreive Tags, ordered greatest-to-least priority.
const conditions = [
// Explicit parent-ownership. (Ordered greatest-to-least ancestor.)
...parents.map((pid) => ({ "#parent": pid, type: type_id, key: attachment_key })),
// Implicit parent-ownership. (Ordered greatest-to-least ancestor.)
...parents.map((pid) => ({ "#parent": pid, type: self_type, key: attachment_key })),
...parents.map((pid) => ({ "#parent": pid, type: "*", key: attachment_key })),
// Explicit self-ownership.
{ "#parent": type_id, type: type_id, key: attachment_key },
// Implicit self-ownership.
{ "#parent": type_id, type: "me", key: attachment_key },
{ "#parent": null, type: '*', key: attachment_key },
{ "#parent": type_id, type: '*', key: attachment_key },
{ "#parent": null, type: self_type, key: attachment_key },
{ "#parent": null, type: type_id, key: attachment_key },
{ "#parent": type_id, type: "null", key: attachment_key },
{ "#parent": null, type: "null", key: attachment_key },
{ "#parent": type_id, type: "me", key: attachment_key },
]

// Following greatest-to-least priority, see if the Tag exists. We do this because:
Expand All @@ -178,26 +172,21 @@ export class TypeRepository implements TypeInterface {
public async _list(mode: any, type_id: string): Promise<string[]> {
const repo = new Repository()
const TypeRepository = repo.getTypeRepository()
const self_type = (type_id ===null) ? undefined : await TypeRepository._self_type(type_id)
const parents = (type_id ===null) ? new Array : Object.values(await TypeRepository._parent(type_id)).reverse()

const self_type = (type_id === null) ? undefined : await TypeRepository._self_type(type_id)
const parents = (type_id === null) ? new Array : [null,...Object.values(await TypeRepository._parent(type_id)).reverse()]
// All possible conditions to retreive Tags, ordered greatest-to-least priority.
// Note: We MUST add a "key" selector to force CouchDB to use the right Mango index.
const conditions = [
// Explicit parent-ownership. (Ordered greatest-to-least ancestor.)
...parents.map((pid) => ({ "#parent": pid, type: type_id, key: { $gt: null } })),
// Implicit parent-ownership. (Ordered greatest-to-least ancestor.)
...parents.map((pid) => ({ "#parent": pid, type: self_type, key: { $gt: null } })),
...parents.map((pid) => ({ "#parent": pid, type: "*", key: { $gt: null } })),
// Explicit self-ownership.
{ "#parent": type_id, type: type_id, key: { $gt: null } },
// Implicit self-ownership.
{ "#parent": type_id, type: "me", key: { $gt: null } },
{ "#parent": null, type: '*', key: { $gt: null }},
{ "#parent": type_id, type: '*', key: { $gt: null }},
{ "#parent": null, type:self_type, key: { $gt: null }},
{ "#parent": null, type:type_id, key: { $gt: null }},
{ "#parent": type_id, type:"null", key: { $gt: null }},
{ "#parent": null, type:"null", key: { $gt: null }},

]

// Following greatest-to-least priority, see if the Tag exists. We do this because:
Expand Down
29 changes: 9 additions & 20 deletions src/repository/mongo/TypeRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,21 @@ export class TypeRepository implements TypeInterface {
public async _get(mode: any, type_id: string, attachment_key: string): Promise<any | undefined> {
const repo = new Repository()
const TypeRepository = repo.getTypeRepository()
const self_type = (type_id ===null) ? undefined : await TypeRepository._self_type(type_id)
const parents = (type_id ===null) ? new Array : Object.values(await TypeRepository._parent(type_id)).reverse()
const self_type = (type_id === null) ? undefined : await TypeRepository._self_type(type_id)
const parents = (type_id === null) ? new Array : [null,...Object.values(await TypeRepository._parent(type_id)).reverse()]

// All possible conditions to retreive Tags, ordered greatest-to-least priority.
const conditions = [
// Explicit parent-ownership. (Ordered greatest-to-least ancestor.)
...parents.map((pid) => ({ _deleted: false, _parent: pid, type: type_id, key: attachment_key })),
// Implicit parent-ownership. (Ordered greatest-to-least ancestor.)
...parents.map((pid) => ({ _deleted: false, _parent: pid, type: self_type, key: attachment_key })),
...parents.map((pid) => ({ _deleted: false, _parent: pid, type: "*", key: attachment_key })),
// Explicit self-ownership.
{ _deleted: false, _parent: type_id, type: type_id, key: attachment_key },
// Implicit self-ownership.
{ _deleted: false, _parent: type_id, type: "me", key: attachment_key },
{ _deleted: false, _parent: null, type: '*', key: attachment_key },
{ _deleted: false, _parent: type_id, type: '*', key: attachment_key },
{ _deleted: false, _parent:null , type: self_type, key: attachment_key },
{ _deleted: false, _parent:null , type: type_id, key: attachment_key },
{ _deleted: false, _parent:type_id , type: "null", key: attachment_key },
{ _deleted: false, _parent:null , type: "null", key: attachment_key },
]

]
// Following greatest-to-least priority, see if the Tag exists. We do this because:
// (1) Following priority order allows us to avoid searching the database after we find the
// Tag we're looking for that applies with the greatest priority.
Expand All @@ -153,27 +148,21 @@ export class TypeRepository implements TypeInterface {
public async _list(mode: any, type_id: string): Promise<string[]> {
const repo = new Repository()
const TypeRepository = repo.getTypeRepository()
const self_type = (type_id ===null) ? undefined : await TypeRepository._self_type(type_id)
const parents = (type_id ===null) ? new Array : Object.values(await TypeRepository._parent(type_id)).reverse()
const self_type = (type_id === null) ? undefined : await TypeRepository._self_type(type_id)
const parents = (type_id === null) ? new Array : [null,...Object.values(await TypeRepository._parent(type_id)).reverse()]
let conditions: any[] = []
conditions = [
// Explicit parent-ownership. (Ordered greatest-to-least ancestor.)

...parents.map((pid) => ({ _deleted: false, _parent: pid, type: type_id, key: { $ne: null } })),
// Implicit parent-ownership. (Ordered greatest-to-least ancestor.)
...parents.map((pid) => ({ _deleted: false, _parent: pid, type: self_type, key: { $ne: null } })),
...parents.map((pid) => ({ _deleted: false, _parent: pid, type: "*", key: { $ne: null } })),
// Explicit self-ownership.
{ _deleted: false, _parent: type_id, type: type_id, key: { $ne: null } },
// Implicit self-ownership.
{ _deleted: false, _parent: type_id, type: "me", key: { $ne: null } },
{ _deleted: false, _parent: null, type: '*', key: { $ne: null }},
{ _deleted: false, _parent: type_id, type: '*', key: { $ne: null }},
{ _deleted: false, _parent: null, type: self_type, key: { $ne: null }},
{ _deleted: false, _parent: null, type: type_id, key: { $ne: null }},
{ _deleted: false, _parent: type_id, type: "null", key: { $ne: null }},
{ _deleted: false, _parent: null, type: "null", key: { $ne: null }},
]

// Following greatest-to-least priority, see if the Tag exists. We do this because:
// (1) Following priority order allows us to avoid searching the database after we find the
// Tag we're looking for that applies with the greatest priority.
Expand Down

0 comments on commit cdac9c8

Please sign in to comment.