Skip to content
Permalink
Browse files

Issue: Organization Update

This commit fixes discrepencies we had with organization updates for the audit plugin and organization updates from a User.

It also ensures that we log the following Organization edits:
- Update Primary Contacts list
  • Loading branch information...
aydreeihn committed Nov 18, 2019
1 parent fe140f4 commit 7b6bd90237ad91b3805b4c5f286a9640a95f6aaf
Showing with 40 additions and 19 deletions.
  1. +40 −19 include/class.organization.php
@@ -347,7 +347,7 @@ function getVar($tag) {
return $this->getAccountManager();
case 'contacts':
return new UserList($this->users->filter(array(
'flags__hasbit' => User::PRIMARY_ORG_CONTACT
'status' => User::PRIMARY_ORG_CONTACT
)));
}
}
@@ -383,22 +383,7 @@ static function supportsCustomData() {
return true;
}
function update($vars, &$errors) {
$valid = true;
$forms = $this->getForms($vars);
foreach ($forms as $entry) {
if (!$entry->isValid())
$valid = false;
if ($entry->getDynamicForm()->get('type') == 'O'
&& ($f = $entry->getField('name'))
&& $f->getClean()
&& ($o=Organization::lookup(array('name'=>$f->getClean())))
&& $o->id != $this->getId()) {
$valid = false;
$f->addError(__('Organization with the same name already exists'));
}
}
function updateProfile($vars, &$errors) {
if ($vars['domain']) {
foreach (explode(',', $vars['domain']) as $d) {
if (!Validator::is_email('t@' . trim($d))) {
@@ -428,6 +413,28 @@ function update($vars, &$errors) {
if ($errors)
return false;
return $this->save();
}
function update($vars, &$errors) {
$valid = true;
$forms = $this->getForms($vars);
foreach ($forms as $entry) {
if (!$entry->isValid())
$valid = false;
if ($entry->getDynamicForm()->get('type') == 'O'
&& ($f = $entry->getField('name'))
&& $f->getClean()
&& ($o=Organization::lookup(array('name'=>$f->getClean())))
&& $o->id != $this->getId()) {
$valid = false;
$f->addError(__('Organization with the same name already exists'));
}
}
if (!$valid || $errors)
return false;
// Save dynamic data.
foreach ($this->getDynamicData() as $entry) {
$fields = $entry->getFields();
foreach ($fields as $field) {
@@ -468,6 +475,20 @@ function update($vars, &$errors) {
}
foreach ($vars as $key => $value) {
// Primary Contacts List Changes
if ($key == 'contacts') {
$ogContacts = $value;
if ($contacts = $this->getVar('contacts')) {
$allContacts = array();
foreach ($contacts as $key => $value)
$allContacts[] = strval($value->getId());
if ($ogContacts != $allContacts) {
$type = array('type' => 'edited', 'key' => 'contacts');
Signal::send('object.edited', $this, $type);
}
}
}
if ($key != 'id' && $this->get($key) && $value != $this->get($key)) {
$type = array('type' => 'edited', 'key' => $key);
Signal::send('object.edited', $this, $type);
@@ -495,7 +516,7 @@ function update($vars, &$errors) {
'sharing-primary' => Organization::SHARE_PRIMARY_CONTACT,
'sharing-all' => Organization::SHARE_EVERYBODY,
) as $ck=>$flag) {
if (($sharingPrimary || $sharingEverybody) && $key == $ck) {
if (($sharingPrimary || $sharingEverybody) && $vars['sharing'] == $ck) {
$type = array('type' => 'edited', 'key' => 'sharing');
Signal::send('object.edited', $this, $type);
}
@@ -521,7 +542,7 @@ function update($vars, &$errors) {
));
}
return $this->save();
return true;
}
function delete() {

0 comments on commit 7b6bd90

Please sign in to comment.
You can’t perform that action at this time.