JILS-12: Project Filtering (client requests)



Issue Information

Issue Type: New Feature
 
Priority: Major
Status: Closed

Reported By:
Ben Tasker
Assigned To:
Ben Tasker
Project: Jira Issue Listing Script (JILS)
Resolution: Done (2016-04-29 15:00:58)
Affects Version: 0.01b,
Target version: 0.01b,

Created: 2014-11-03 12:20:14
Time Spent Working


Description
A very, very basic version of this was implemented on the homepage in commit eeb3c63 (View Commit)

The aim is to use the script to populate some static HTML pages on project.bentasker.co.uk, but only certain projects should be eligible for display.

The commit above introduce the concept of a comma-seperated header allowing filtering by project key, this needs to be expanded so that the filter is taken into account on every page (the script needs to return a 404 if the filter prevents an issue/version from being displayed)

The header used is

X-PROJECT-LIMIT: JILS,GPXIN


Issue Links

Toggle State Changes

Activity


Marking as blocking JILS-11 as cannot configure the export pull into projects.bentasker.co.uk until this functionality is implemented.
The codeblock committed in the earlier commit is

	$sql = "SELECT ID, pname, pkey, DESCRIPTION from project ";

	// This will be moved somewhere more suitable (and global) in future
	if (isset($_SERVER['HTTP_X_PROJECT_LIMIT']) && !empty($_SERVER['HTTP_X_PROJECT_LIMIT'])){

		$sql .= "WHERE pkey IN (";
		$keys = explode(",",$_SERVER['HTTP_X_PROJECT_LIMIT']);
		foreach ($keys as $k){
		      $sql .= "'".$db->stringEscape($k)."',";
		}

		$sql .= "'') ";

	}
	$sql .= 'ORDER BY pkey ASC';

	$db->setQuery($sql);
	$projects = $db->loadResults();


The best way forward is probably to add a function to utils.class which checks for the header and builds the filter if needed.
The filter is now called within projects.php by doing the following

	$filter = buildProjectFilter(); // See JILS-12
	if ($filter){
	    $sql .= "WHERE ".$filter;
	}


The function buildProjectFilter() returns false if there is no filter to build, and it's down to the calling entity whether the generated SQL needs to be prefixed with WHERE or AND

Repo: Jira-Issue-Listing
Commit: eb083892f11cef1ccd724b9f470533462f2b9a55
Author: Ben Tasker <github@<Domain Hidden>>

Date: Mon Nov 03 12:29:32 2014 +0000
Commit Message: Changed project filtering into a utility function. See JILS-12



Modified
-------
projects.php
utils.class.php


Webhook User-Agent

GitHub-Hookshot/fae58c8


View Commit


Repo: Jira-Issue-Listing
Commit: d726e05ffb9ebaf95685d25011d5d2ee89eca8eb
Author: Ben Tasker <github@<Domain Hidden>>

Date: Mon Nov 03 12:35:50 2014 +0000
Commit Message: Added ability to pass table name alias for filter. See JILS-12



Modified
-------
utils.class.php


Webhook User-Agent

GitHub-Hookshot/fae58c8


View Commit


Repo: Jira-Issue-Listing
Commit: 40bddee1e96b0563ecb1f53e919e7da24b44fa6b
Author: Ben Tasker <github@<Domain Hidden>>

Date: Mon Nov 03 12:36:09 2014 +0000
Commit Message: Added filter to issue_page. See JILS-12



Modified
-------
issue_page.php


Webhook User-Agent

GitHub-Hookshot/fae58c8


View Commit

With some minor adjustments to buildProjectFilter() (namely that a tablename alias can now be passed as the first argument) have added the filter to the issue page.

GET http://jiralist.bentasker.co.uk/browse/JILS-12.html -H "X-PROJECT-LIMIT: VEH,VPS"
ISSUE NOT FOUND
The entire codebase should now honour the client specified filters, though will need to run a mirror to see whether it's actually honoured across the board (would assume wget will include the header for each request, but needs testing)

Repo: Jira-Issue-Listing
Commit: 24dc7626335898bd1b3bee8cd621993a862abdf7
Author: Ben Tasker <github@<Domain Hidden>>

Date: Mon Nov 03 12:53:03 2014 +0000
Commit Message: Rolled out honouring of client-specified filter header. See JILS-12



Modified
-------
attachment.php
component-issues.php
project-index.php
utils.class.php
version-issues.php


Webhook User-Agent

GitHub-Hookshot/fae58c8


View Commit

Ran a test with a modified version of the script already in the Repo

#!/bin/bash
#
# Generate an offline copy of JIRA project
#
# Copyright (C) 2014 B Tasker

JIRALIST="http://jiralst.example.com" # Set your JIRA url here
DATEFORMAT=`date +'%Y-%m-%d-%H-%M'`
PROJECTKEYS='VEH,GPXIN'

wget --header="X-PROJECT-LIMIT: $PROJECTKEYS" -A "$PROJECT*" -R "robots.txt" -U "Jira-Project-Archive" -r -p -k "$JIRALIST/"


It correctly retrieves only issues for the specified project. However, where links to issues in other projects exist, the link continues to point at the jiralist source, so may need to think of and create an amendment to prevent that
It's a bit brute-forcey (grepping all the files), but the following seems to work as a client script

#!/bin/bash
#
# Generate an offline copy of JIRA project, filtered by keys
#
# Copyright (C) 2014 B Tasker

JIRALIST="" # Set your JIRA url here
DATEFORMAT=`date +'%Y-%m-%d-%H-%M'` 
PROJECTKEYS='VEH,GPXIN'


sedsafe=$(echo -n $JIRALIST | sed 's/\//\\\//g')
wget --header="X-PROJECT-LIMIT: $PROJECTKEYS" -A "$PROJECT*" -R "robots.txt" -U "Jira-Project-Archive" -r -p -k "$JIRALIST/"
find . -type f -print0 | xargs -0 sed -i "s/$sedsafe//g"

Repo: Jira-Issue-Listing
Commit: 15a68cce14d6cceeed85ebf03340f75d1a333ea7
Author: Ben Tasker <github@<Domain Hidden>>

Date: Mon Nov 03 13:21:44 2014 +0000
Commit Message: Added example script for archiving specific projects. See JILS-12



Added
-------
scripts/archive_filtered_projects.sh


Webhook User-Agent

GitHub-Hookshot/fae58c8


View Commit

Filtering seems to be working correctly. Closing
btasker changed status from 'Open' to 'Resolved'
btasker added 'Done' to resolution
btasker changed status from 'Resolved' to 'Closed'
Re-opening to assign to a version
btasker removed 'Done' from resolution
btasker changed status from 'Closed' to 'Reopened'
Assigning to v0.01b
btasker added '0.01b' to Version
btasker added '0.01b' to Fix Version
Re-Closing
btasker changed status from 'Reopened' to 'Resolved'
btasker added 'Done' to resolution
btasker changed status from 'Resolved' to 'Closed'