public void ReindexAllBugs(object sender, EventArgs e)
 {
     if (Util.get_setting("EnableSearch", "1") == "1")
     {
         IBugSearch search = BugSearchFactory.CreateBugSearch();
         Task.Run(() => search.IndexAll());
         reindexLink.Enabled = false;
         reindexLink.Text    = reindexLink.Text + " (Indexing in process)";
     }
 }
Exemple #2
0
#pragma warning disable 618

        ///////////////////////////////////////////////////////////////////////
        void Page_Load(Object sender, EventArgs e)
        {
            Master.Menu.SelectedItem = Util.get_setting("PluralBugLabel", "bugs");

            try
            {
                if (string.IsNullOrEmpty(Request["query"]))
                {
                    throw new Exception("You forgot to enter something to search for...");
                }
            }
            catch (Exception e3)
            {
                display_exception(e3);
            }

            var search = BugSearchFactory.CreateBugSearch();

            _searchResults = search.Search(Request["Query"], User.Identity).Tables[0];

            Session["query"] = Request["query"];
        }
Exemple #3
0
        ///////////////////////////////////////////////////////////////////////
        // This used to send the emails, but not now.  Now it just queues
        // the emails to be sent, then spawns a thread to send them.
        public static void send_notifications(int insert_or_update,  // The implementation
                                              int bugid,
                                              IIdentity identity,
                                              int just_to_this_userid,
                                              bool status_changed,
                                              bool assigned_to_changed,
                                              int prev_assigned_to_user)
        {
            // If there's something worth emailing about, then there's
            // probably something worth updating the index about.
            // Really, though, we wouldn't want to update the index if it were
            // just the status that were changing...
            if (btnet.Util.get_setting("EnableSearch", "1") == "1")
            {
                IBugSearch search = BugSearchFactory.CreateBugSearch();
                search.IndexBug(bugid);
            }

            bool notification_email_enabled = (btnet.Util.get_setting("NotificationEmailEnabled", "1") == "1");

            if (!notification_email_enabled)
            {
                return;
            }
            // MAW -- 2006/01/27 -- Determine level of change detected
            int changeLevel = 0;

            if (insert_or_update == INSERT)
            {
                changeLevel = 1;
            }
            else if (status_changed)
            {
                changeLevel = 2;
            }
            else if (assigned_to_changed)
            {
                changeLevel = 3;
            }
            else
            {
                changeLevel = 4;
            }

            SQLString sql;

            if (just_to_this_userid > 0)
            {
                sql = new SQLString(@"
/* get notification email for just one user  */
select us_email, us_id, us_admin, og.*
from bug_subscriptions
inner join users on bs_user = us_id
inner join orgs og on us_org = og_id
inner join bugs on bg_id = bs_bug
left outer join project_user_xref on pu_user = us_id and pu_project = bg_project
where us_email is not null
and us_enable_notifications = 1
-- @status_change
and us_active = 1
and us_email <> ''
and
case
when
    us_org <> bg_org
    and og_other_orgs_permission_level < 2
    and og_other_orgs_permission_level < isnull(pu_permission_level,@dpl)
        then og_other_orgs_permission_level
else
    isnull(pu_permission_level,@dpl)
end <> 0
and bs_bug = @id
and us_id = @just_this_usid");

                sql = sql.AddParameterWithValue("just_this_usid", Convert.ToString(just_to_this_userid));
            }
            else
            {
                // MAW -- 2006/01/27 -- Added different notifications if reported or assigned-to
                sql = new SQLString(@"
/* get notification emails for all subscribers */
select us_email, us_id, us_username, us_admin, og.*
from bug_subscriptions
inner join users on bs_user = us_id
inner join orgs og on us_org = og_id
inner join bugs on bg_id = bs_bug
left outer join project_user_xref on pu_user = us_id and pu_project = bg_project
where us_email is not null
and us_enable_notifications = 1
-- @status_change
and us_active = 1
and us_email <> ''
and (   (@cl <= us_reported_notifications and bg_reported_user = bs_user)
or (@cl <= us_assigned_notifications and bg_assigned_to_user = bs_user)
or (@cl <= us_assigned_notifications and @pau = bs_user)
or (@cl <= us_subscribed_notifications))
and
case
when
us_org <> bg_org
and og_other_orgs_permission_level < 2
and og_other_orgs_permission_level < isnull(pu_permission_level,@dpl)
    then og_other_orgs_permission_level
else
isnull(pu_permission_level,@dpl)
end <> 0
and bs_bug = @id
and (us_id <> @us or isnull(us_send_notifications_to_self,0) = 1)");
            }

            sql = sql.AddParameterWithValue("@cl", changeLevel);
            sql = sql.AddParameterWithValue("@pau", prev_assigned_to_user);
            sql = sql.AddParameterWithValue("@id", bugid);
            sql = sql.AddParameterWithValue("@dpl", Convert.ToInt32(btnet.Util.get_setting("DefaultPermissionLevel", "2")));
            sql = sql.AddParameterWithValue("@us", identity.GetUserId());


            DataSet ds_subscribers = btnet.DbUtil.get_dataset(sql);

            if (ds_subscribers.Tables[0].Rows.Count > 0)
            {
                bool added_to_queue = false;


                // Get bug html
                DataRow bug_dr = btnet.Bug.get_bug_datarow(bugid, identity);

                string from = btnet.Util.get_setting("NotificationEmailFrom", "");

                // Format the subject line
                string subject = btnet.Util.get_setting("NotificationSubjectFormat", "$THING$:$BUGID$ was $ACTION$ - $SHORTDESC$ $TRACKINGID$");

                subject = subject.Replace("$THING$", btnet.Util.capitalize_first_letter(btnet.Util.get_setting("SingularBugLabel", "bug")));

                string action = "";
                if (insert_or_update == INSERT)
                {
                    action = "added";
                }
                else
                {
                    action = "updated";
                }

                subject = subject.Replace("$ACTION$", action);
                subject = subject.Replace("$BUGID$", Convert.ToString(bugid));
                subject = subject.Replace("$SHORTDESC$", (string)bug_dr["short_desc"]);

                string tracking_id = " (";
                tracking_id += btnet.Util.get_setting("TrackingIdString", "DO NOT EDIT THIS:");
                tracking_id += Convert.ToString(bugid);
                tracking_id += ")";
                subject      = subject.Replace("$TRACKINGID$", tracking_id);

                subject = subject.Replace("$PROJECT$", (string)bug_dr["current_project"]);
                subject = subject.Replace("$ORGANIZATION$", (string)bug_dr["og_name"]);
                subject = subject.Replace("$CATEGORY$", (string)bug_dr["category_name"]);
                subject = subject.Replace("$PRIORITY$", (string)bug_dr["priority_name"]);
                subject = subject.Replace("$STATUS$", (string)bug_dr["status_name"]);
                subject = subject.Replace("$ASSIGNED_TO$", (string)bug_dr["assigned_to_username"]);


                // send a separate email to each subscriber
                foreach (DataRow dr in ds_subscribers.Tables[0].Rows)
                {
                    string to = (string)dr["us_email"];

                    // Create a fake response and let the code
                    // write the html to that response
                    System.IO.StringWriter writer      = new System.IO.StringWriter();
                    HttpResponse           my_response = new HttpResponse(writer);
                    my_response.Write("<html>");
                    my_response.Write("<base href=\"" +
                                      btnet.Util.get_setting("AbsoluteUrlPrefix", "http://127.0.0.1/") + "\"/>");

                    // create a security rec for the user receiving the email
                    IIdentity identity2 = Security.Security.GetIdentity((string)dr["us_username"]);


                    PrintBug.print_bug(
                        my_response,
                        bug_dr, identity2,
                        true,  // include style
                        false, // images_inline
                        true,  // history_inline
                        true); // internal_posts

                    // at this point "writer" has the bug html

                    sql = new SQLString(@"
delete from queued_notifications where qn_bug = @bug and qn_to = @to

insert into queued_notifications
(qn_date_created, qn_bug, qn_user, qn_status, qn_retries, qn_to, qn_from, qn_subject, qn_body, qn_last_exception)
values (getdate(), @bug, @user, N''not sent', 0, @to, @from, @subject, @body, N'')");

                    sql = sql.AddParameterWithValue("@bug", Convert.ToString(bugid));
                    sql = sql.AddParameterWithValue("@user", Convert.ToString(dr["us_id"]));
                    sql = sql.AddParameterWithValue("@to", to);
                    sql = sql.AddParameterWithValue("@from", from);
                    sql = sql.AddParameterWithValue("@subject", subject);
                    sql = sql.AddParameterWithValue("@body", writer.ToString());

                    btnet.DbUtil.execute_nonquery_without_logging(sql);

                    added_to_queue = true;
                } // end loop through ds_subscribers

                if (added_to_queue)
                {
                    // spawn a worker thread to send the emails
                    System.Threading.Thread thread = new System.Threading.Thread(threadproc_notifications);
                    thread.Start();
                }
            }  // if there are any subscribers
        }