Skip to content

Commit

Permalink
Merge pull request #1355 from civicrm/staging
Browse files Browse the repository at this point in the history
Sync master with staging
  • Loading branch information
davialexandre authored Jan 16, 2017
2 parents 44478dd + b9ca3dc commit 0bd65af
Show file tree
Hide file tree
Showing 290 changed files with 6,274 additions and 2,546 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

[*.csv]
insert_final_newline = false
23 changes: 6 additions & 17 deletions bin/drush-install.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/bash

## About: Install the CiviHR extensions using drush
## Usage: install.sh [--with-sample-data] [drush-options]
## Example: ./drush-install.sh --with-sample-data
## Example: ./drush-install.sh --root=/var/www/drupal -l newdomain.ex
## Example: ./drush-install.sh --with-sample-data --root=/var/www/drupal -l newdomain.ex

##################################
## List of CiviHR core extensions
Expand Down Expand Up @@ -72,27 +68,20 @@ function set_resource_urls() {
##################################
## Main

# Get CiviCRm Path and shift to the next option
# Get CiviCRM Path and shift to the next option
CIVI_PATH=$1
shift

if [ "$1" == "--with-sample-data" ]; then
WITHSAMPLE=1
shift
else
WITHSAMPLE=
fi

set -ex
drush "$@" cvapi extension.install keys=$CORE_EXTS,$ENTITY_EXTS,$APP_EXTS
set +ex

if [ -n "$WITHSAMPLE" ]; then
set_default_localisation_settings ${CIVI_PATH}
set_resource_urls

if [ "$WITH_HR_SAMPLE" == "1" ]; then
set -ex
drush "$@" cvapi extension.install keys=org.civicrm.hrsampledata
drush "$@" cvapi extension.install keys=uk.co.compucorp.civicrm.hrsampledata
set +ex
fi

set_default_localisation_settings ${CIVI_PATH}
set_resource_urls

4 changes: 2 additions & 2 deletions bin/git-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ hrdemog \
hrident \
hrim \
hrmed \
hrprofile
hrprofile \
hrqual \
hrrecruitment \
hrreport \
hrsampledata \
uk.co.compucorp.civicrm.hrsampledata \
hrstaffdir \
hrui \
hrvisa \
Expand Down
14 changes: 7 additions & 7 deletions com.civicrm.hrjobroles/CRM/Hrjobroles/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private function getCostCentreOptions() {
*/
private function getLocationOptions() {
if(empty($this->locationOptions)) {
$this->locationOptions = $this->getOptionsWithIDAsKeyFor('CRM_Hrjobroles_DAO_HrJobRoles', 'location');
$this->locationOptions = $this->getOptionsWithValueAsKeyFor('CRM_Hrjobroles_DAO_HrJobRoles', 'location');
}

return $this->locationOptions;
Expand All @@ -306,7 +306,7 @@ private function getLocationOptions() {
*/
private function getRegionOptions() {
if(empty($this->regionOptions)) {
$this->regionOptions = $this->getOptionsWithIDAsKeyFor('CRM_Hrjobroles_DAO_HrJobRoles', 'region');
$this->regionOptions = $this->getOptionsWithValueAsKeyFor('CRM_Hrjobroles_DAO_HrJobRoles', 'region');
}

return $this->regionOptions;
Expand All @@ -317,7 +317,7 @@ private function getRegionOptions() {
*/
private function getDepartmentOptions() {
if(empty($this->departmentOptions)) {
$this->departmentOptions = $this->getOptionsWithIDAsKeyFor('CRM_Hrjobroles_DAO_HrJobRoles', 'department');
$this->departmentOptions = $this->getOptionsWithValueAsKeyFor('CRM_Hrjobroles_DAO_HrJobRoles', 'department');
}

return $this->departmentOptions;
Expand All @@ -328,14 +328,14 @@ private function getDepartmentOptions() {
*/
private function getLevelTypeOptions() {
if(empty($this->levelTypeOptions)) {
$this->levelTypeOptions = $this->getOptionsWithIDAsKeyFor('CRM_Hrjobroles_DAO_HrJobRoles', 'level_type');
$this->levelTypeOptions = $this->getOptionsWithValueAsKeyFor('CRM_Hrjobroles_DAO_HrJobRoles', 'level_type');
}

return $this->levelTypeOptions;
}

private function getOptionsWithIDAsKeyFor($daoName, $field) {
return CRM_Core_PseudoConstant::get($daoName, $field, array('keyColumn' => 'id'));
private function getOptionsWithValueAsKeyFor($daoName, $field) {
return CRM_Core_PseudoConstant::get($daoName, $field, array('keyColumn' => 'value'));
}

private function buildMultiValueClause(&$query, $value, $options, $fieldTitle, $grouping, $whereField) {
Expand All @@ -349,7 +349,7 @@ private function buildMultiValueClause(&$query, $value, $options, $fieldTitle, $
}
$op = 'IN';
$query->_qill[$grouping][] = "Job Role $fieldTitle IN " . implode(' or ', $qillValues);
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($whereField, $op, $value, "Integer");
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($whereField, $op, $value, "String");
$query->_tables['civicrm_hrjobroles'] = $query->_whereTables['civicrm_hrjobroles'] = 1;
}

Expand Down
4 changes: 2 additions & 2 deletions com.civicrm.hrjobroles/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<author>gregmeszaros</author>
<email>[email protected]</email>
</maintainer>
<releaseDate>2016-12-02</releaseDate>
<version>1.6.4</version>
<releaseDate>2017-01-16</releaseDate>
<version>1.6.5</version>
<develStage>alpha</develStage>
<compatibility>
<ver>4.7</ver>
Expand Down
5 changes: 3 additions & 2 deletions contactaccessrights/CRM/Contactaccessrights/BAO/Rights.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CRM_Contactaccessrights_BAO_Rights extends CRM_Contactaccessrights_DAO_Rig
* @return CRM_Contactaccessrights_DAO_Rights|NULL
*
*/
public function create($params) {
public static function create($params) {
$entityName = 'Rights';
$hook = empty($params['id']) ? 'create' : 'edit';

Expand Down Expand Up @@ -46,7 +46,8 @@ public function getRightsByType(CRM_Contactaccessrights_Utils_RightType_RightTyp
rights.contact_id contact_id,
rights.entity_type entity_type,
rights.entity_id entity_id,
ov.label label
ov.label label,
ov.value value
FROM civicrm_contactaccessrights_rights rights
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* Fabricates rights for tests.
*/
class CRM_Contactaccessrights_Test_Fabricator_Rights {

/**
* Fabricates Rights, given specific values for contact_id, entity_id and
* entity_type.
*
* @param array $params
* Associative array of parameters to be used to store rights information in
* database.
* @return array
* Holds values stored in database for created access right
*/
public static function fabricate($params) {
$result = civicrm_api3('Rights', 'create', [
'sequential' => 1,
'contact_id' => $params['contact_id'],
'entity_id' => $params['entity_id'],
'entity_type' => $params['entity_type']
]);

return array_shift($result['values']);
}

}
4 changes: 2 additions & 2 deletions contactaccessrights/CRM/Contactaccessrights/Utils/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ private function addJobContractDetailsClause() {
* @throws \CRM_Extension_Exception
*/
private function addJobRolesClause() {
$locationIds = implode(', ', array_column($this->getLocations(), 'entity_id') ?: [0]);
$regionIds = implode(', ', array_column($this->getRegions(), 'entity_id') ?: [0]);
$locationIds = "'" . implode("', '", array_column($this->getLocations(), 'value') ?: [0]) . "'";
$regionIds = "'" . implode("', '", array_column($this->getRegions(), 'value') ?: [0]) . "'";

$this->addWhereTable(
'car_3_jr',
Expand Down
4 changes: 2 additions & 2 deletions contactaccessrights/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<author>Robin Mitra</author>
<email>[email protected]</email>
</maintainer>
<releaseDate>2016-12-02</releaseDate>
<version>1.6.4</version>
<releaseDate>2017-01-16</releaseDate>
<version>1.6.5</version>
<develStage>alpha</develStage>
<compatibility>
<ver>4.7</ver>
Expand Down
18 changes: 18 additions & 0 deletions contactaccessrights/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<phpunit backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="false" bootstrap="tests/phpunit/bootstrap.php">
<testsuites>
<testsuite name="My Test Suite">
<directory>./tests/phpunit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./</directory>
</whitelist>
</filter>
<listeners>
<listener class="Civi\Test\CiviTestListener">
<arguments/>
</listener>
</listeners>
</phpunit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

use Civi\Test\HeadlessInterface;
use Civi\Test\TransactionalInterface;
use CRM_HRCore_Test_Fabricator_Contact as ContactFabricator;
use CRM_HRCore_Test_Fabricator_OptionValue as OptionValueFabricator;
use CRM_Contactaccessrights_Test_Fabricator_Rights as RightsFabricator;

/**
* Class CRM_Contactaccessrights_BAO_RightsTest
* Tests Rights BAO class for contact's access rights to civicrm.
*
* @group headless
*/
class CRM_Contactaccessrights_Utils_ACLTest extends PHPUnit_Framework_TestCase implements
HeadlessInterface, TransactionalInterface {

/**
* Installs extensions required for test
*
* @return \Civi\Test\CiviEnvBuilder
*/
public function setUpHeadless() {
return \Civi\Test::headless()
->install('uk.co.compucorp.civicrm.hrcore')
->install('org.civicrm.hrjobcontract')
->installMe(__DIR__)
->apply();
}

/**
* Tests if ACL Utility class is building the Job Roles Clause appropriately,
* using option_value.value for Locations and Regions in the table join.
*/
public function testJobRolesClauseWhereACL() {
// Setup local admin
$localAdmin = ContactFabricator::fabricate();

// Create Regions and Locations
$region1 = $this->createOptionValue('hrjc_region', 'Region 1');
$region2 = $this->createOptionValue('hrjc_region', 'Region 2');
$location1 = $this->createOptionValue('hrjc_location', 'Location 1');
$location2 = $this->createOptionValue('hrjc_location', 'Location 2');

// Add Regions / Locations to localAdmin's Rights
$this->setContactRights($localAdmin, $region1);
$this->setContactRights($localAdmin, $location1);
$this->setContactRights($localAdmin, $location2);

// Get Job Roles Clause
$aclUtil = new CRM_Contactaccessrights_Utils_ACL($localAdmin['id']);
$whereTables = $aclUtil->getWhereTables();
$jobsClause = $whereTables['car_3_jr'];

// Check Locations Clause
$locationMatches = [];
preg_match("/car_jr.location IN \(('[^']*'(, ?'[^']*')*)\)/", $jobsClause, $locationMatches);
$this->assertTrue(isset($locationMatches[1]), 'Jobs clause does not have expected format for locations.');

$locations = array_map('trim', explode(',', $locationMatches[1]));
$this->assertContains("'{$location1['value']}'", $locations, 'Expected value in clause for locations is not found.');
$this->assertContains("'{$location2['value']}'", $locations, 'Expected value in clause for locations is not found.');

// Check Regions Clause
$regionMatches = [];
preg_match("/car_jr.region IN \(('[^']*'(, ?'[^']*')*)\)/", $jobsClause, $regionMatches);
$this->assertTrue(isset($regionMatches[1]), 'Jobs clause does not have expected format for Regions.');

$regions = array_map('trim', explode(',', $regionMatches[1]));
$this->assertContains("'{$region1['value']}'", $regions);
$this->assertNotContains("'{$region2['value']}'", $regions);
}

/**
* Creates a new record for Rights entity for the given contact.
*
* @param array $contact
* Associative array with details for the contact
* @param array $entity
* Details of either Region or Location for which the contact will be
* granted access
* @return array
* Details of access right created in an associative array
*/
private function setContactRights($contact, $entity) {
return RightsFabricator::fabricate([
'contact_id' => $contact['id'],
'entity_id' => $entity['id'],
'entity_type' => $entity['entity_type']
]);
}

/**
* Creates a Record in Option Value for given Option Group
*
* @param string $optionGroup
* Name of the option group to which the option will be added
* @param string $value
* Value for the new option value, used as its name, label and value
* @return array
* Details of added option value + entity_type attribute
*/
private function createOptionValue($optionGroup, $value) {
$params = [
'option_group_id' => $optionGroup,
'name' => $value,
'label' => $value,
'value' => $value
];
$result = OptionValueFabricator::fabricate($params);
$result['entity_type'] = $optionGroup;

return $result;
}

}
49 changes: 49 additions & 0 deletions contactaccessrights/tests/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

ini_set('memory_limit', '2G');
ini_set('safe_mode', 0);
eval(cv('php:boot --level=classloader', 'phpcode'));

/**
* Call the "cv" command.
*
* @param string $cmd
* The rest of the command to send.
* @param string $decode
* Ex: 'json' or 'phpcode'.
* @return string
* Response output (if the command executed normally).
* @throws \RuntimeException
* If the command terminates abnormally.
*/
function cv($cmd, $decode = 'json') {
$cmd = 'cv ' . $cmd;
$descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => STDERR);
$oldOutput = getenv('CV_OUTPUT');
putenv("CV_OUTPUT=json");
$process = proc_open($cmd, $descriptorSpec, $pipes, __DIR__);
putenv("CV_OUTPUT=$oldOutput");
fclose($pipes[0]);
$result = stream_get_contents($pipes[1]);
fclose($pipes[1]);
if (proc_close($process) !== 0) {
throw new RuntimeException("Command failed ($cmd):\n$result");
}
switch ($decode) {
case 'raw':
return $result;

case 'phpcode':
// If the last output is /*PHPCODE*/, then we managed to complete execution.
if (substr(trim($result), 0, 12) !== "/*BEGINPHP*/" || substr(trim($result), -10) !== "/*ENDPHP*/") {
throw new \RuntimeException("Command failed ($cmd):\n$result");
}
return $result;

case 'json':
return json_decode($result, 1);

default:
throw new RuntimeException("Bad decoder format ($decode)");
}
}
4 changes: 2 additions & 2 deletions contactsummary/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<author>Robin Mitra</author>
<email>[email protected]</email>
</maintainer>
<releaseDate>2016-12-02</releaseDate>
<version>1.6.4</version>
<releaseDate>2017-01-16</releaseDate>
<version>1.6.5</version>
<develStage>alpha</develStage>
<compatibility>
<ver>4.7</ver>
Expand Down
Loading

0 comments on commit 0bd65af

Please sign in to comment.