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

Added group mailbox functionnality. #407

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
plugin
config.ini
config.php
/vendor/
/phpunit
*.cache
plugin
config.ini
config.php
/vendor/
/phpunit
*.cache
/nbproject/private/
/nbproject/project.properties
/nbproject/project.xml
27 changes: 26 additions & 1 deletion app/controller/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public function group_edit(\Base $f3, array $params)

$members = new \Model\Custom("user_group_user");
$f3->set("members", $members->find(array("group_id = ? AND deleted_date IS NULL", $group->id)));

$users = new \Model\User();
$f3->set("users", $users->find("deleted_date IS NULL AND role != 'group'", array("order" => "name ASC")));

Expand Down Expand Up @@ -629,6 +629,31 @@ public function group_setmanager(\Base $f3, array $params)
$f3->reroute("/admin/groups/" . $group->id);
}

/**
* POST /admin/groups/@id/setmailbox/@user_group_id
* @param \Base $f3
* @param array $params
* @throws \Exception
*/
public function group_setmailbox(\Base $f3, array $params)
{
$this->validateCsrf();
$db = $f3->get("db.instance");

$group = new \Model\User();
$group->load(array("id = ? AND deleted_date IS NULL AND role = 'group'", $params["id"]));

if (!$group->id) {
$f3->error(404);
return;
}

$db->exec("UPDATE user_group SET mailbox = 0 WHERE group_id = ?", $group->id);
$db->exec("UPDATE user_group SET mailbox = 1 WHERE id = ?", $params["user_group_id"]);

$f3->reroute("/admin/groups/" . $group->id);
}

/**
* GET /admin/sprints
* @param \Base $f3
Expand Down
1 change: 1 addition & 0 deletions app/dict/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ group_name=Group Name
group_name_saved=Group name saved
manager=Manager
set_as_manager=Set as Manager
set_as_mailbox=Set as Mailbox
add_to_group=Add to Group
api_visible=Visible to API

Expand Down
1 change: 1 addition & 0 deletions app/routes.ini
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ GET /admin/groups/@id = Controller\Admin->group_edit
POST /admin/groups/@id/delete = Controller\Admin->group_delete
POST /admin/groups/ajax = Controller\Admin->group_ajax
GET|POST /admin/groups/@id/setmanager/@user_group_id = Controller\Admin->group_setmanager
GET|POST /admin/groups/@id/setmailbox/@user_group_id = Controller\Admin->group_setmailbox

GET|POST /admin/sprints/new = Controller\Admin->sprint_new
GET|POST /admin/sprints/@id = Controller\Admin->sprint_edit
Expand Down
19 changes: 18 additions & 1 deletion app/view/admin/groups/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
<li data-user-id="{{ @member.user_id }}">
<a href="#" class="delete text-danger has-tooltip" data-placement="right" title="{{ @dict.delete }}" aria-label="{{ @dict.delete }}">
<span class="fa fa-remove"></span>
</a>&nbsp;
</a>
&nbsp;
<check if="{{ @member.manager }}">
<true>
<span class="manager text-warning has-tooltip" data-placement="right" title="{{ @dict.manager }}" aria-label="{{ @dict.manager }}">
Expand All @@ -38,6 +39,22 @@
</false>
</check>
&nbsp;
<check if="{{ @member.mailbox }}">
<true>
<span class="manager text-warning has-tooltip" data-placement="right" title="{{ @dict.mailbox }}" aria-label="{{ @dict.mailbox }}">
<span class="fa fa-envelope"></span>
</span>
</true>
<false>
<form style="display: inline-block;" action="{{ @BASE }}/admin/groups/{{ @group.id }}/setmailbox/{{ @member.id }}" method="post">
<csrf-token />
<button type="submit" class="manager text-muted has-tooltip" data-placement="right" title="{{ @dict.set_as_mailbox }}">
<span class="fa fa-envelope-o"></span>
</button>
</form>
</false>
</check>
&nbsp;
{{ @member.user_name }}
</li>
</repeat>
Expand Down
39 changes: 27 additions & 12 deletions cron/checkmail2.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,44 +125,51 @@
$parts = explode($truncator, $text);
$text = $parts[0];
}

$from = $header->from[0]->mailbox . "@" . $header->from[0]->host;
$subject = imap_utf8($header->subject);
$from_user = new \Model\User;
$from_user->load(array('email = ? AND deleted_date IS NULL', $from));
if (!$from_user->id) {
if (isset($imap['default_user'])) {
$from_user->load($imap['default_user']);
$log->write(sprintf('No matching user, using default - From: %s; Subject: %s', $from, $header->subject));
$log->write(sprintf('No matching user, using default - From: %s; Subject: %s', $from, $subject));
} else {
$log->write(sprintf('Skipping message, no matching user - From: %s; Subject: %s', $from, $header->subject));
continue;
$from_user->load(array('email = ? AND deleted_date IS NULL', $f3->get('mail.from')));
$log->write(sprintf('No matching user, No default IMAP user set, using mail.from - From: %s; Subject: %s', $from, $subject));
//continue;
}
$text .= "\n\nSender: " . $from;//This will insert sender mail in the incident if it's not a known user.
}

$to_user = new \Model\User;
$owner = $from_user->id;
$owner = $from_user->id;//imap default user
foreach ($header->to as $to_email) {
$to = $to_email->mailbox . "@" . $to_email->host;
$to_user->load(array('email = ? AND deleted_date IS NULL', $to));
if ($to_user->id) {
$owner = $to_user->id;
break;
$log->write(sprintf('Message for group mailbox - From: %s; To: %s; Subject: %s', $from, $to_user->email, $subject));
break;//le script ne semble pas procéder aux mails suivants.
} else {
$log->write(sprintf('Skipping message, No matching user as recipient - From: %s; To: %s; Subject: %s', $from, $to_user->email, $subject));
continue;//test supplémentaire
}
}

// Find issue IDs in subject
preg_match("/\[#([0-9]+)\] -/", $header->subject, $matches);
preg_match("/\[#([0-9]+)\] -/", $subject, $matches);

// Get issue instance
$issue = new \Model\Issue;
if (!empty($matches[1])) {
$issue->load(intval($matches[1]));
}
if (!$issue->id) {
$subject = trim(preg_replace("/^((Re|Fwd?):\s)*/i", "", $header->subject));
$subject = trim(preg_replace("/^((Re|Fwd?):\s)*/i", "", $subject));
$issue->load(array('name=? AND deleted_date IS NULL AND closed_date IS NULL', $subject));
}

