Show More
@@ -1,4 +1,4 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
1 | ||
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2014-2020 RhodeCode GmbH |
|
4 | 4 | # |
@@ -28,7 +28,7 b' import logging' | |||
|
28 | 28 | from rhodecode.api.exc import JSONRPCError |
|
29 | 29 | from rhodecode.lib.auth import ( |
|
30 | 30 | HasPermissionAnyApi, HasRepoPermissionAnyApi, HasRepoGroupPermissionAnyApi) |
|
31 |
from rhodecode.lib.utils import safe_ |
|
|
31 | from rhodecode.lib.str_utils import safe_str | |
|
32 | 32 | from rhodecode.lib.vcs.exceptions import RepositoryError |
|
33 | 33 | from rhodecode.lib.view_utils import get_commit_from_ref_name |
|
34 | 34 | from rhodecode.lib.utils2 import str2bool |
@@ -368,7 +368,7 b' def build_commit_data(rhodecode_vcs_repo' | |||
|
368 | 368 | from rhodecode.lib import diffs |
|
369 | 369 | |
|
370 | 370 | _diff = rhodecode_vcs_repo.get_diff(commit1, commit2,) |
|
371 | diff_processor = diffs.DiffProcessor(_diff, format='newdiff', show_full_diff=True) | |
|
371 | diff_processor = diffs.DiffProcessor(_diff, diff_format='newdiff', show_full_diff=True) | |
|
372 | 372 | |
|
373 | 373 | for dp in diff_processor.prepare(): |
|
374 | 374 | del dp['stats']['ops'] |
@@ -446,7 +446,7 b' def _get_commit_dict(' | |||
|
446 | 446 | "deleted": None |
|
447 | 447 | } |
|
448 | 448 | return { |
|
449 |
"filename": safe_ |
|
|
449 | "filename": safe_str(filename), | |
|
450 | 450 | "op": op, |
|
451 | 451 | |
|
452 | 452 | # extra details |
@@ -1,4 +1,4 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
1 | ||
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2011-2020 RhodeCode GmbH |
|
4 | 4 | # |
@@ -48,14 +48,16 b' def get_gist(request, apiuser, gistid, c' | |||
|
48 | 48 | |
|
49 | 49 | gist = get_gist_or_error(gistid) |
|
50 | 50 | content = Optional.extract(content) |
|
51 | ||
|
51 | 52 | if not has_superadmin_permission(apiuser): |
|
52 | 53 | if gist.gist_owner != apiuser.user_id: |
|
53 | 54 | raise JSONRPCError('gist `%s` does not exist' % (gistid,)) |
|
54 | 55 | data = gist.get_api_data() |
|
56 | ||
|
55 | 57 | if content: |
|
56 | 58 | from rhodecode.model.gist import GistModel |
|
57 | 59 | rev, gist_files = GistModel().get_gist_files(gistid) |
|
58 | data['content'] = dict([(x.path, x.content) for x in gist_files]) | |
|
60 | data['content'] = dict([(x.path, x.str_content) for x in gist_files]) | |
|
59 | 61 | return data |
|
60 | 62 | |
|
61 | 63 |
@@ -1,4 +1,4 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
1 | ||
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2011-2020 RhodeCode GmbH |
|
4 | 4 | # |
@@ -525,9 +525,7 b' def comment_pull_request(' | |||
|
525 | 525 | raise JSONRPCError('userid is not the same as your user') |
|
526 | 526 | |
|
527 | 527 | if pull_request.is_closed(): |
|
528 | raise JSONRPCError( | |
|
529 | 'pull request `%s` comment failed, pull request is closed' % ( | |
|
530 | pullrequestid,)) | |
|
528 | raise JSONRPCError(f'pull request `{pullrequestid}` comment failed, pull request is closed') | |
|
531 | 529 | |
|
532 | 530 | if not PullRequestModel().check_user_read( |
|
533 | 531 | pull_request, apiuser, api=True): |
@@ -545,34 +543,29 b' def comment_pull_request(' | |||
|
545 | 543 | 'Both message and status parameters are missing. ' |
|
546 | 544 | 'At least one is required.') |
|
547 | 545 | |
|
548 |
if |
|
|
549 | status is not None): | |
|
550 | raise JSONRPCError('Unknown comment status: `%s`' % status) | |
|
546 | if status and status not in (st[0] for st in ChangesetStatus.STATUSES): | |
|
547 | raise JSONRPCError(f'Unknown comment status: `{status}`') | |
|
551 | 548 | |
|
552 | 549 | if commit_id and commit_id not in pull_request.revisions: |
|
553 | raise JSONRPCError( | |
|
554 | 'Invalid commit_id `%s` for this pull request.' % commit_id) | |
|
550 | raise JSONRPCError(f'Invalid commit_id `{commit_id}` for this pull request.') | |
|
555 | 551 | |
|
556 | 552 | allowed_to_change_status = PullRequestModel().check_user_change_status( |
|
557 | 553 | pull_request, apiuser) |
|
558 | 554 | |
|
559 | 555 | # if commit_id is passed re-validated if user is allowed to change status |
|
560 | # based on latest commit_id from the PR | |
|
556 | # based on the latest commit_id from the PR | |
|
561 | 557 | if commit_id: |
|
562 | 558 | commit_idx = pull_request.revisions.index(commit_id) |
|
563 | 559 | if commit_idx != 0: |
|
560 | log.warning('Resetting allowed_to_change_status = False because commit is NOT the latest in pull-request') | |
|
564 | 561 | allowed_to_change_status = False |
|
565 | 562 | |
|
566 | 563 | if resolves_comment_id: |
|
567 | 564 | comment = ChangesetComment.get(resolves_comment_id) |
|
568 | 565 | if not comment: |
|
569 | raise JSONRPCError( | |
|
570 | 'Invalid resolves_comment_id `%s` for this pull request.' | |
|
571 | % resolves_comment_id) | |
|
566 | raise JSONRPCError(f'Invalid resolves_comment_id `{resolves_comment_id}` for this pull request.') | |
|
572 | 567 | if comment.comment_type != ChangesetComment.COMMENT_TYPE_TODO: |
|
573 | raise JSONRPCError( | |
|
574 | 'Comment `%s` is wrong type for setting status to resolved.' | |
|
575 | % resolves_comment_id) | |
|
568 | raise JSONRPCError(f'Comment `{resolves_comment_id}` is wrong type for setting status to resolved.') | |
|
576 | 569 | |
|
577 | 570 | text = message |
|
578 | 571 | status_label = ChangesetStatus.get_status_lbl(status) |
@@ -602,6 +595,7 b' def comment_pull_request(' | |||
|
602 | 595 | extra_recipients=extra_recipients, |
|
603 | 596 | send_email=send_email |
|
604 | 597 | ) |
|
598 | ||
|
605 | 599 | is_inline = comment.is_inline |
|
606 | 600 | |
|
607 | 601 | if allowed_to_change_status and status: |
@@ -648,6 +642,7 b' def comment_pull_request(' | |||
|
648 | 642 | |
|
649 | 643 | return data |
|
650 | 644 | |
|
645 | ||
|
651 | 646 | def _reviewers_validation(obj_list): |
|
652 | 647 | schema = ReviewerListSchema() |
|
653 | 648 | try: |
@@ -1,4 +1,4 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
1 | ||
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2011-2020 RhodeCode GmbH |
|
4 | 4 | # |
@@ -36,7 +36,7 b' from rhodecode.lib.auth import (' | |||
|
36 | 36 | HasRepoPermissionAnyApi) |
|
37 | 37 | from rhodecode.lib.celerylib.utils import get_task_id |
|
38 | 38 | from rhodecode.lib.utils2 import ( |
|
39 |
str2bool, time_to_datetime, safe_str, safe_int |
|
|
39 | str2bool, time_to_datetime, safe_str, safe_int) | |
|
40 | 40 | from rhodecode.lib.ext_json import json |
|
41 | 41 | from rhodecode.lib.exceptions import ( |
|
42 | 42 | StatusChangeOnClosedPullRequestError, CommentVersionMismatch) |
@@ -204,6 +204,7 b' def get_repo(request, apiuser, repoid, c' | |||
|
204 | 204 | data = repo.get_api_data(include_secrets=include_secrets) |
|
205 | 205 | data['permissions'] = permissions |
|
206 | 206 | data['followers'] = following_users |
|
207 | ||
|
207 | 208 | return data |
|
208 | 209 | |
|
209 | 210 | |
@@ -474,7 +475,9 b' def get_repo_nodes(request, apiuser, rep' | |||
|
474 | 475 | |
|
475 | 476 | _extended_types = ['basic', 'full'] |
|
476 | 477 | if details not in _extended_types: |
|
477 |
r |
|
|
478 | ret_types = ','.join(_extended_types) | |
|
479 | raise JSONRPCError(f'ret_type must be one of {ret_types}') | |
|
480 | ||
|
478 | 481 | extended_info = False |
|
479 | 482 | content = False |
|
480 | 483 | if details == 'basic': |
@@ -500,20 +503,19 b' def get_repo_nodes(request, apiuser, rep' | |||
|
500 | 503 | 'files': _f, |
|
501 | 504 | 'dirs': _d, |
|
502 | 505 | } |
|
506 | ||
|
503 | 507 | return _map[ret_type] |
|
504 | 508 | except KeyError: |
|
505 | raise JSONRPCError( | |
|
506 | 'ret_type must be one of %s' % (','.join(sorted(_map.keys())))) | |
|
509 | keys = ','.join(sorted(_map.keys())) | |
|
510 | raise JSONRPCError(f'ret_type must be one of {keys}') | |
|
507 | 511 | except Exception: |
|
508 | 512 | log.exception("Exception occurred while trying to get repo nodes") |
|
509 | raise JSONRPCError( | |
|
510 | 'failed to get repo: `%s` nodes' % repo.repo_name | |
|
511 | ) | |
|
513 | raise JSONRPCError(f'failed to get repo: `{repo.repo_name}` nodes') | |
|
512 | 514 | |
|
513 | 515 | |
|
514 | 516 | @jsonrpc_method() |
|
515 | 517 | def get_repo_file(request, apiuser, repoid, commit_id, file_path, |
|
516 |
max_file_bytes=Optional( |
|
|
518 | max_file_bytes=Optional(0), details=Optional('basic'), | |
|
517 | 519 | cache=Optional(True)): |
|
518 | 520 | """ |
|
519 | 521 | Returns a single file from repository at given revision. |
@@ -564,10 +566,12 b' def get_repo_file(request, apiuser, repo' | |||
|
564 | 566 | |
|
565 | 567 | cache = Optional.extract(cache, binary=True) |
|
566 | 568 | details = Optional.extract(details) |
|
569 | max_file_bytes = Optional.extract(max_file_bytes) | |
|
570 | ||
|
567 | 571 | _extended_types = ['minimal', 'minimal+search', 'basic', 'full'] |
|
568 | 572 | if details not in _extended_types: |
|
569 | raise JSONRPCError( | |
|
570 |
|
|
|
573 | ret_types = ','.join(_extended_types) | |
|
574 | raise JSONRPCError(f'ret_type must be one of %s, got {ret_types}', details) | |
|
571 | 575 | extended_info = False |
|
572 | 576 | content = False |
|
573 | 577 | |
@@ -580,7 +584,7 b' def get_repo_file(request, apiuser, repo' | |||
|
580 | 584 | elif details == 'full': |
|
581 | 585 | extended_info = content = True |
|
582 | 586 | |
|
583 |
file_path = safe_ |
|
|
587 | file_path = safe_str(file_path) | |
|
584 | 588 | try: |
|
585 | 589 | # check if repo is not empty by any chance, skip quicker if it is. |
|
586 | 590 | _scm = repo.scm_instance() |
@@ -590,14 +594,14 b' def get_repo_file(request, apiuser, repo' | |||
|
590 | 594 | node = ScmModel().get_node( |
|
591 | 595 | repo, commit_id, file_path, extended_info=extended_info, |
|
592 | 596 | content=content, max_file_bytes=max_file_bytes, cache=cache) |
|
597 | ||
|
593 | 598 | except NodeDoesNotExistError: |
|
594 | raise JSONRPCError(u'There is no file in repo: `{}` at path `{}` for commit: `{}`'.format( | |
|
595 | repo.repo_name, file_path, commit_id)) | |
|
599 | raise JSONRPCError( | |
|
600 | f'There is no file in repo: `{repo.repo_name}` at path `{file_path}` for commit: `{commit_id}`') | |
|
596 | 601 | except Exception: |
|
597 |
log.exception( |
|
|
602 | log.exception("Exception occurred while trying to get repo %s file", | |
|
598 | 603 | repo.repo_name) |
|
599 |
raise JSONRPCError( |
|
|
600 | repo.repo_name, file_path)) | |
|
604 | raise JSONRPCError(f'failed to get repo: `{repo.repo_name}` file at path {file_path}') | |
|
601 | 605 | |
|
602 | 606 | return node |
|
603 | 607 | |
@@ -619,11 +623,11 b' def get_repo_fts_tree(request, apiuser, ' | |||
|
619 | 623 | validate_repo_permissions(apiuser, repoid, repo, _perms) |
|
620 | 624 | |
|
621 | 625 | repo_id = repo.repo_id |
|
622 |
cache_seconds = |
|
|
626 | cache_seconds = rhodecode.ConfigGet().get_int('rc_cache.cache_repo.expiration_time') | |
|
623 | 627 | cache_on = cache_seconds > 0 |
|
624 | 628 | |
|
625 |
cache_namespace_uid = ' |
|
|
626 |
|
|
|
629 | cache_namespace_uid = 'repo.{}'.format(repo_id) | |
|
630 | rc_cache.get_or_create_region('cache_repo', cache_namespace_uid) | |
|
627 | 631 | |
|
628 | 632 | def compute_fts_tree(cache_ver, repo_id, commit_id, root_path): |
|
629 | 633 | return ScmModel().get_fts_data(repo_id, commit_id, root_path) |
@@ -631,11 +635,11 b' def get_repo_fts_tree(request, apiuser, ' | |||
|
631 | 635 | try: |
|
632 | 636 | # check if repo is not empty by any chance, skip quicker if it is. |
|
633 | 637 | _scm = repo.scm_instance() |
|
634 | if _scm.is_empty(): | |
|
638 | if not _scm or _scm.is_empty(): | |
|
635 | 639 | return [] |
|
636 | 640 | except RepositoryError: |
|
637 | 641 | log.exception("Exception occurred while trying to get repo nodes") |
|
638 |
raise JSONRPCError('failed to get repo: ` |
|
|
642 | raise JSONRPCError(f'failed to get repo: `{repo.repo_name}` nodes') | |
|
639 | 643 | |
|
640 | 644 | try: |
|
641 | 645 | # we need to resolve commit_id to a FULL sha for cache to work correctly. |
@@ -647,6 +651,7 b' def get_repo_fts_tree(request, apiuser, ' | |||
|
647 | 651 | repo_id, commit_id, cache_on, cache_seconds or 0)) |
|
648 | 652 | |
|
649 | 653 | tree_files = compute_fts_tree(rc_cache.FILE_TREE_CACHE_VER, repo_id, commit_id, root_path) |
|
654 | ||
|
650 | 655 | return tree_files |
|
651 | 656 | |
|
652 | 657 | except Exception: |
@@ -1869,7 +1874,11 b' def edit_comment(request, apiuser, messa' | |||
|
1869 | 1874 | raise JSONRPCError('userid is not the same as your user') |
|
1870 | 1875 | |
|
1871 | 1876 | comment_author = comment.author.user_id == auth_user.user_id |
|
1872 | if not (comment.immutable is False and (is_super_admin or is_repo_admin) or comment_author): | |
|
1877 | ||
|
1878 | if comment.immutable: | |
|
1879 | raise JSONRPCError("Immutable comment cannot be edited") | |
|
1880 | ||
|
1881 | if not (is_super_admin or is_repo_admin or comment_author): | |
|
1873 | 1882 | raise JSONRPCError("you don't have access to edit this comment") |
|
1874 | 1883 | |
|
1875 | 1884 | try: |
@@ -1,4 +1,4 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
1 | ||
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2011-2020 RhodeCode GmbH |
|
4 | 4 | # |
@@ -342,8 +342,9 b' def get_method(request, apiuser, pattern' | |||
|
342 | 342 | matches = find_methods(request.registry.jsonrpc_methods, pattern) |
|
343 | 343 | |
|
344 | 344 | args_desc = [] |
|
345 | if len(matches) == 1: | |
|
346 | func = matches[matches.keys()[0]] | |
|
345 | matches_keys = list(matches.keys()) | |
|
346 | if len(matches_keys) == 1: | |
|
347 | func = matches[matches_keys[0]] | |
|
347 | 348 | |
|
348 | 349 | argspec = inspect.getargspec(func) |
|
349 | 350 | arglist = argspec[0] |
@@ -356,7 +357,7 b' def get_method(request, apiuser, pattern' | |||
|
356 | 357 | reversed(arglist), reversed(defaults), fillvalue=default_empty)) |
|
357 | 358 | args_desc.append(func_kwargs) |
|
358 | 359 | |
|
359 |
return matches |
|
|
360 | return matches_keys + args_desc | |
|
360 | 361 | |
|
361 | 362 | |
|
362 | 363 | @jsonrpc_method() |
General Comments 0
You need to be logged in to leave comments.
Login now