Changeset - 6f0143e5efe5
[Not reviewed]
beta
0 6 0
Marcin Kuzminski - 14 years ago 2011-11-12 16:09:17
marcin@python-works.com
#71 code review
- added delete of comments by owner or admin
6 files changed with 36 insertions and 10 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/routing.py
Show inline comments
 
@@ -343,25 +343,25 @@ def make_map(config):
 
                conditions=dict(function=check_group))
 

	
 
    rmap.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}',
 
                controller='changeset', revision='tip',
 
                conditions=dict(function=check_repo))
 

	
 
    rmap.connect('changeset_comment', '/{repo_name:.*}/changeset/{revision}/comment',
 
                controller='changeset', revision='tip', action='comment',
 
                conditions=dict(function=check_repo))
 

	
 
    rmap.connect('changeset_comment_delete', '/{repo_name:.*}/changeset/comment/{comment_id}/delete',
 
                controller='changeset', action='delete_comment',
 
                conditions=dict(function=check_repo))
 
                conditions = dict(function=check_repo, method=["DELETE"]))
 

	
 
    rmap.connect('raw_changeset_home',
 
                 '/{repo_name:.*}/raw-changeset/{revision}',
 
                 controller='changeset', action='raw_changeset',
 
                 revision='tip', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('summary_home', '/{repo_name:.*}/summary',
 
                controller='summary', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('shortlog_home', '/{repo_name:.*}/shortlog',
 
                controller='shortlog', conditions=dict(function=check_repo))
 

	
rhodecode/controllers/changeset.py
Show inline comments
 
@@ -35,24 +35,25 @@ import rhodecode.lib.helpers as h
 
from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator, \
 
    NotAnonymous
 
from rhodecode.lib.base import BaseRepoController, render
 
from rhodecode.lib.utils import EmptyChangeset
 
from rhodecode.lib.compat import OrderedDict
 
from rhodecode.model.db import ChangesetComment
 
from rhodecode.model.comment import ChangesetCommentsModel
 

	
 
from vcs.exceptions import RepositoryError, ChangesetError, \
 
    ChangesetDoesNotExistError
 
from vcs.nodes import FileNode
 
from vcs.utils import diffs as differ
 
from webob.exc import HTTPForbidden
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class ChangesetController(BaseRepoController):
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def __before__(self):
 
        super(ChangesetController, self).__before__()
 
        c.affected_files_cut_off = 60
 
@@ -269,17 +270,22 @@ class ChangesetController(BaseRepoContro
 
        ccmodel = ChangesetCommentsModel()
 

	
 
        ccmodel.create(text=request.POST.get('text'),
 
                       repo_id=c.rhodecode_db_repo.repo_id, 
 
                       user_id=c.rhodecode_user.user_id, 
 
                       commit_id=revision, f_path=request.POST.get('f_path'), 
 
                       line_no = request.POST.get('line'))
 

	
 
        return redirect(h.url('changeset_home', repo_name=repo_name,
 
                              revision=revision))
 

	
 
    @jsonify
 
    @HasRepoPermissionAnyDecorator('hg.admin', 'repository.admin')
 
    def delete_comment(self, comment_id):
 
        co = ChangesetComment.get(comment_id)
 
        if (h.HasPermissionAny('hg.admin', 'repository.admin')() or
 
            co.author.user_id == c.rhodecode_user.user_id):
 
        ccmodel = ChangesetCommentsModel()
 
        ccmodel.delete(comment_id=comment_id)
 
        return True
 
        else:
 
            raise HTTPForbidden()
 

	
rhodecode/public/css/style.css
Show inline comments
 
@@ -3254,27 +3254,26 @@ div.rst-block  pre {
 
    vertical-align: middle;
 
}
 
 
.comments .comment .meta .user {
 
    font-weight: bold;
 
}
 
 
.comments .comment .meta .date {
 
    float: right;
 
}
 
 
.comments .comment .text {
 
    margin-top: 7px;
 
    padding: 6px;
 
    padding-bottom: 13px;
 
    padding: 8px 6px 6px 14px;
 
    background-color: #FAFAFA;
 
}
 
 
.comments .comments-number{
 
	padding:0px 0px 10px 0px;
 
	font-weight: bold;
 
}
 
 
.comment-form .clearfix{
 
	background: #EEE;
 
    -webkit-border-radius: 4px;
 
    -moz-border-radius: 4px;
 
    border-radius: 4px;
 
@@ -3321,15 +3320,15 @@ form.comment-form {
 
 
.comment-form .comment-button{
 
	padding-top:5px;
 
}
 
 
.add-another-button {
 
    margin-left: 10px;
 
    margin-top: 10px;
 
    margin-bottom: 10px;
 
}
 
 
.comment .buttons {
 
    float: right;
 
    display: none;
 
}
 
    position: absolute;
 
    right:40px;
 
}
rhodecode/public/js/rhodecode.js
Show inline comments
 
@@ -277,14 +277,24 @@ var q_filter = function(target,nodes,dis
 
    	   }
 
       }	  	   
 

	
 
	   // if repo_count is set update the number
 
	   var cnt = YUD.get('repo_count');
 
	   if(cnt){
 
		   YUD.get('repo_count').innerHTML = showing;
 
	   }       
 
       
 
	}	
 
}
 

	
 
var ajaxPOST = function(url,postData,success) {
 
    var sUrl = url;
 
    var callback = {
 
        success: success,
 
        failure: function (o) {
 
            alert("error");
 
        },
 
    };
 
    var postData = postData;
 
    var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
 
};
 

	
 

	
rhodecode/templates/changeset/changeset.html
Show inline comments
 
@@ -149,15 +149,26 @@
 
            <strong>Leave a comment</strong>
 
            <div class="clearfix">
 
                <div class="comment-help">${_('Comments parsed using RST syntax')}</div>
 
                    ${h.textarea('text')}
 
            </div>
 
            <div class="comment-button">
 
            ${h.submit('save', _('Comment'), class_='ui-button')}
 
            </div>
 
            ${h.end_form()}
 
        </div>
 
        %endif
 
    </div>
 
    <script type="text/javascript">
 
      var deleteComment = function(comment_id){
 
    
 
          var url = "${url('changeset_comment_delete',repo_name=c.repo_name,comment_id='__COMMENT_ID__')}".replace('__COMMENT_ID__',comment_id);
 
          var postData = '_method=delete';
 
          var success = function(o){
 
              var n = YUD.get('comment-'+comment_id);
 
              n.parentNode.removeChild(n);
 
          }
 
          ajaxPOST(url,postData,success);
 
      } 
 
    </script> 
 
  </div>	
 
</%def>
rhodecode/templates/changeset/changeset_file_comment.html
Show inline comments
 
@@ -13,19 +13,19 @@
 
  		${h.short_id(co.commit_id)}
 
  		%if co.f_path:
 
  			${_(' in file ')}
 
  			${co.f_path}:L${co.line_no}
 
  		%endif
 
  		<span class="date">
 
  			${h.age(co.modified_at)}
 
  		</span>
 
  	</div>
 
  	<div class="text">
 
  		%if h.HasPermissionAny('hg.admin', 'repository.admin')() or co.author.user_id == c.rhodecode_user.user_id:
 
  			<div class="buttons">
 
  				<a href="javascript:void(0);" onClick="deleteComment(${co.comment_id})" class="">${_('Delete')}</a>
 
  				<span onClick="deleteComment(${co.comment_id})" class="delete-comment ui-button-small">${_('Delete')}</span>
 
  			</div>
 
  		%endif
 
  		${h.rst(co.text)|n}
 
  	</div>
 
  </div>
 
</%def>
 
\ No newline at end of file
0 comments (0 inline, 0 general)