if ($issue->id) {
if (trim($text)) {
$comment = \Model\Issue\Comment::create(array(
Expand All @@ -173,10 +180,18 @@
$log->write(sprintf("Added comment %s on issue #%s - %s", $comment->id, $issue->id, $issue->name));
}
} else {

//No matching issue, creating a new issue
//if user is mailbox of the group, the issue is assigned to the group.
$is_group_mailbox = new \Model\Custom("user_group_user");
$is_group_mailbox->load(array("user_id = ? AND deleted_date IS NULL", $owner));
if($is_group_mailbox->mailbox){
$owner = $is_group_mailbox->group_id;
}
$issue = \Model\Issue::create(array(
'name' => $header->subject,
'name' => $subject,
'description' => $text,
'author_id' => $from_user->id,
'author_id' => $from_user->id?$from_user->id:$is_group_mailbox->id,//if from user is invalid, it means that the mail is sent to a mailbox, otherwise the mail is discarded
'owner_id' => $owner,
'status' => 1,
'type_id' => 1
Expand Down
5 changes: 5 additions & 0 deletions db/21.03.25.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Add default description to issue types
ALTER VIEW `user_group_user`
AS (select `g`.`id` AS `id`,`g`.`group_id` AS `group_id`,`g`.`user_id` AS `user_id`,`u`.`username` AS `user_username`,`u`.`email` AS `user_email`,`u`.`name` AS `user_name`,`u`.`role` AS `user_role`,`u`.`task_color` AS `user_task_color`,`u`.`deleted_date` AS `deleted_date`,`g`.`manager` AS `manager`,`g`.`mailbox` AS `mailbox` from (`user_group` `g` join `user` `u` on((`g`.`user_id` = `u`.`id`))));

UPDATE `config` SET `value` = '21.03.25' WHERE `attribute` = 'version';
43 changes: 22 additions & 21 deletions db/database.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SET NAMES utf8mb4;
SET NAMES utf8;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The utf8mb4 encoding here is required to correctly support many Unicode characters including Emoji, was there a reason you changed this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this as been added by git. On my dev environment I have to remove "mb4" to have the db working, but this is not part of my changes.

SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';

Expand All @@ -25,18 +25,19 @@ CREATE TABLE `user` (
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `user_group`;
CREATE TABLE `user_group` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`group_id` int(10) unsigned NOT NULL,
`manager` tinyint(1) NOT NULL DEFAULT '0',
`mailbox` tinyint(1) NOT NULL DEFAULT '0',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to database schemas need to also have an update file, like the other .sql files in this directory, otherwise the changes won't be applied to existing installations. The config table's value attribute should be updated to match that name, both in this file and at the end of the update script.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will do that

PRIMARY KEY (`id`),
KEY `group_id` (`group_id`),
KEY `group_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `issue`;
CREATE TABLE `issue` (
Expand Down Expand Up @@ -74,7 +75,7 @@ CREATE TABLE `issue` (
CONSTRAINT `issue_owner_id` FOREIGN KEY (`owner_id`) REFERENCES `user`(`id`) ON UPDATE CASCADE ON DELETE SET NULL,
CONSTRAINT `issue_priority` FOREIGN KEY (`priority`) REFERENCES `issue_priority`(`value`) ON UPDATE CASCADE ON DELETE RESTRICT,
CONSTRAINT `issue_status` FOREIGN KEY (`status`) REFERENCES `issue_status`(`id`) ON UPDATE CASCADE ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `issue_backlog`;
CREATE TABLE `issue_backlog` (
Expand All @@ -84,7 +85,7 @@ CREATE TABLE `issue_backlog` (
PRIMARY KEY (`id`),
UNIQUE KEY `issue_backlog_sprint_id` (`sprint_id`),
CONSTRAINT `issue_backlog_sprint_id` FOREIGN KEY (`sprint_id`) REFERENCES `sprint` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `issue_comment`;
CREATE TABLE `issue_comment` (
Expand All @@ -99,7 +100,7 @@ CREATE TABLE `issue_comment` (
KEY `user` (`user_id`),
CONSTRAINT `comment_issue` FOREIGN KEY (`issue_id`) REFERENCES `issue` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `comment_user` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `issue_file`;
CREATE TABLE `issue_file` (
Expand All @@ -119,7 +120,7 @@ CREATE TABLE `issue_file` (
KEY `index_issue_id` (`issue_id`),
KEY `index_user_id` (`user_id`),
KEY `index_created_on` (`created_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `issue_priority`;
CREATE TABLE `issue_priority` (
Expand All @@ -128,7 +129,7 @@ CREATE TABLE `issue_priority` (
`name` varchar(64) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `priority` (`value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `issue_priority` (`id`, `value`, `name`) VALUES
(1, 0, 'Normal'),
Expand All @@ -143,7 +144,7 @@ CREATE TABLE `issue_status` (
`taskboard` tinyint(1) NOT NULL DEFAULT '1',
`taskboard_sort` INT UNSIGNED NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `issue_status` (`id`, `name`, `closed`, `taskboard`, `taskboard_sort`) VALUES
(1, 'New', 0, 2, 1),
Expand All @@ -159,7 +160,7 @@ CREATE TABLE `issue_type` (
`default_description` text NULL,
PRIMARY KEY (`id`),
KEY `issue_type_role` (`role`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `issue_type` (`id`, `name`, `role`) VALUES
(1, 'Task', 'task'),
Expand All @@ -178,7 +179,7 @@ CREATE TABLE `issue_update` (
KEY `issue` (`issue_id`),
KEY `user` (`user_id`),
CONSTRAINT `update_issue` FOREIGN KEY (`issue_id`) REFERENCES `issue` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `issue_update_field`;
CREATE TABLE `issue_update_field` (
Expand All @@ -190,7 +191,7 @@ CREATE TABLE `issue_update_field` (
PRIMARY KEY (`id`),
KEY `issue_update_field_update_id` (`issue_update_id`),
CONSTRAINT `issue_update_field_update` FOREIGN KEY (`issue_update_id`) REFERENCES `issue_update` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `issue_watcher`;
CREATE TABLE `issue_watcher` (
Expand All @@ -199,7 +200,7 @@ CREATE TABLE `issue_watcher` (
`user_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_watch` (`issue_id`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `issue_tag`;
CREATE TABLE `issue_tag`(
Expand All @@ -209,20 +210,20 @@ CREATE TABLE `issue_tag`(
PRIMARY KEY (`id`),
INDEX `issue_tag_tag` (`tag`, `issue_id`),
CONSTRAINT `issue_tag_issue` FOREIGN KEY (`issue_id`) REFERENCES `issue`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=INNODB CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=INNODB CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `issue_dependency`;
CREATE TABLE `issue_dependency` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`issue_id` int(10) unsigned NOT NULL,
`dependency_id` int(10) unsigned NOT NULL,
`dependency_type` char(2) COLLATE utf8mb4_unicode_ci NOT NULL,
`dependency_type` char(2) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `issue_id_dependency_id` (`issue_id`,`dependency_id`),
KEY `dependency_id` (`dependency_id`),
CONSTRAINT `issue_dependency_ibfk_2` FOREIGN KEY (`issue_id`) REFERENCES `issue` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `issue_dependency_ibfk_3` FOREIGN KEY (`dependency_id`) REFERENCES `issue` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `sprint`;
CREATE TABLE `sprint` (
Expand All @@ -231,10 +232,10 @@ CREATE TABLE `sprint` (
`start_date` date NOT NULL,
`end_date` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP VIEW IF EXISTS `user_group_user`;
CREATE VIEW `user_group_user` AS (select `g`.`id` AS `id`,`g`.`group_id` AS `group_id`,`g`.`user_id` AS `user_id`,`u`.`username` AS `user_username`,`u`.`email` AS `user_email`,`u`.`name` AS `user_name`,`u`.`role` AS `user_role`,`u`.`task_color` AS `user_task_color`,`u`.`deleted_date` AS `deleted_date`,`g`.`manager` AS `manager` from (`user_group` `g` join `user` `u` on((`g`.`user_id` = `u`.`id`))));
CREATE VIEW `user_group_user` AS (select `g`.`id` AS `id`,`g`.`group_id` AS `group_id`,`g`.`user_id` AS `user_id`,`u`.`username` AS `user_username`,`u`.`email` AS `user_email`,`u`.`name` AS `user_name`,`u`.`role` AS `user_role`,`u`.`task_color` AS `user_task_color`,`u`.`deleted_date` AS `deleted_date`,`g`.`manager` AS `manager`,`g`.`mailbox` AS `mailbox` from (`user_group` `g` join `user` `u` on((`g`.`user_id` = `u`.`id`))));

DROP VIEW IF EXISTS `issue_comment_user`;
CREATE VIEW `issue_comment_user` AS (select `c`.`id` AS `id`,`c`.`issue_id` AS `issue_id`,`c`.`user_id` AS `user_id`,`c`.`text` AS `text`, `c`.`file_id` as `file_id`, `c`.`created_date` AS `created_date`,`u`.`username` AS `user_username`,`u`.`email` AS `user_email`,`u`.`name` AS `user_name`,`u`.`role` AS `user_role`,`u`.`task_color` AS `user_task_color` from (`issue_comment` `c` join `user` `u` on((`c`.`user_id` = `u`.`id`))));
Expand Down Expand Up @@ -313,16 +314,16 @@ CREATE TABLE `session`(
UNIQUE KEY `session_token` (`token`, `ip`),
KEY `session_user_id` (`user_id`),
CONSTRAINT `session_user_id` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=INNODB CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=INNODB CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `config`;
CREATE TABLE `config` (
`id` int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`attribute` varchar(255) NULL,
`value` varchar(255) NULL,
UNIQUE KEY `attribute` (`attribute`)
) CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `config` (`attribute`,`value`) VALUES ('security.reset_ttl', '86400');
INSERT INTO `config` (`attribute`,`value`) VALUES ('security.file_blacklist', '/\.(ph(p([3457s]|\-s)?|t|tml)|aspx?|shtml|exe|dll)$/i');
INSERT INTO `config` (`attribute`, `value`) VALUES ('version', '21.03.18');
INSERT INTO `config` (`attribute`, `value`) VALUES ('version', '21.03.25');