def get_dirnode_metadata(self, commit, dir_node): if not dir_node.is_dir(): return [] data = [] for node in dir_node: if not node.is_file(): # we skip file-nodes continue last_commit = node.last_commit last_commit_date = last_commit.date data.append({ 'name': node.name, 'size': h.format_byte_size_binary(node.size), 'modified_at': h.format_date(last_commit_date), 'modified_ts': last_commit_date.isoformat(), 'revision': last_commit.revision, 'short_id': last_commit.short_id, 'message': h.escape(last_commit.message), 'author': h.escape(last_commit.author), 'user_profile': h.gravatar_with_user(last_commit.author), }) return data
def wrapped_diff(filenode_old, filenode_new, diff_limit=None, file_limit=None, show_full_diff=False, ignore_whitespace=True, line_context=3, enable_comments=False): """ returns a wrapped diff into a table, checks for cut_off_limit for file and whole diff and presents proper message """ if filenode_old is None: filenode_old = FileNode(filenode_new.path, '', EmptyCommit()) if filenode_old.is_binary or filenode_new.is_binary: diff = wrap_to_table(_('Binary file')) stats = None size = 0 data = None elif diff_limit != -1 and (diff_limit is None or (filenode_old.size < diff_limit and filenode_new.size < diff_limit)): f_gitdiff = get_gitdiff(filenode_old, filenode_new, ignore_whitespace=ignore_whitespace, context=line_context) diff_processor = DiffProcessor(f_gitdiff, format='gitdiff', diff_limit=diff_limit, file_limit=file_limit, show_full_diff=show_full_diff) _parsed = diff_processor.prepare() diff = diff_processor.as_html(enable_comments=enable_comments) stats = _parsed[0]['stats'] if _parsed else None size = len(diff or '') data = _parsed[0] if _parsed else None else: diff = wrap_to_table( _('Changeset was too big and was cut off, use ' 'diff menu to display this diff')) stats = None size = 0 data = None if not diff: submodules = filter(lambda o: isinstance(o, SubModuleNode), [filenode_new, filenode_old]) if submodules: diff = wrap_to_table(escape('Submodule %r' % submodules[0])) else: diff = wrap_to_table(_('No changes detected')) cs1 = filenode_old.commit.raw_id cs2 = filenode_new.commit.raw_id return size, cs1, cs2, diff, stats, data
def create(self): """POST /users: Create a new item""" # url('users') c.default_extern_type = auth_rhodecode.RhodeCodeAuthPlugin.name user_model = UserModel() user_form = UserForm()() try: form_result = user_form.to_python(dict(request.POST)) user = user_model.create(form_result) Session().flush() username = form_result['username'] action_logger(c.rhodecode_user, 'admin_created_user:%s' % username, None, self.ip_addr, self.sa) user_link = h.link_to(h.escape(username), url('edit_user', user_id=user.user_id)) h.flash(h.literal( _('Created user %(user_link)s') % {'user_link': user_link}), category='success') Session().commit() except formencode.Invalid as errors: return htmlfill.render(render('admin/users/user_add.html'), defaults=errors.value, errors=errors.error_dict or {}, prefix_error=False, encoding="UTF-8", force_defaults=False) except UserCreationError as e: h.flash(e, 'error') except Exception: log.exception("Exception creation of user") h.flash(_('Error occurred during creation of user %s') % request.POST.get('username'), category='error') return redirect(url('users'))
def index(self): """GET /users_groups: All items in the collection""" # url('users_groups') from rhodecode.lib.utils import PartialRenderer _render = PartialRenderer('data_table/_dt_elements.html') def user_group_name(user_group_id, user_group_name): return _render("user_group_name", user_group_id, user_group_name) def user_group_actions(user_group_id, user_group_name): return _render("user_group_actions", user_group_id, user_group_name) ## json generate group_iter = UserGroupList(UserGroup.query().all(), perm_set=['usergroup.admin']) user_groups_data = [] for user_gr in group_iter: user_groups_data.append({ "group_name": user_group_name(user_gr.users_group_id, h.escape(user_gr.users_group_name)), "group_name_raw": user_gr.users_group_name, "desc": h.escape(user_gr.user_group_description), "members": len(user_gr.members), "active": h.bool2icon(user_gr.users_group_active), "owner": h.escape(h.link_to_user(user_gr.user.username)), "action": user_group_actions(user_gr.users_group_id, user_gr.users_group_name) }) c.data = json.dumps(user_groups_data) return render('admin/user_groups/user_groups.html')
def wrapped_diff(filenode_old, filenode_new, cut_off_limit=None, ignore_whitespace=True, line_context=3, enable_comments=False): """ returns a wrapped diff into a table, checks for cut_off_limit and presents proper message """ if filenode_old is None: filenode_old = FileNode(filenode_new.path, '', EmptyChangeset()) if filenode_old.is_binary or filenode_new.is_binary: diff = wrap_to_table(_('binary file')) stats = (0, 0) size = 0 elif cut_off_limit != -1 and (cut_off_limit is None or (filenode_old.size < cut_off_limit and filenode_new.size < cut_off_limit)): f_gitdiff = get_gitdiff(filenode_old, filenode_new, ignore_whitespace=ignore_whitespace, context=line_context) diff_processor = DiffProcessor(f_gitdiff, format='gitdiff') diff = diff_processor.as_html(enable_comments=enable_comments) stats = diff_processor.stat() size = len(diff or '') else: diff = wrap_to_table( _('Changeset was to big and was cut off, use ' 'diff menu to display this diff')) stats = (0, 0) size = 0 if not diff: submodules = filter(lambda o: isinstance(o, SubModuleNode), [filenode_new, filenode_old]) if submodules: diff = wrap_to_table(escape('Submodule %r' % submodules[0])) else: diff = wrap_to_table(_('No changes detected')) cs1 = filenode_old.changeset.raw_id cs2 = filenode_new.changeset.raw_id return size, cs1, cs2, diff, stats
def wrapped_diff(filenode_old, filenode_new, cut_off_limit=None, ignore_whitespace=True, line_context=3, enable_comments=False): """ returns a wrapped diff into a table, checks for cut_off_limit and presents proper message """ if filenode_old is None: filenode_old = FileNode(filenode_new.path, '', EmptyChangeset()) if filenode_old.is_binary or filenode_new.is_binary: diff = wrap_to_table(_('Binary file')) stats = (0, 0) size = 0 elif cut_off_limit != -1 and (cut_off_limit is None or (filenode_old.size < cut_off_limit and filenode_new.size < cut_off_limit)): f_gitdiff = get_gitdiff(filenode_old, filenode_new, ignore_whitespace=ignore_whitespace, context=line_context) diff_processor = DiffProcessor(f_gitdiff, format='gitdiff') diff = diff_processor.as_html(enable_comments=enable_comments) stats = diff_processor.stat() size = len(diff or '') else: diff = wrap_to_table(_('Changeset was too big and was cut off, use ' 'diff menu to display this diff')) stats = (0, 0) size = 0 if not diff: submodules = filter(lambda o: isinstance(o, SubModuleNode), [filenode_new, filenode_old]) if submodules: diff = wrap_to_table(escape('Submodule %r' % submodules[0])) else: diff = wrap_to_table(_('No changes detected')) cs1 = filenode_old.changeset.raw_id cs2 = filenode_new.changeset.raw_id return size, cs1, cs2, diff, stats
def create(self): """POST /users_groups: Create a new item""" # url('users_groups') users_group_form = UserGroupForm()() try: form_result = users_group_form.to_python(dict(request.POST)) user_group = UserGroupModel().create( name=form_result['users_group_name'], description=form_result['user_group_description'], owner=c.rhodecode_user.user_id, active=form_result['users_group_active']) Session().flush() user_group_name = form_result['users_group_name'] action_logger(c.rhodecode_user, 'admin_created_users_group:%s' % user_group_name, None, self.ip_addr, self.sa) user_group_link = h.link_to( h.escape(user_group_name), url('edit_users_group', user_group_id=user_group.users_group_id)) h.flash(h.literal( _('Created user group %(user_group_link)s') % {'user_group_link': user_group_link}), category='success') Session().commit() except formencode.Invalid as errors: return htmlfill.render( render('admin/user_groups/user_group_add.html'), defaults=errors.value, errors=errors.error_dict or {}, prefix_error=False, encoding="UTF-8", force_defaults=False) except Exception: log.exception("Exception creating user group") h.flash(_('Error occurred during creation of user group %s') \ % request.POST.get('users_group_name'), category='error') return redirect( url('edit_users_group', user_group_id=user_group.users_group_id))
def index(self): """GET /users: All items in the collection""" # url('users') from rhodecode.lib.utils import PartialRenderer _render = PartialRenderer('data_table/_dt_elements.html') def grav_tmpl(user_email, size): return _render("user_gravatar", user_email, size) def username(user_id, username): return _render("user_name", user_id, username) def user_actions(user_id, username): return _render("user_actions", user_id, username) # json generate c.users_list = User.query()\ .filter(User.username != User.DEFAULT_USER) \ .all() users_data = [] for user in c.users_list: users_data.append({ "gravatar": grav_tmpl(user.email, 20), "username": h.link_to(user.username, h.url('user_profile', username=user.username)), "username_raw": user.username, "email": user.email, "first_name": h.escape(user.name), "last_name": h.escape(user.lastname), "last_login": h.format_date(user.last_login), "last_login_raw": datetime_to_time(user.last_login), "last_activity": h.format_date( h.time_to_datetime(user.user_data.get('last_activity', 0))), "last_activity_raw": user.user_data.get('last_activity', 0), "active": h.bool2icon(user.active), "active_raw": user.active, "admin": h.bool2icon(user.admin), "admin_raw": user.admin, "extern_type": user.extern_type, "extern_name": user.extern_name, "action": user_actions(user.user_id, user.username), }) c.data = json.dumps(users_data) return render('admin/users/users.html')
def index(self): """GET /admin/gists: All items in the collection""" # url('gists') not_default_user = c.rhodecode_user.username != User.DEFAULT_USER c.show_private = request.GET.get('private') and not_default_user c.show_public = request.GET.get('public') and not_default_user c.show_all = request.GET.get('all') and c.rhodecode_user.admin gists = _gists = Gist().query()\ .filter(or_(Gist.gist_expires == -1, Gist.gist_expires >= time.time()))\ .order_by(Gist.created_on.desc()) c.active = 'public' # MY private if c.show_private and not c.show_public: gists = _gists.filter(Gist.gist_type == Gist.GIST_PRIVATE)\ .filter(Gist.gist_owner == c.rhodecode_user.user_id) c.active = 'my_private' # MY public elif c.show_public and not c.show_private: gists = _gists.filter(Gist.gist_type == Gist.GIST_PUBLIC)\ .filter(Gist.gist_owner == c.rhodecode_user.user_id) c.active = 'my_public' # MY public+private elif c.show_private and c.show_public: gists = _gists.filter(or_(Gist.gist_type == Gist.GIST_PUBLIC, Gist.gist_type == Gist.GIST_PRIVATE))\ .filter(Gist.gist_owner == c.rhodecode_user.user_id) c.active = 'my_all' # Show all by super-admin elif c.show_all: c.active = 'all' gists = _gists # default show ALL public gists if not c.show_public and not c.show_private and not c.show_all: gists = _gists.filter(Gist.gist_type == Gist.GIST_PUBLIC) c.active = 'public' from rhodecode.lib.utils import PartialRenderer _render = PartialRenderer('data_table/_dt_elements.html') data = [] for gist in gists: data.append({ 'created_on': _render('gist_created', gist.created_on), 'created_on_raw': gist.created_on, 'type': _render('gist_type', gist.gist_type), 'access_id': _render('gist_access_id', gist.gist_access_id, gist.owner.full_contact), 'author': _render('gist_author', gist.owner.full_contact, gist.created_on, gist.gist_expires), 'author_raw': h.escape(gist.owner.full_contact), 'expires': _render('gist_expires', gist.gist_expires), 'description': _render('gist_description', gist.gist_description) }) c.data = json.dumps(data) return render('admin/gists/index.html')
def _get_pull_requests_list(self, repo_name, opened_by, statuses): # pagination start = safe_int(request.GET.get('start'), 0) length = safe_int(request.GET.get('length'), c.visual.dashboard_items) order_by, order_dir = self._extract_ordering(request) if c.awaiting_review: pull_requests = PullRequestModel().get_awaiting_review( repo_name, source=c.source, opened_by=opened_by, statuses=statuses, offset=start, length=length, order_by=order_by, order_dir=order_dir) pull_requests_total_count = PullRequestModel( ).count_awaiting_review(repo_name, source=c.source, statuses=statuses, opened_by=opened_by) elif c.awaiting_my_review: pull_requests = PullRequestModel().get_awaiting_my_review( repo_name, source=c.source, opened_by=opened_by, user_id=c.rhodecode_user.user_id, statuses=statuses, offset=start, length=length, order_by=order_by, order_dir=order_dir) pull_requests_total_count = PullRequestModel( ).count_awaiting_my_review(repo_name, source=c.source, user_id=c.rhodecode_user.user_id, statuses=statuses, opened_by=opened_by) else: pull_requests = PullRequestModel().get_all(repo_name, source=c.source, opened_by=opened_by, statuses=statuses, offset=start, length=length, order_by=order_by, order_dir=order_dir) pull_requests_total_count = PullRequestModel().count_all( repo_name, source=c.source, statuses=statuses, opened_by=opened_by) from rhodecode.lib.utils import PartialRenderer _render = PartialRenderer('data_table/_dt_elements.html') data = [] for pr in pull_requests: comments = ChangesetCommentsModel().get_all_comments( c.rhodecode_db_repo.repo_id, pull_request=pr) data.append({ 'name': _render('pullrequest_name', pr.pull_request_id, pr.target_repo.repo_name), 'name_raw': pr.pull_request_id, 'status': _render('pullrequest_status', pr.calculated_review_status()), 'title': _render('pullrequest_title', pr.title, pr.description), 'description': h.escape(pr.description), 'updated_on': _render('pullrequest_updated_on', h.datetime_to_time(pr.updated_on)), 'updated_on_raw': h.datetime_to_time(pr.updated_on), 'created_on': _render('pullrequest_updated_on', h.datetime_to_time(pr.created_on)), 'created_on_raw': h.datetime_to_time(pr.created_on), 'author': _render( 'pullrequest_author', pr.author.full_contact, ), 'author_raw': pr.author.full_name, 'comments': _render('pullrequest_comments', len(comments)), 'comments_raw': len(comments), 'closed': pr.is_closed(), }) # json used to render the grid data = ({ 'data': data, 'recordsTotal': pull_requests_total_count, 'recordsFiltered': pull_requests_total_count, }) return data