Merge branch 'master' of github.com:chamilo/chamilo-lms

pull/4020/head^2
Julio 3 years ago
commit f3d2cc2cf4
  1. 37
      public/main/inc/lib/TicketManager.php
  2. 6
      public/main/install/configuration.dist.php
  3. 2
      public/main/ticket/ticket_details.php
  4. 17
      src/CoreBundle/Migrations/Schema/V200/Version20170627122900.php
  5. 5
      src/CoreBundle/Settings/TicketSettingsSchema.php

@ -2445,20 +2445,33 @@ class TicketManager
return false; return false;
} }
/** public static function getAllowedRolesFromProject(int $projectId): array
* @param int $projectId
*
* @todo load from database instead of configuration.php setting
*
* @return array
*/
public static function getAllowedRolesFromProject($projectId)
{ {
$options = api_get_configuration_value('ticket_project_user_roles'); if ('' === $options = Container::getSettingsManager()->getSetting('ticket.ticket_project_user_roles')) {
if ($options) { return [];
if (isset($options['permissions'][$projectId])) { }
return $options['permissions'][$projectId];
if ([] === $permissionsLines = explode(PHP_EOL, $options)) {
return [];
}
foreach ($permissionsLines as $permissionsLine) {
[$id, $rolesLine] = explode(':', $permissionsLine, 2);
if (empty($rolesLine)) {
continue;
}
$roles = explode(',', $rolesLine);
if ($projectId !== (int) $id) {
continue;
} }
return array_map(
fn($role) => (int) $role,
$roles
);
} }
return []; return [];

@ -386,12 +386,6 @@ $_configuration['send_all_emails_to'] = [
'admin2@example.com', 'admin2@example.com',
] ]
];*/ ];*/
// Allow ticket projects to be access by specific chamilo roles
/*$_configuration['ticket_project_user_roles'] = [
'permissions' => [
1 => [17] // project_id = 1, STUDENT_BOSS = 17
]
];*/
// Allow additional data (exercise and learningpath) in the ticket // Allow additional data (exercise and learningpath) in the ticket
// - Required DB change // - Required DB change
// ALTER TABLE ticket_ticket ADD exercise_id INT DEFAULT NULL AFTER course_id; // ALTER TABLE ticket_ticket ADD exercise_id INT DEFAULT NULL AFTER course_id;

@ -130,7 +130,7 @@ $ticket = TicketManager::get_ticket_detail_by_id($ticket_id);
if (empty($ticket)) { if (empty($ticket)) {
api_not_allowed(true); api_not_allowed(true);
} }
$projectId = $ticket['ticket']['project_id']; $projectId = (int) $ticket['ticket']['project_id'];
$userIsAllowInProject = TicketManager::userIsAllowInProject($userInfo, $projectId); $userIsAllowInProject = TicketManager::userIsAllowInProject($userInfo, $projectId);
$allowEdition = $ticket['ticket']['assigned_last_user'] == $user_id $allowEdition = $ticket['ticket']['assigned_last_user'] == $user_id
|| $ticket['ticket']['sys_insert_user_id'] || $ticket['ticket']['sys_insert_user_id']

@ -330,6 +330,23 @@ class Version20170627122900 extends AbstractMigrationChamilo
} }
$this->addSql('UPDATE settings_current SET category = LOWER(category)'); $this->addSql('UPDATE settings_current SET category = LOWER(category)');
// ticket configuration
$ticketProjectUserRoles = $this->getConfigurationValue('ticket_project_user_roles');
if ($ticketProjectUserRoles && isset($ticketProjectUserRoles['permissions'])) {
$selectedValue = array_map(
fn($projectId, $roles) => "$projectId:".implode(',', $roles),
array_keys($ticketProjectUserRoles['permissions']),
array_values($ticketProjectUserRoles['permissions'])
);
$selectedValue = implode(PHP_EOL, $selectedValue);
$this->addSql(
"INSERT INTO settings_current (access_url, variable, category, selected_value, title, access_url_changeable, access_url_locked) VALUES (1, 'ticket_project_user_roles', 'Ticket', '$selectedValue', 'ticket_project_user_roles', 1, 1)"
);
}
} }
public function down(Schema $schema): void public function down(Schema $schema): void

@ -6,8 +6,11 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Settings; namespace Chamilo\CoreBundle\Settings;
use Chamilo\CoreBundle\Form\Type\IndexedConfigurationType;
use Chamilo\CoreBundle\Form\Type\YesNoType; use Chamilo\CoreBundle\Form\Type\YesNoType;
use Mpdf\Tag\TextArea;
use Sylius\Bundle\SettingsBundle\Schema\AbstractSettingsBuilder; use Sylius\Bundle\SettingsBundle\Schema\AbstractSettingsBuilder;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class TicketSettingsSchema extends AbstractSettingsSchema class TicketSettingsSchema extends AbstractSettingsSchema
@ -22,6 +25,7 @@ class TicketSettingsSchema extends AbstractSettingsSchema
'ticket_allow_student_add' => 'false', 'ticket_allow_student_add' => 'false',
'ticket_send_warning_to_all_admins' => 'false', 'ticket_send_warning_to_all_admins' => 'false',
'ticket_warn_admin_no_user_in_category' => 'false', 'ticket_warn_admin_no_user_in_category' => 'false',
'ticket_project_user_roles' => '',
] ]
) )
; ;
@ -40,6 +44,7 @@ class TicketSettingsSchema extends AbstractSettingsSchema
->add('ticket_allow_student_add') ->add('ticket_allow_student_add')
->add('ticket_send_warning_to_all_admins', YesNoType::class) ->add('ticket_send_warning_to_all_admins', YesNoType::class)
->add('ticket_warn_admin_no_user_in_category', YesNoType::class) ->add('ticket_warn_admin_no_user_in_category', YesNoType::class)
->add('ticket_project_user_roles', TextareaType::class)
; ;
} }
} }

Loading…
Cancel
Save