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

fix Issue #62 Wrong comment url in notifiy email #65

Open
wants to merge 3 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions code_comments/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,27 @@ def validate(self):

def href(self):
if self.is_comment_to_file:
href = self.req.href.browser(self.path, rev=self.revision, codecomment=self.id)
href = self.req.href.browser(self.path, rev=self.revision,
codecomment=self.id)
elif self.is_comment_to_changeset:
href = self.req.href.changeset(self.revision, codecomment=self.id)
base_url = self.env.abs_href()
pathList = base_url.split('/')
projectPath = ""
if len(pathList) > 4:
del pathList[0:3]
projectPath = '/'.join(pathList)
projectPath = '/' + projectPath
if href.startswith(projectPath):
href = href.split("/")
del href[0:len(pathList)+1]
href = '/'.join(href)
href = '/' + href
elif self.is_comment_to_attachment:
href = self.req.href('/attachment/ticket/%d/%s' % (self.attachment_ticket, self.attachment_filename), codecomment=self.id)
href = self.req.href('/attachment/ticket/%d/%s' % (
self.attachment_ticket,
self.attachment_filename),
codecomment=self.id)
if self.line and not self.is_comment_to_changeset:
href += '#L' + str(self.line)
return href
Expand Down
1 change: 0 additions & 1 deletion code_comments/htdocs/code-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var underscore = _.noConflict();
console.log(traceback);
}
}
alert(errorText);
});

window.Comment = Backbone.Model.extend({
Expand Down
46 changes: 30 additions & 16 deletions code_comments/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from code_comments.api import ICodeCommentChangeListener
from code_comments.comments import Comments


class Subscription(object):
"""
Representation of a code comment subscription.
Expand Down Expand Up @@ -87,11 +86,12 @@ def insert(self, db=None):
@self.env.with_transaction()
def do_insert(db):
cursor = db.cursor()
insert = ("INSERT INTO code_comments_subscriptions "
"(user, type, path, repos, rev, notify) "
"VALUES (%s, %s, %s, %s, %s, %s)")
insert = (u"INSERT INTO code_comments_subscriptions "
u"(user, type, path, repos, rev, notify) "
u"VALUES (%s, %s, %s, %s, %s, %s)")
self.path = self.path.decode('utf8')
values = (self.user, self.type, self.path, self.repos,
self.rev, self.notify)
self.rev, self.notify)
Copy link
Contributor

Choose a reason for hiding this comment

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

Trailing whitespace

cursor.execute(insert, values)
self.id = db.get_last_id(cursor, 'code_comments_subscriptions')
return True
Expand All @@ -107,9 +107,10 @@ def update(self, db=None):
@self.env.with_transaction()
def do_update(db):
cursor = db.cursor()
update = ("UPDATE code_comments_subscriptions SET "
"user=%s, type=%s, path=%s, repos=%s, rev=%s, "
"notify=%s WHERE id=%s")
update = (u"UPDATE code_comments_subscriptions SET "
u"user=%s, type=%s, path=%s, repos=%s, rev=%s, "
u"notify=%s WHERE id=%s")
self.path = self.path.encode('utf8')
values = (self.user, self.type, self.path, self.repos,
self.rev, self.notify, self.id)
try:
Expand All @@ -131,6 +132,8 @@ def do_delete(db):
"id=%s")
cursor.execute(delete, (self.id,))



@classmethod
def _from_row(cls, env, row):
"""
Expand Down Expand Up @@ -193,10 +196,14 @@ def from_attachment(cls, env, attachment, user=None, notify=True):
"""
Creates a subscription from an Attachment object.
"""
_path = "/{0}/{1}/{2}".format(attachment.parent_realm,

filename = attachment.filename

_path = u"/{0}/{1}/{2}".format(attachment.parent_realm,
attachment.parent_id,
attachment.filename)

filename)
_path = _path.encode('utf8')

sub = {
'user': user or attachment.author,
'type': 'attachment',
Expand Down Expand Up @@ -265,10 +272,13 @@ def for_attachment(cls, env, attachment, path=None, notify=None):
Returns all subscriptions for an attachment. The path can be
overridden.
"""
path_template = "/{0}/{1}/{2}"
path_template = u"/{0}/{1}/{2}"
filename = attachment.filename
_path = path or path_template.format(attachment.parent_realm,
attachment.parent_id,
attachment.filename)
filename)
_path = _path.encode('utf8')

args = {
'type': 'attachment',
'path': _path,
Expand Down Expand Up @@ -418,13 +428,17 @@ def attachment_deleted(self, attachment):

def attachment_reparented(self, attachment, old_parent_realm,
old_parent_id):
path_template = "/{0}/{1}/{2}"
path_template = u"/{0}/{1}/{2}"
filename = attachment.filename
old_path = path_template.format(old_parent_realm,
old_parent_id,
attachment.filename)
filename)
old_path = old_path.encode('utf8')

new_path = path_template.format(attachment.parent_realm,
attachment.parent_id,
attachment.filename)
filename)
new_path = new_path.encode('utf8')

for subscription in Subscription.for_attachment(self.env, attachment,
old_path):
Expand Down