Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIMS-1821: Fixing agency filtering on properties and projects #2488

Merged
merged 34 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6eac130
initial commit
LawrenceLau2020 Jun 27, 2024
a8a7a69
prevent rendering errors with fallbacks
dbarkowsky Jun 28, 2024
a70d5b8
restrict property union by allowed agency id
dbarkowsky Jun 28, 2024
7407906
fix undefined classification error
dbarkowsky Jun 28, 2024
42fd24a
agency filter work as AND, not OR
dbarkowsky Jun 28, 2024
46a21a4
stop extra ltsa calls
dbarkowsky Jun 28, 2024
1820c67
navigate off of property page if no permissions
dbarkowsky Jun 28, 2024
7a91f7c
redo check with querybuilder
dbarkowsky Jul 2, 2024
b24a479
User Detail bug fix
dbarkowsky Jul 2, 2024
7090b63
Merge branch 'main' into PIMS-1822/25-Property-Details-Errors
dbarkowsky Jul 2, 2024
fc44005
comments
dbarkowsky Jul 2, 2024
e9e7179
Merge branch 'PIMS-1822/25-Property-Details-Errors' of https://github…
dbarkowsky Jul 2, 2024
afdcabb
update tests
dbarkowsky Jul 2, 2024
fe6389d
Merge branch 'main' into PIMS-1821
dbarkowsky Jul 2, 2024
82e9db3
Merge branch 'PIMS-1822/25-Property-Details-Errors' into PIMS-1821
dbarkowsky Jul 2, 2024
bbfbabe
tidy up after merge
dbarkowsky Jul 2, 2024
55c4ae0
Merge branch 'PIMS-1821' of https://github.com/bcgov/PIMS into PIMS-1821
dbarkowsky Jul 2, 2024
3a14061
some progress with sorting
dbarkowsky Jul 3, 2024
18fa93c
Added a projects join view to make using the query builder a whole lo…
GrahamS-Quartech Jul 3, 2024
be908cf
Frontend value getters reflect view format, fixed broken status find …
GrahamS-Quartech Jul 3, 2024
37c852d
View will no longer return deleted rows
GrahamS-Quartech Jul 3, 2024
fd6c08f
Working properties backend column/quickfilter filter
dbarkowsky Jul 4, 2024
de89e89
trying to diagnose filter reset
dbarkowsky Jul 4, 2024
cfd8847
Made the logic for quick filter and column filter updates happen in t…
GrahamS-Quartech Jul 4, 2024
2b67279
Merge branch 'main' into PIMS-1821
GrahamS-Quartech Jul 5, 2024
fb79ca6
missed merge markers
GrahamS-Quartech Jul 5, 2024
161c70a
Fixed get project unit test
GrahamS-Quartech Jul 5, 2024
8cec72a
Merge branch 'main' into PIMS-1821
GrahamS-Quartech Jul 5, 2024
fb75383
Another minor unit test fix
GrahamS-Quartech Jul 5, 2024
69becdd
Merge branch 'PIMS-1821' of github.com:bcgov/PIMS into PIMS-1821
GrahamS-Quartech Jul 5, 2024
8198c76
Merge branch 'main' into PIMS-1821
TaylorFries Jul 5, 2024
cb8c706
lint and test fix
GrahamS-Quartech Jul 5, 2024
47e5514
Merge branch 'PIMS-1821' of github.com:bcgov/PIMS into PIMS-1821
GrahamS-Quartech Jul 5, 2024
91c2e17
Merge branch 'main' into PIMS-1821
GrahamS-Quartech Jul 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions express-api/src/controllers/properties/propertiesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,18 @@ export const getPropertiesForMap = async (req: Request, res: Response) => {
};

export const getPropertyUnion = async (req: Request, res: Response) => {
const kcUser = req.user;
const filter = PropertyUnionFilterSchema.safeParse(req.query);
if (!(isAdmin(kcUser) || isAuditor(kcUser))) {
const requestedAgencies = filter.data.agencyId;
const userHasAgencies = await checkUserAgencyPermission(kcUser, requestedAgencies);
// If not agencies were requested or if the user doesn't have those requested agencies
if (!requestedAgencies || !userHasAgencies) {
// Then only show that user's agencies instead.
const usersAgencies = await userServices.getAgencies(kcUser.preferred_username);
filter.data.agencyId = usersAgencies;
}
}
if (filter.success == false) {
return res.status(400).send(filter.error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const PropertyUnionFilterSchema = z.object({
status: z.string().optional(),
classification: z.string().optional(),
agency: z.string().optional(),
agencyId: z.array(z.number()).optional(),
propertyType: z.string().optional(),
address: z.string().optional(),
administrativeArea: z.string().optional(),
Expand Down
5 changes: 5 additions & 0 deletions express-api/src/services/properties/propertiesServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ const collectFindOptions = (filter: PropertyUnionFilter) => {
options.push(constructFindOptionFromQuery('AdministrativeArea', filter.administrativeArea));
if (filter.propertyType)
options.push(constructFindOptionFromQuery('PropertyType', filter.propertyType));
if (filter.agencyId && filter.agencyId.length > 0) {
filter.agencyId.forEach((id) => {
options.push(constructFindOptionFromQuery('AgencyId', `in,${String(id)}`));
});
}
dbarkowsky marked this conversation as resolved.
Show resolved Hide resolved
return options;
};

Expand Down
5 changes: 4 additions & 1 deletion express-api/src/utilities/helperFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Equal, FindOptionsWhere, IsNull, Not, Raw } from 'typeorm';
import { Equal, FindOptionsWhere, In, IsNull, Not, Raw } from 'typeorm';

/**
* Special case for PID/PIN matching, as general text comparison is not sufficient.
Expand Down Expand Up @@ -69,6 +69,9 @@ export const constructFindOptionFromQuery = <T>(
case 'is':
internalMatcher = (str: string) => TimestampComparisonWrapper(str, '=');
break;
case 'in':
// Assuming value is an array of numbers
return { [column]: In(value.split(',').map(Number)) } as FindOptionsWhere<T>;
case 'not':
internalMatcher = (str: string) => TimestampComparisonWrapper(str, '!=');
break;
Expand Down
Loading