Commit 8ef4bde2 authored by Frank Bergmann's avatar Frank Bergmann

- changes in forum to send messages to all stake holders

- includes sending notifications based on the subscription
  of the "root" message (when modifying replies)
parent 023f2368
...@@ -8,21 +8,18 @@ ...@@ -8,21 +8,18 @@
<singleton-p>t</singleton-p> <singleton-p>t</singleton-p>
<auto-mount>intranet-forum</auto-mount> <auto-mount>intranet-forum</auto-mount>
<version name="2.0.0" url="http://openacs.org/repository/download/apm/intranet-forum-2.0.0.apm"> <version name="1.0" url="http://openacs.org/repository/download/apm/intranet-forum-1.0.apm">
<owner url="mailto:fraber@fraber.de">Frank Bergmann</owner> <owner url="mailto:fraber@fraber.de">Frank Bergmann</owner>
<vendor url="http://www.project-open.com/">Project/Open</vendor> <vendor url="http://www.project-open.com/">Project/Open</vendor>
<provides url="intranet-forum" version="2.0.0"/> <provides url="intranet-forum" version="1.0"/>
<requires url="intranet-core" version="2.0.0"/> <requires url="intranet-core" version="1.0"/>
<callbacks> <callbacks>
</callbacks> </callbacks>
<parameters> <parameters>
<parameter datatype="number" min_n_values="1" max_n_values="1" name="SubscribeAllMembersToNewItemsP" default="0" description="Inform all project members about forum updates by subscribing them to items by default?"/> <parameter datatype="number" min_n_values="1" max_n_values="1" name="SubscribeAllMembersToNewItemsP" default="1" description="SubscribeAllMembersToNewItemsP"/>
</parameters> </parameters>
</version> </version>
</package> </package>
...@@ -29,6 +29,21 @@ ad_proc -public im_topic_type_id_incident { } { return 1104 } ...@@ -29,6 +29,21 @@ ad_proc -public im_topic_type_id_incident { } { return 1104 }
ad_proc -public im_topic_type_id_reply { } { return 1190 } ad_proc -public im_topic_type_id_reply { } { return 1190 }
ad_proc -public im_package_forum_id {} {
Returns the package id of the intranet-forum module
} {
return [util_memoize "im_package_forum_id_helper"]
}
ad_proc -private im_package_forum_id_helper {} {
return [db_string im_package_core_id {
select package_id from apm_packages
where package_key = 'intranet-forum'
} -default 0]
}
ad_proc -public im_forum_is_task_or_incident { topic_type_id } { ad_proc -public im_forum_is_task_or_incident { topic_type_id } {
Returns 1 if it's a "Task" or "Incident" Returns 1 if it's a "Task" or "Incident"
} { } {
...@@ -346,6 +361,7 @@ ad_proc -public im_forum_render_tind { ...@@ -346,6 +361,7 @@ ad_proc -public im_forum_render_tind {
subject message subject message
posting_date due_date posting_date due_date
priority scope priority scope
receive_updates
return_url return_url
} { } {
Render the rows of a single TIND Render the rows of a single TIND
...@@ -489,6 +505,15 @@ ad_proc -public im_forum_render_tind { ...@@ -489,6 +505,15 @@ ad_proc -public im_forum_render_tind {
</td> </td>
</tr>" </tr>"
incr ctr incr ctr
# Show whether the user has subscribed to updates
append tind_html "
<tr $bgcolor([expr $ctr % 2])>
<td>Receive updates</td>
<td>$receive_updates
</td>
</tr>"
incr ctr
} }
# Only allow plain text messages # Only allow plain text messages
...@@ -584,7 +609,11 @@ where ...@@ -584,7 +609,11 @@ where
append thread_html " append thread_html "
<td colspan=$colspan_level> <td colspan=$colspan_level>
<table border=0 cellpadding=0 bgcolor=#E0E0E0>" <table border=0 cellpadding=0 bgcolor=#E0E0E0>"
append thread_html " [im_forum_render_tind $topic_id 0 $topic_type_id $topic_type $topic_status_id $topic_status $owner_id $asignee_id $owner_name $asignee_name $user_id $object_id $object_name $object_admin $subject $message $posting_date $due_date $priority $scope $return_url]
# don't show received updates for everything but the main message
set receive_updates ""
append thread_html " [im_forum_render_tind $topic_id 0 $topic_type_id $topic_type $topic_status_id $topic_status $owner_id $asignee_id $owner_name $asignee_name $user_id $object_id $object_name $object_admin $subject $message $posting_date $due_date $priority $scope $receive_updates $return_url]
</table> </table>
</td> </td>
......
...@@ -135,7 +135,7 @@ set page_body " ...@@ -135,7 +135,7 @@ set page_body "
<table cellspacing=1 border=0 cellpadding=1> <table cellspacing=1 border=0 cellpadding=1>
[im_forum_render_tind $topic_id $parent_id $topic_type_id $topic_type $topic_status_id $topic_status $owner_id $asignee_id $owner_name $asignee_name $user_id $object_id $object_name $object_admin $subject $message $posting_date $due_date $priority $scope $return_url] [im_forum_render_tind $topic_id $parent_id $topic_type_id $topic_type $topic_status_id $topic_status $owner_id $asignee_id $owner_name $asignee_name $user_id $object_id $object_name $object_admin $subject $message $posting_date $due_date $priority $scope $receive_updates $return_url]
<tr><td colspan=2>&nbsp;</td></tr> <tr><td colspan=2>&nbsp;</td></tr>
$table_body $table_body
......
...@@ -140,22 +140,26 @@ if {[string equal $actions "save"]} { ...@@ -140,22 +140,26 @@ if {[string equal $actions "save"]} {
if {!$exists_p} { if {!$exists_p} {
# Create an empty entry - # Create an empty entry -
# Details are added at the insert below # Details are added at the insert below
db_transaction { db_transaction {
db_dml topic_insert " db_dml topic_insert {
insert into im_forum_topics ( insert into im_forum_topics (
topic_id, object_id, topic_type_id, topic_status_id, owner_id, subject topic_id, object_id, topic_type_id,
) values ( topic_status_id, owner_id, subject
:topic_id, :object_id, :topic_type_id, :topic_status_id, :owner_id, :subject ) values (
)" :topic_id, :object_id, :topic_type_id,
} on_error { :topic_status_id, :owner_id, :subject
)
}
} on_error {
ad_return_error "Error adding a new topic" " ad_return_error "Error adding a new topic" "
The database rejected the addition of discussion topic The database rejected the addition of discussion topic
\"$subject\". Here the error message: <pre>$errmsg\n</pre>\n" \"$subject\". Here the error message: <pre>$errmsg\n</pre>\n"
return return
} }
} }
# update the information # update the information
db_transaction { db_transaction {
db_dml topic_update " db_dml topic_update "
...@@ -180,7 +184,6 @@ where topic_id=:topic_id" ...@@ -180,7 +184,6 @@ where topic_id=:topic_id"
return return
} }
# im_forum_topics_user_map may or may not exist for every user. # im_forum_topics_user_map may or may not exist for every user.
# So we create a record just in case, even if the SQL fails. # So we create a record just in case, even if the SQL fails.
db_transaction { db_transaction {
...@@ -192,6 +195,7 @@ where topic_id=:topic_id" ...@@ -192,6 +195,7 @@ where topic_id=:topic_id"
# nothing - may already exist... # nothing - may already exist...
} }
# Now let's update the existing entry # Now let's update the existing entry
db_transaction { db_transaction {
db_dml im_forum_topic_user_map_update " db_dml im_forum_topic_user_map_update "
...@@ -211,6 +215,72 @@ where ...@@ -211,6 +215,72 @@ where
} }
# ---------------------------------------------------------------------
# New Message: Subscribe all current project members
# ---------------------------------------------------------------------
# Only if we are creating a new message...
if {[string equal $action_type "new_message"]} {
# .. and only if the parameter is enabled...
if {[ad_parameter -package_id [im_package_forum_id] SubscribeAllMembersToNewItemsP "" "0"]} {
# Select the list of all project members allowed to see
# see the new TIND.
#
set object_member_sql "
select
p.party_id as user_id
from
acs_rels r,
parties p,
(select m.member_id as user_id,
1 as p
from group_distinct_member_map m
where m.group_id = [im_customer_group_id]
) customers,
(select m.member_id as user_id,
1 as p
from group_distinct_member_map m
where m.group_id = [im_employee_group_id]
) employees
where
r.object_id_one = 3273
and r.object_id_two = p.party_id
and p.party_id = customers.user_id(+)
and p.party_id = employees.user_id(+)
and 1 = im_forum_permission(
p.party_id,
:user_id,
:asignee_id,
:object_id,
:scope,
1,
0,
employees.p,
customers.p
)"
db_foreach subscribe_object_members $object_member_sql {
ns_log Notice "intranet-forum/new-2: subscribe user\#$user_id to message\#$topic_id in object\#$object_id"
# im_forum_topics_user_map may or may not exist for every user.
# So we create a record just in case, even if the SQL fails.
db_transaction {
db_dml im_forum_topic_user_map_insert "
insert into im_forum_topic_user_map
(topic_id, user_id, read_p, folder_id, receive_updates) values
(:topic_id, :user_id, :read_p, :folder_id, 'all')
"
} on_error {
# nothing - may already exist...
}
}
}
}
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Assign the ticket to a new user # Assign the ticket to a new user
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -324,13 +394,14 @@ where topic_id=:topic_id" ...@@ -324,13 +394,14 @@ where topic_id=:topic_id"
# Alert about changes # Alert about changes
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
set msg_url "[ad_parameter -package_id [ad_acs_kernel_id] SystemURL "" ""]/intranet-forum/view?topic_id=$topic_id" set msg_url "[ad_parameter -package_id [ad_acs_kernel_id] SystemURL "" ""]intranet-forum/view?topic_id=$topic_id"
set importance 0 set importance 0
db_1row subject_message " db_1row subject_message "
select select
t.subject, t.subject,
t.message, t.message,
t.parent_id,
im_category_from_id(t.topic_type_id) as topic_type im_category_from_id(t.topic_type_id) as topic_type
from from
im_forum_topics t im_forum_topics t
...@@ -338,11 +409,60 @@ where ...@@ -338,11 +409,60 @@ where
t.topic_id = :topic_id t.topic_id = :topic_id
" "
# Check for the root-parent message in order to determine
# whethter the user has subscribed to it or not.
set ctr 0
while {"" != $parent_id && 0 != $parent_id && $ctr < 10} {
ns_log Notice "intranet-forum/new-2: looking up parent $parent_id of topic $topic_id"
# avoid infinite loops...
incr ctr
set lookup_parent_sql "
select
t.topic_id,
t.parent_id
from
im_forum_topics t
where
t.topic_id = :parent_id
"
db_0or1row lookup_parent $lookup_parent_sql
}
# Determine whether the update was "important" or not # Determine whether the update was "important" or not
# 0=none, 1=non-important, 2=important # 0=none, 1=non-important, 2=important
# #
switch $action_type {
"new_message" {
set importance 2
set subject "New $topic_type: $subject"
set message "
A new $topic_type has been created.
Please visit the link above for details.\n"
}
"edit_message" {
set importance 1
set subject "Changed $topic_type: $subject"
set message "
A $topic_type has been modified.
Please visit the link above for details.\n"
}
"reply_message" {
set importance 1
set subject "Reply to $topic_type: $subject"
set message "
A $topic_type reply has been created.
Please visit the link above for details.\n"
}
}
switch $actions { switch $actions {
"accept" { "accept" {
set importance 1 set importance 1
......
...@@ -131,7 +131,7 @@ set ctr 1 ...@@ -131,7 +131,7 @@ set ctr 1
# Render the message # Render the message
# ------------------------------------------------------------------ # ------------------------------------------------------------------
append table_body [im_forum_render_tind $topic_id $parent_id $topic_type_id $topic_type $topic_status_id $topic_status $owner_id $asignee_id $owner_name $asignee_name $user_id $object_id $object_name $object_admin $subject $message $posting_date $due_date $priority $scope $return_url] append table_body [im_forum_render_tind $topic_id $parent_id $topic_type_id $topic_type $topic_status_id $topic_status $owner_id $asignee_id $owner_name $asignee_name $user_id $object_id $object_name $object_admin $subject $message $posting_date $due_date $priority $scope $receive_updates $return_url]
# -------------- Action Area ----------------------------- # -------------- Action Area -----------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment