def edit_form(self, gist_id, format='html'): """GET /admin/gists/gist_id/edit: Form to edit an existing item""" # url('edit_gist', gist_id=ID) self._add_gist_to_context(gist_id) owner = c.gist.gist_owner == c.rhodecode_user.user_id if not (h.HasPermissionAny('hg.admin')() or owner): raise HTTPForbidden() try: c.file_last_commit, c.files = GistModel().get_gist_files(gist_id) except VCSError: log.exception("Exception in gist edit") raise HTTPNotFound() if c.gist.gist_expires == -1: expiry = _('never') else: # this cannot use timeago, since it's used in select2 as a value expiry = h.age(h.time_to_datetime(c.gist.gist_expires)) self.__load_defaults(extra_values=('0', _('%(expiry)s - current value') % { 'expiry': expiry })) return render('admin/gists/edit.html')
def delete_home(self, repo_name, revision, f_path): commit_id = revision repo = c.rhodecode_db_repo if repo.enable_locking and repo.locked[0]: h.flash( _('This repository has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.format_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect( h.url('files_home', repo_name=repo_name, revision='tip')) if not self._is_valid_head(commit_id, repo.scm_instance()): h.flash(_('You can only delete files with revision ' 'being a valid branch '), category='warning') return redirect( h.url('files_home', repo_name=repo_name, revision='tip', f_path=f_path)) c.commit = self.__get_commit_or_redirect(commit_id, repo_name) c.file = self.__get_filenode_or_redirect(repo_name, c.commit, f_path) c.default_message = _('Deleted file %s via RhodeCode Enterprise') % ( f_path) c.f_path = f_path return render('files/files_delete.html')
def add(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name, redirect_after=False) if c.cs is None: c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias) c.f_path = f_path if r_post: unix_mode = 0 content = convert_line_endings(r_post.get('content'), unix_mode) message = r_post.get('message') or (_('Added %s via RhodeCode') % (f_path)) location = r_post.get('location') filename = r_post.get('filename') file_obj = r_post.get('upload_file', None) if file_obj is not None and hasattr(file_obj, 'filename'): filename = file_obj.filename content = file_obj.file node_path = os.path.join(location, filename) author = self.rhodecode_user.full_contact if not content: h.flash(_('No content'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) if not filename: h.flash(_('No filename'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) try: self.scm_model.create_node(repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, user=self.rhodecode_user, author=author, message=message, content=content, f_path=node_path) h.flash(_('Successfully committed to %s') % node_path, category='success') except NodeAlreadyExistsError, e: h.flash(_(e), category='error') except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during commit'), category='error')
def edit(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name) c.file = self.__get_filenode_or_redirect(repo_name, c.cs, f_path) if c.file.is_binary: return redirect(url('files_home', repo_name=c.repo_name, revision=c.cs.raw_id, f_path=f_path)) c.f_path = f_path if r_post: old_content = c.file.content sl = old_content.splitlines(1) first_line = sl[0] if sl else '' # modes: 0 - Unix, 1 - Mac, 2 - DOS mode = detect_mode(first_line, 0) content = convert_line_endings(r_post.get('content'), mode) message = r_post.get('message') or (_('Edited %s via RhodeCode') % (f_path)) author = self.rhodecode_user.full_contact if content == old_content: h.flash(_('No changes'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) try: self.scm_model.commit_change(repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, user=self.rhodecode_user, author=author, message=message, content=content, f_path=f_path) h.flash(_('Successfully committed to %s') % f_path, category='success') except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during commit'), category='error') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) return render('files/files_edit.html')
def delete(self, repo_name, revision, f_path): commit_id = revision repo = c.rhodecode_db_repo if repo.enable_locking and repo.locked[0]: h.flash( _('This repository has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.format_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect( h.url('files_home', repo_name=repo_name, revision='tip')) if not self._is_valid_head(commit_id, repo.scm_instance()): h.flash(_('You can only delete files with revision ' 'being a valid branch '), category='warning') return redirect( h.url('files_home', repo_name=repo_name, revision='tip', f_path=f_path)) c.commit = self.__get_commit_or_redirect(commit_id, repo_name) c.file = self.__get_filenode_or_redirect(repo_name, c.commit, f_path) c.default_message = _('Deleted file %s via RhodeCode Enterprise') % ( f_path) c.f_path = f_path node_path = f_path author = c.rhodecode_user.full_contact message = request.POST.get('message') or c.default_message try: nodes = {node_path: {'content': ''}} self.scm_model.delete_nodes( user=c.rhodecode_user.user_id, repo=c.rhodecode_db_repo, message=message, nodes=nodes, parent_commit=c.commit, author=author, ) h.flash(_('Successfully deleted file %s') % f_path, category='success') except Exception: msg = _('Error occurred during commit') log.exception(msg) h.flash(msg, category='error') return redirect( url('changeset_home', repo_name=c.repo_name, revision='tip'))
def statistics(self): stats = [{ 'key': _('Index Type'), 'value': 'Whoosh' }, { 'key': _('File Index'), 'value': str(self.file_index) }, { 'key': _('Indexed documents'), 'value': self.file_index.doc_count() }, { 'key': _('Last update'), 'value': h.time_to_datetime(self.file_index.last_modified()) }, { 'key': _('Commit index'), 'value': str(self.commit_index) }, { 'key': _('Indexed documents'), 'value': str(self.commit_index.doc_count()) }, { 'key': _('Last update'), 'value': h.time_to_datetime(self.commit_index.last_modified()) }] return stats
def test_index(self, create_gist): self.log_user() g1 = create_gist('gist1') g2 = create_gist('gist2', lifetime=1400) g3 = create_gist('gist3', description='gist3-desc') g4 = create_gist('gist4', gist_type='private').gist_access_id response = self.app.get(url('gists')) response.mustcontain('gist: %s' % g1.gist_access_id) response.mustcontain('gist: %s' % g2.gist_access_id) response.mustcontain('gist: %s' % g3.gist_access_id) response.mustcontain('gist3-desc') response.mustcontain(no=['gist: %s' % g4]) # Expiration information should be visible expires_tag = '%s' % h.age_component( h.time_to_datetime(g2.gist_expires)) response.mustcontain(expires_tag.replace('"', '\\"'))
def add_home(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash( _('This repository has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.format_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect( h.url('files_home', repo_name=repo_name, revision='tip')) c.commit = self.__get_commit_or_redirect(revision, repo_name, redirect_after=False) if c.commit is None: c.commit = EmptyCommit(alias=c.rhodecode_repo.alias) c.default_message = (_('Added file via RhodeCode Enterprise')) c.f_path = f_path return render('files/files_add.html')
def add(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name, redirect_after=False) if c.cs is None: c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias) c.default_message = (_('Added file via RhodeCode')) c.f_path = f_path if r_post: unix_mode = 0 content = convert_line_endings(r_post.get('content'), unix_mode) message = r_post.get('message') or c.default_message filename = r_post.get('filename') location = r_post.get('location') file_obj = r_post.get('upload_file', None) if file_obj is not None and hasattr(file_obj, 'filename'): filename = file_obj.filename content = file_obj.file if not content: h.flash(_('No content'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) if not filename: h.flash(_('No filename'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) if location.startswith('/') or location.startswith('.') or '../' in location: h.flash(_('Location must be relative path and must not ' 'contain .. in path'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) if location: location = os.path.normpath(location) filename = os.path.basename(filename) node_path = os.path.join(location, filename) author = self.rhodecode_user.full_contact try: self.scm_model.create_node(repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, user=self.rhodecode_user.user_id, author=author, message=message, content=content, f_path=node_path) h.flash(_('Successfully committed to %s') % node_path, category='success') except (NodeError, NodeAlreadyExistsError), e: h.flash(_(e), category='error') except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during commit'), category='error')
def edit(self, repo_name, revision, f_path): repo = c.rhodecode_db_repo if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) # check if revision is a branch identifier- basically we cannot # create multiple heads via file editing _branches = repo.scm_instance.branches # check if revision is a branch name or branch hash if revision not in _branches.keys() + _branches.values(): h.flash(_('You can only edit files with revision ' 'being a valid branch '), category='warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip', f_path=f_path)) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name) c.file = self.__get_filenode_or_redirect(repo_name, c.cs, f_path) if c.file.is_binary: return redirect(url('files_home', repo_name=c.repo_name, revision=c.cs.raw_id, f_path=f_path)) c.default_message = _('Edited file %s via RhodeCode') % (f_path) c.f_path = f_path if r_post: old_content = c.file.content sl = old_content.splitlines(1) first_line = sl[0] if sl else '' # modes: 0 - Unix, 1 - Mac, 2 - DOS mode = detect_mode(first_line, 0) content = convert_line_endings(r_post.get('content'), mode) message = r_post.get('message') or c.default_message author = self.rhodecode_user.full_contact if content == old_content: h.flash(_('No changes'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) try: self.scm_model.commit_change(repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, user=self.rhodecode_user.user_id, author=author, message=message, content=content, f_path=f_path) h.flash(_('Successfully committed to %s') % f_path, category='success') except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during commit'), category='error') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) return render('files/files_edit.html')
def edit(self, repo_name, revision, f_path): commit_id = revision repo = c.rhodecode_db_repo if repo.enable_locking and repo.locked[0]: h.flash( _('This repository has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.format_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect( h.url('files_home', repo_name=repo_name, revision='tip')) if not self._is_valid_head(commit_id, repo.scm_instance()): h.flash(_('You can only edit files with revision ' 'being a valid branch '), category='warning') return redirect( h.url('files_home', repo_name=repo_name, revision='tip', f_path=f_path)) c.commit = self.__get_commit_or_redirect(commit_id, repo_name) c.file = self.__get_filenode_or_redirect(repo_name, c.commit, f_path) if c.file.is_binary: return redirect( url('files_home', repo_name=c.repo_name, revision=c.commit.raw_id, f_path=f_path)) c.default_message = _('Edited file %s via RhodeCode Enterprise') % ( f_path) c.f_path = f_path old_content = c.file.content sl = old_content.splitlines(1) first_line = sl[0] if sl else '' # modes: 0 - Unix, 1 - Mac, 2 - DOS mode = detect_mode(first_line, 0) content = convert_line_endings(request.POST.get('content', ''), mode) message = request.POST.get('message') or c.default_message org_f_path = c.file.unicode_path filename = request.POST['filename'] org_filename = c.file.name if content == old_content and filename == org_filename: h.flash(_('No changes'), category='warning') return redirect( url('changeset_home', repo_name=c.repo_name, revision='tip')) try: mapping = { org_f_path: { 'org_filename': org_f_path, 'filename': os.path.join(c.file.dir_path, filename), 'content': content, 'lexer': '', 'op': 'mod', } } ScmModel().update_nodes( user=c.rhodecode_user.user_id, repo=c.rhodecode_db_repo, message=message, nodes=mapping, parent_commit=c.commit, ) h.flash(_('Successfully committed to %s') % f_path, category='success') except Exception: msg = _('Error occurred during commit') log.exception(msg) h.flash(msg, category='error') return redirect( url('changeset_home', repo_name=c.repo_name, revision='tip'))
def add(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash( _('This repository has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.format_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect( h.url('files_home', repo_name=repo_name, revision='tip')) r_post = request.POST c.commit = self.__get_commit_or_redirect(revision, repo_name, redirect_after=False) if c.commit is None: c.commit = EmptyCommit(alias=c.rhodecode_repo.alias) c.default_message = (_('Added file via RhodeCode Enterprise')) c.f_path = f_path unix_mode = 0 content = convert_line_endings(r_post.get('content', ''), unix_mode) message = r_post.get('message') or c.default_message filename = r_post.get('filename') location = r_post.get('location', '') # dir location file_obj = r_post.get('upload_file', None) if file_obj is not None and hasattr(file_obj, 'filename'): filename = file_obj.filename content = file_obj.file if hasattr(content, 'file'): # non posix systems store real file under file attr content = content.file # If there's no commit, redirect to repo summary if type(c.commit) is EmptyCommit: redirect_url = "summary_home" else: redirect_url = "changeset_home" if not filename: h.flash(_('No filename'), category='warning') return redirect( url(redirect_url, repo_name=c.repo_name, revision='tip')) # extract the location from filename, # allows using foo/bar.txt syntax to create subdirectories subdir_loc = filename.rsplit('/', 1) if len(subdir_loc) == 2: location = os.path.join(location, subdir_loc[0]) # strip all crap out of file, just leave the basename filename = os.path.basename(filename) node_path = os.path.join(location, filename) author = c.rhodecode_user.full_contact try: nodes = {node_path: {'content': content}} self.scm_model.create_nodes( user=c.rhodecode_user.user_id, repo=c.rhodecode_db_repo, message=message, nodes=nodes, parent_commit=c.commit, author=author, ) h.flash(_('Successfully committed to %s') % node_path, category='success') except NonRelativePathError as e: h.flash(_( 'The location specified must be a relative path and must not ' 'contain .. in the path'), category='warning') return redirect( url('changeset_home', repo_name=c.repo_name, revision='tip')) except (NodeError, NodeAlreadyExistsError) as e: h.flash(_(e), category='error') except Exception: msg = _('Error occurred during commit') log.exception(msg) h.flash(msg, category='error') return redirect( url('changeset_home', repo_name=c.repo_name, revision='tip'))
def add(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash( _('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect( h.url('files_home', repo_name=repo_name, revision='tip')) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name, redirect_after=False) if c.cs is None: c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias) c.default_message = (_('Added file via RhodeCode')) c.f_path = f_path if r_post: unix_mode = 0 content = convert_line_endings(r_post.get('content', ''), unix_mode) message = r_post.get('message') or c.default_message filename = r_post.get('filename') location = r_post.get('location', '') file_obj = r_post.get('upload_file', None) if file_obj is not None and hasattr(file_obj, 'filename'): filename = file_obj.filename content = file_obj.file if hasattr(content, 'file'): # non posix systems store real file under file attr content = content.file if not content: h.flash(_('No content'), category='warning') return redirect( url('changeset_home', repo_name=c.repo_name, revision='tip')) if not filename: h.flash(_('No filename'), category='warning') return redirect( url('changeset_home', repo_name=c.repo_name, revision='tip')) #strip all crap out of file, just leave the basename filename = os.path.basename(filename) node_path = os.path.join(location, filename) author = self.rhodecode_user.full_contact try: nodes = {node_path: {'content': content}} self.scm_model.create_nodes( user=c.rhodecode_user.user_id, repo=c.rhodecode_db_repo, message=message, nodes=nodes, parent_cs=c.cs, author=author, ) h.flash(_('Successfully committed to %s') % node_path, category='success') except NonRelativePathError, e: h.flash(_('Location must be relative path and must not ' 'contain .. in path'), category='warning') return redirect( url('changeset_home', repo_name=c.repo_name, revision='tip')) except (NodeError, NodeAlreadyExistsError), e: h.flash(_(e), category='error')
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 add(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash( _("This repository is has been locked by %s on %s") % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), "warning", ) return redirect(h.url("files_home", repo_name=repo_name, revision="tip")) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name, redirect_after=False) if c.cs is None: c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias) c.default_message = _("Added file via RhodeCode") c.f_path = f_path if r_post: unix_mode = 0 content = convert_line_endings(r_post.get("content"), unix_mode) message = r_post.get("message") or c.default_message filename = r_post.get("filename") location = r_post.get("location") file_obj = r_post.get("upload_file", None) if file_obj is not None and hasattr(file_obj, "filename"): filename = file_obj.filename content = file_obj.file if not content: h.flash(_("No content"), category="warning") return redirect(url("changeset_home", repo_name=c.repo_name, revision="tip")) if not filename: h.flash(_("No filename"), category="warning") return redirect(url("changeset_home", repo_name=c.repo_name, revision="tip")) if location.startswith("/") or location.startswith(".") or "../" in location: h.flash(_("Location must be relative path and must not " "contain .. in path"), category="warning") return redirect(url("changeset_home", repo_name=c.repo_name, revision="tip")) if location: location = os.path.normpath(location) filename = os.path.basename(filename) node_path = os.path.join(location, filename) author = self.rhodecode_user.full_contact try: self.scm_model.create_node( repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, user=self.rhodecode_user.user_id, author=author, message=message, content=content, f_path=node_path, ) h.flash(_("Successfully committed to %s") % node_path, category="success") except (NodeError, NodeAlreadyExistsError), e: h.flash(_(e), category="error") except Exception: log.error(traceback.format_exc()) h.flash(_("Error occurred during commit"), category="error")
def settings_system(self): """GET /admin/settings/system: All items in the collection""" # url('admin_settings_system') snapshot = str2bool(request.GET.get('snapshot')) c.active = 'system' defaults = self._form_defaults() c.rhodecode_ini = rhodecode.CONFIG c.rhodecode_update_url = defaults.get('rhodecode_update_url') server_info = ScmModel().get_server_info(request.environ) for key, val in server_info.iteritems(): setattr(c, key, val) if c.disk['percent'] > 90: h.flash( h.literal( _('Critical: your disk space is very low <b>%s%%</b> used' % c.disk['percent'])), 'error') elif c.disk['percent'] > 70: h.flash( h.literal( _('Warning: your disk space is running low <b>%s%%</b> used' % c.disk['percent'])), 'warning') try: c.uptime_age = h._age(h.time_to_datetime(c.boot_time), False, show_suffix=False) except TypeError: c.uptime_age = c.boot_time try: c.system_memory = '%s/%s, %s%% (%s%%) used%s' % ( h.format_byte_size_binary(c.memory['used']), h.format_byte_size_binary(c.memory['total']), c.memory['percent2'], c.memory['percent'], ' %s' % c.memory['error'] if 'error' in c.memory else '') except TypeError: c.system_memory = 'NOT AVAILABLE' rhodecode_ini_safe = rhodecode.CONFIG.copy() blacklist = [ 'rhodecode_license_key', 'routes.map', 'pylons.h', 'pylons.app_globals', 'pylons.environ_config', 'sqlalchemy.db1.url', ('app_conf', 'sqlalchemy.db1.url') ] for k in blacklist: if isinstance(k, tuple): section, key = k if section in rhodecode_ini_safe: rhodecode_ini_safe[section].pop(key, None) else: rhodecode_ini_safe.pop(k, None) c.rhodecode_ini_safe = rhodecode_ini_safe # TODO: marcink, figure out how to allow only selected users to do this c.allowed_to_snapshot = False if snapshot: if c.allowed_to_snapshot: return render('admin/settings/settings_system_snapshot.html') else: h.flash('You are not allowed to do this', category='warning') return htmlfill.render(render('admin/settings/settings.html'), defaults=defaults, encoding="UTF-8", force_defaults=False)
def add(self, repo_name, revision, f_path): repo = Repository.get_by_repo_name(repo_name) if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name, redirect_after=False) if c.cs is None: c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias) c.default_message = (_('Added file via RhodeCode')) c.f_path = f_path if r_post: unix_mode = 0 content = convert_line_endings(r_post.get('content', ''), unix_mode) message = r_post.get('message') or c.default_message filename = r_post.get('filename') location = r_post.get('location', '') file_obj = r_post.get('upload_file', None) if file_obj is not None and hasattr(file_obj, 'filename'): filename = file_obj.filename content = file_obj.file if hasattr(content, 'file'): # non posix systems store real file under file attr content = content.file if not content: h.flash(_('No content'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) if not filename: h.flash(_('No filename'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) #strip all crap out of file, just leave the basename filename = os.path.basename(filename) node_path = os.path.join(location, filename) author = self.rhodecode_user.full_contact try: nodes = { node_path: { 'content': content } } self.scm_model.create_nodes( user=c.rhodecode_user.user_id, repo=c.rhodecode_db_repo, message=message, nodes=nodes, parent_cs=c.cs, author=author, ) h.flash(_('Successfully committed to %s') % node_path, category='success') except NonRelativePathError, e: h.flash(_('Location must be relative path and must not ' 'contain .. in path'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) except (NodeError, NodeAlreadyExistsError), e: h.flash(_(e), category='error')
def edit(self, repo_name, revision, f_path): repo = c.rhodecode_db_repo if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), h.fmt_date(h.time_to_datetime(repo.locked[1]))), 'warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) # check if revision is a branch identifier- basically we cannot # create multiple heads via file editing _branches = repo.scm_instance.branches # check if revision is a branch name or branch hash if revision not in _branches.keys() + _branches.values(): h.flash(_('You can only edit files with revision ' 'being a valid branch '), category='warning') return redirect(h.url('files_home', repo_name=repo_name, revision='tip', f_path=f_path)) r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name) c.file = self.__get_filenode_or_redirect(repo_name, c.cs, f_path) if c.file.is_binary: return redirect(url('files_home', repo_name=c.repo_name, revision=c.cs.raw_id, f_path=f_path)) c.default_message = _('Edited file %s via RhodeCode') % (f_path) c.f_path = f_path if r_post: old_content = c.file.content sl = old_content.splitlines(1) first_line = sl[0] if sl else '' # modes: 0 - Unix, 1 - Mac, 2 - DOS mode = detect_mode(first_line, 0) content = convert_line_endings(r_post.get('content', ''), mode) message = r_post.get('message') or c.default_message author = self.rhodecode_user.full_contact if content == old_content: h.flash(_('No changes'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) try: self.scm_model.commit_change(repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, user=self.rhodecode_user.user_id, author=author, message=message, content=content, f_path=f_path) h.flash(_('Successfully committed to %s') % f_path, category='success') except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during commit'), category='error') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) return render('files/files_edit.html')