|
|
Mads Kiilerich
|
f2dc57c123cf
|
3 years ago
|
|
repo: introduce enable_downloads and enable_statistics when creating repos
These booleans were not shown in the normal repo creation form, so the form validation applied the "default" values of False. These values were however not used by the model when creating repos - it just unconditionally used the real global defaults.
The API already exposed some of this, but it wasn't implemented.
The web form for creating repos lacked these fields, but it was present in the repo edit form. Just make these fields mandatory. There will thus not be any defaults to apply in the model for creating repos.
|
|
|
Mads Kiilerich
|
1d3b67443aac
|
5 years ago
|
|
celery: move repo create tasks to repo model - that's where it belongs
Avoid bundling everything from many different layers in one big task library.
This is more feasible now when we don't need kallithea.CELERY_APP set at import time.
The whole thing about model classes and instantiation is just trouble - we will get rid of that soon.
|
|
|
Mads Kiilerich
|
a36a8804e7be
|
5 years ago
|
|
|
|
|
Mads Kiilerich
|
7c541dc095c8
|
5 years ago
|
|
lib: clean up pointless use of h.person on db.User just to get .username
After cleaning up, h.person will never be invoked with a db.User .
|
|
|
Mads Kiilerich
|
71a37439dcee
|
5 years ago
|
|
lib: move urlification to webutils
Less use of helpers in model.
|
|
|
Mads Kiilerich
|
341e4bb9e227
|
5 years ago
|
|
|
|
|
Mads Kiilerich
|
7b7afdbe57af
|
5 years ago
|
|
|
|
|
Mads Kiilerich
|
df930758dcf7
|
5 years ago
|
|
repos: extra HTML escaping of repo and repo group names shown in DataTables
These names will already have been "slugged" and can thus not contain anything that can be used for any attack. But let's be explicitly safe and escape them anyway.
raw_name without escaping would cause XSS *if* it was possible to create unsafe repo names.
just_name must be escaped in order to make search work correctly - for example if searching for '<' ... *if* it was possible for names to contain that.
|
|
|
Mads Kiilerich
|
cd8fa11c5c89
|
5 years ago
|
|
repogroups: fix HTML markup of descriptions Repogroup descriptions were not urlified like repo descriptions are. That caused incorrect rendering with posibility of XSS. The problem was introduced in 0.4.0 with 6db3122e4d75. Thanks to stypr of Flatt Security for reporting this vulnerability.
|
|
|
Thomas De Schampheleire
|
0b1a23b88f9a
|
5 years ago
|
|
cleanup: get rid of redundant assignments 'foo = foo' Redundant assignments were searched with: grep '^ *\(.*\) = \1$' `hg files` Some of these cases have resulted from earlier cleanup, like: foo = safe_unicode(foo) and later batch removing safe_unicode usage. See e.g. commit e35373106528b29461b7f5144780cb9ec79f765d . Note: two false positives occur: kallithea/tests/models/test_settings.py:39: setting.app_settings_value = setting.app_settings_value kallithea/tests/models/test_settings.py:42: setting.app_settings_value = setting.app_settings_value which is not a plain assignment but where 'app_settings_value' is a property method with side effects.
|
|
|
Mads Kiilerich
|
9b7c5d7ad1a2
|
5 years ago
|
|
hooks: import whole hooks module
Minimize impact if there should be cycles.
|
|
|
Mads Kiilerich
|
87c2cd07166a
|
5 years ago
|
|
|
|
|
Mads Kiilerich
|
c98c7d4c9ec3
|
5 years ago
|
|
model: changes toward import whole modules
*If* there should be circular dependencies, importing 'from' another module could fail because the module at that time only was partially imported. That had to be worked around by importing at runtime instead of globally.
Instead, try to always import whole modules. (But we should still try to avoid cycles.)
|
|
|
Mads Kiilerich
|
180effeba219
|
5 years ago
|
|
|
|
|
Mads Kiilerich
|
5e46f73f0d1c
|
5 years ago
|
|
|
|
|
Mads Kiilerich
|
dff9658bdd98
|
5 years ago
|
|
|
|
|
Mads Kiilerich
|
6fbbbd9a627a
|
5 years ago
|
|
db: move URL_SEP constant from db to top level kallithea module
URL_SEP is used in several places - having it in the db module is too high level.
__init__ might not be the best place for this, but it does no harm to the dependencies graph to place constants there.
|
|
|
Mads Kiilerich
|
1ecd6c0e2787
|
5 years ago
|
|
auth: refactor permissions
Avoid using complex vague typing in dict-of-dicts.
|
|
|
Mads Kiilerich
|
68eee0e7f4f5
|
5 years ago
|
|
isort: upgrade to 5.1.2
The changes to non-top-level imports seem nice.
|
|
|
Mads Kiilerich
|
eb486c0c3114
|
5 years ago
|
|
scm: refactor install_git_hooks
Rename, simplify, and negate some logic to make the flow more readable to me and give better logging.
For example, "force_create" were more about "force overwrite". Calling it "force" is more precise.
|
|
|
Mads Kiilerich
|
a67bcc6f9118
|
6 years ago
|
|
db: drop SA caching_query and FromCache, and thus sql_cache_short beaker cache
It is not a good idea to have dead ORM objects. If we want caching, we should do it explicit.
It is unknown how much this cache helps, but we can profile and introduce better caching of simple data where relevant.
|
|
|
Mads Kiilerich
|
6484a0fc0e0b
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
8c57eda0823e
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
5b1f43027662
|
6 years ago
|
|
scripts: drop isort --wrap-length 160 - it is broken with py3 and not really necessary Under Python 3, isort 4.3.21 failed with https://github.com/timothycrosley/isort/issues/741 on kallithea/controllers/api/api.py : Traceback (most recent call last): File "data/env/bin/isort", line 10, in <module> sys.exit(main()) File ".../env/lib64/python3.7/site-packages/isort/main.py", line 379, in main for sort_attempt in attempt_iterator: File ".../env/lib64/python3.7/site-packages/isort/main.py", line 377, in <genexpr> attempt_iterator = (sort_imports(file_name, **arguments) for file_name in file_names) File ".../env/lib64/python3.7/site-packages/isort/main.py", line 88, in sort_imports result = SortImports(file_name, **arguments) File ".../env/lib64/python3.7/site-packages/isort/isort.py", line 207, in __init__ self._add_formatted_imports() File ".../env/lib64/python3.7/site-packages/isort/isort.py", line 606, in _add_formatted_imports self._add_from_imports(from_modules, section, section_output, sort_ignore_case) File ".../env/lib64/python3.7/site-packages/isort/isort.py", line 526, in _add_from_imports import_statement = self._multi_line_reformat(import_start, from_import_section, comments) File ".../env/lib64/python3.7/site-packages/isort/isort.py", line 552, in _multi_line_reformat dynamic_indent, indent, line_length, comments) File ".../env/lib64/python3.7/site-packages/isort/isort.py", line 705, in _output_grid if len(next_statement.split(self.line_separator)[-1]) + 1 > line_length: TypeError: '>' not supported between instances of 'int' and 'str'
|
|
|
Mads Kiilerich
|
5725fa4cfecd
|
6 years ago
|
|
cleanup: minimize use of lambda expressions - we have 'def' for that purpose
Fix some flake8 warnings "E731 do not assign a lambda expression, use a def".
|
|
|
Ross Thomas
|
173612a900ef
|
6 years ago
|
|
ui: show toggleable "Follow" status in repo groups' repo list
It makes sense to show Follow status next to repo names in the repo list, and it is a meaningful and efficient bulk operation to toggle Follow status there.
Clicking on the (Un)Follow 'heart' will toggle the caller's follow status for that repo.
The repo model already has layering violations - expand on them to compute the follow status of the current user.
(Changeset was cherry picked and modified by Mads Kiilerich.)
|
|
|
Mads Kiilerich
|
e63bcce18fef
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
e51ad2cd400e
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
e35373106528
|
6 years ago
|
|
py3: remove safe_unicode in places where it no longer is needed because all strings (except bytes) already *are* unicode strings
(The remaining safe_unicode calls are still needed and can't just be removed, generally because we in these cases still have to convert from bytes to unicode strings.)
|
|
|
Mads Kiilerich
|
ed78b4fbe2a3
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
e8e9f33e9ff6
|
6 years ago
|
|
py3: use comprehensions and generators instead of filters - it is more explicit, and sometimes shorter
From 2to3 -f filter.
|
|
|
Mads Kiilerich
|
ce5d4c582a82
|
6 years ago
|
|
py3: cleanup map usage and avoid py3 ambiguity
Based on 2to3 -f map ... but replace map with something more explicit (unless born and raised in a lisp world) (but sometimes slightly more verbose).
|
|
|
Mads Kiilerich
|
8e2313be042d
|
6 years ago
|
|
model: use unicode for internal rendering of repo snippets
Preparing for py3.
|
|
|
Mads Kiilerich
|
a1115795fabb
|
6 years ago
|
|
utils: drop make_ui parameter clear_session - this utility function should never mess with sessions
clear_session seems to have been based on the idea that utility functions that happened to create a session also should clean up. But instead, we now consistently take care of session removal at a high level.
|
|
|
Mads Kiilerich
|
fe4086096758
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
0a277465fddf
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
5b551b189459
|
7 years ago
|
|
utils: refactor make_ui to always read from db, optionally also augmenting with hgrc content
simplehg was the only user of reading hgrc content ... and it would rather just have everything at once.
The implementation in utils is moved around and re-indented, but without significant changes.
|
|
|
Mads Kiilerich
|
99edd97366e3
|
7 years ago
|
|
locking: drop the pull-to-lock / push-to-unlock functionality
The feature is not worth the maintenance cost. The locking is too coarse and unflexible with insufficient UI and UX. The implementation is also quite invasive in tricky areas of the code, and thus high maintenance. Dropping this will enable other cleanup ... or at least make it easier.
|
|
|
domruf
|
1f3b311e865f
|
8 years ago
|
|
|
|
|
Thomas De Schampheleire
|
401fe08bc6b8
|
7 years ago
|
|
utils: move repo_name_slug to utils2 to prevent import cycle on setup_db After commit 57a733313e4f, 'gearbox setup-db -c my.ini' fails with an import cycle as follows: Traceback (most recent call last): File "/home/tdescham/repo/contrib/kallithea/venv/kallithea-release/bin/gearbox", line 11, in <module> sys.exit(main()) File "/home/tdescham/repo/contrib/kallithea/venv/kallithea-release/lib/python2.7/site-packages/gearbox/main.py", line 199, in main return gearbox.run(args) File "/home/tdescham/repo/contrib/kallithea/venv/kallithea-release/lib/python2.7/site-packages/gearbox/main.py", line 145, in run return self._run_subcommand(remainder) File "/home/tdescham/repo/contrib/kallithea/venv/kallithea-release/lib/python2.7/site-packages/gearbox/main.py", line 149, in _run_subcommand subcommand = self.command_manager.find_command(argv) File "/home/tdescham/repo/contrib/kallithea/venv/kallithea-release/lib/python2.7/site-packages/gearbox/commandmanager.py", line 78, in find_command cmd_factory = cmd_ep.resolve() File "/home/tdescham/repo/contrib/kallithea/venv/kallithea-release/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2324, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0) File "/home/tdescham/repo/contrib/kallithea/kallithea-release/kallithea/lib/paster_commands/setup_db.py", line 27, in <module> from kallithea.lib.db_manage import DbManage File "/home/tdescham/repo/contrib/kallithea/kallithea-release/kallithea/lib/db_manage.py", line 47, in <module> from kallithea.model.repo_group import RepoGroupModel File "/home/tdescham/repo/contrib/kallithea/kallithea-release/kallithea/model/repo_group.py", line 35, in <module> import kallithea.lib.utils File "/home/tdescham/repo/contrib/kallithea/kallithea-release/kallithea/lib/utils.py", line 48, in <module> from kallithea.model.repo_group import RepoGroupModel ImportError: cannot import name RepoGroupModel i.e. kallithea.model.repo_group wants to import kallithea.lib.utils which in turn wants to import kallithea.model.repo_group. In fact there exists kallithea.lib.utils and kallithea.lib.utils2. The current split is that 'utils2' contains 'simple' utilities, none of which depend on kallithea models, controllers, ... In contrast, 'utils' does rely on such kallithea classes. As kallithea.model.repo_group was only include kallithea.lib.utils for its repo_name_slug method, which has no dependency on other kallithea classes, move that method (and its dependent recursive_replace) to kallithea.lib.utils2 instead. This fixes the import cycle.
|
|
|
Mads Kiilerich
|
b3289fef0daa
|
7 years ago
|
|
|
|
|
Mads Kiilerich
|
57a733313e4f
|
7 years ago
|
|
repos: introduce low level slug check of repo and group names The high level web forms already slug-ify repo and repo group names. It might thus not create the exact repo that was created, but the name will be "safe". For API, we would rather have it fail than not doing exactly what was requested. Thus, always verify at low level that the provided name wouldn't be modified by slugification. This makes sure the API provide allow the same actual names as the web UI. This will only influence creation and renaming of repositories and repo groups. Existing repositories will continue working as before. This is a slight API change, but it makes the system more stable and can prevent some security issues - especially XSS attacks. This issue was found and reported by Kacper Szurek https://security.szurek.pl/
|
|
|
Mads Kiilerich
|
a569b523f86a
|
8 years ago
|
|
repos: introduce low level check of clone URIs to prevent direct file system access to local repos This is already checked in web form validation, but also check at low level to make sure API access enforce the same invariants. This issue was found and reported by Kacper Szurek https://security.szurek.pl/
|
|
|
Mads Kiilerich
|
64d41568507c
|
7 years ago
|
|
repos: introduce low level slug check of repo and group names The high level web forms already slug-ify repo and repo group names. It might thus not create the exact repo that was created, but the name will be "safe". For API, we would rather have it fail than not doing exactly what was requested. Thus, always verify at low level that the provided name wouldn't be modified by slugification. This makes sure the API provide allow the same actual names as the web UI. This will only influence creation and renaming of repositories and repo groups. Existing repositories will continue working as before. This is a slight API change, but it makes the system more stable and can prevent some security issues - especially XSS attacks. This issue was found and reported by Kacper Szurek https://security.szurek.pl/
|
|
|
Mads Kiilerich
|
fa3365c94064
|
8 years ago
|
|
repos: introduce low level check of clone URIs to prevent direct file system access to local repos This is already checked in web form validation, but also check at low level to make sure API access enforce the same invariants. This issue was found and reported by Kacper Szurek https://security.szurek.pl/
|
|
|
Mads Kiilerich
|
af938280e76a
|
8 years ago
|
|
|
|
|
Mads Kiilerich
|
1b737e25266c
|
8 years ago
|
|
|
|
|
Mads Kiilerich
|
a86ebf58c720
|
8 years ago
|
|
templates: drop unused get_repos_as_dict super_user parameter
It was perhaps at some point used to show a content menu.
|
|
|
Mads Kiilerich
|
b90b82881398
|
8 years ago
|
|
|
|
|
domruf
|
97ea346aa4bd
|
8 years ago
|
|
less: use .label and .label-* style instead of custom .*tag
This reduces the code and makes it more consistent.
Visualy this results in bold texts (which in case of small fonts is easier to read) and a bit more padding left and right.
For a proper spacing, this requires to remove whitespaces before and after the texts inside the labels.
Since the name changed from tag to label, also rename the variables and functions.
|
|
|
domruf
|
205daed7185b
|
8 years ago
|
|
users: remove code that is unused after most autocomplete has been switched to ajax
@mention support still require _USERS_AC_DATA as a global variable.
|
|
|
domruf
|
862e55888ff8
|
8 years ago
|
|
js: don't show number of members of groups when doing autocomplete
This is done to make the database queries cheaper.
|
|
|
Mads Kiilerich
|
6db3122e4d75
|
8 years ago
|
|
index: show repositories and repository groups in the same table
Having two different tables with their own paging and search gave a bad UI. Instead, do like all other UIs that show directory content and show both "folders" and "files" in the same list.
The rendering of repo groups is changed to use js data instead of a taking data from an html table.
Repository groups are shoe-horned into the repository DataTable. The columns are no perfect match - some of the existing columns are thus given an empty default value.
|
|
|
Mads Kiilerich
|
e81332582fc9
|
8 years ago
|
|
controllers: drop unused totalRecords and startIndex
We don't want it just for testing.
|
|
|
Lars Kruse
|
7691290837d2
|
8 years ago
|
|
codingstyle: trivial whitespace fixes
Reported by flake8.
|
|
|
Mads Kiilerich
|
0bae66824ac5
|
9 years ago
|
|
tests: clarify that default parameters are for form - direct model access requires different types
_get_repo_group_create_params parent_group_id is thus set to the form value '-1' instead of None. It worked before anyway because the model failed to find the repo '-1' and thus got pretty much the same as None.
|
|
|
Alessandro Molina
|
e1ab82613133
|
9 years ago
|
|
backend: replace Pylons with TurboGears2 Replace the no-longer-supported Pylons application framework by TurboGears2 which is largely compatible/similar to Pylons. Some interesting history is described at: https://en.wikipedia.org/wiki/TurboGearsChanges by Dominik Ruf: - fix sql config in test.ini Changes by Thomas De Schampheleire: - set-up of test suite - tests: 'fix' repo archival test failure Between Pylons and TurboGears2, there seems to be a small difference in the headers sent for repository archive files, related to character encoding. It is assumed that this difference is not important, and that the test should just align with reality. - remove need to import helpers/app_globals in lib TurboGears2 by default expects helpers and app_globals to be available in lib. For this reason kallithea/lib/__init__.py was originally changed to include those files. However, this triggered several types of circular import problems. If module A imported something from lib (e.g. lib.annotate), and lib.helpers imported (possibly indirectly) module A, then there was a circular import. Fix this by overruling the relevant method of tg AppConfig, which is also hinted in the TurboGears2 code. Hereby, the include of something from lib does not automatically import helpers, greatly reducing the chances of circular import problems. - make sure HTTP error '400' uses the custom error pages TurboGears2 does not by default handle HTTP status code '400 (Bad Request)' via the custom error page handling, causing a standard non-styled error page. - disable transaction manager Kallithea currently handles its own transactions and does not need the TurboGears2 transaction manager. However, TurboGears2 tries to enable it by default and fails, throwing an error during application initialization. The error itself seemed to be harmless for normal application functioning, but was nevertheless confusing. - add backlash as required dependency: backlash is meant as the WebError replacement in TurboGears2 (originally WebError is part of Pylons). When debug==true, it provides an interactive debugger in the browser. When debug==false, backlash is necessary to show backtraces on the console. - misc fixes
|
|
|
Mads Kiilerich
|
e9ac5698281d
|
9 years ago
|
|
tg: minimize future diff by some mocking and replacing some pylons imports with tg
No actual tg dependency yet, just a temporary hack faking tg as an alias for pylons.
Based on work by Alessandro Molina.
|
|
|
Søren Løvborg
|
33b71a130b16
|
9 years ago
|
|
templates: properly escape inline JavaScript values
TLDR: Kallithea has issues with escaping values for use in inline JS. Despite judicious poking of the code, no actual security vulnerabilities have been found, just lots of corner-case bugs. This patch fixes those, and hardens the code against actual security issues.
The long version:
To embed a Python value (typically a 'unicode' plain-text value) in a larger file, it must be escaped in a context specific manner. Example:
>>> s = u'<script>alert("It\'s a trap!");</script>'
1) Escaped for insertion into HTML element context
>>> print cgi.escape(s) <script>alert("It's a trap!");</script>
2) Escaped for insertion into HTML element or attribute context
>>> print h.escape(s) <script>alert("It's a trap!");</script>
This is the default Mako escaping, as usually used by Kallithea.
3) Encoded as JSON
>>> print json.dumps(s) "<script>alert(\"It's a trap!\");</script>"
4) Escaped for insertion into a JavaScript file
>>> print '(' + json.dumps(s) + ')' ("<script>alert(\"It's a trap!\");</script>")
The parentheses are not actually required for strings, but may be needed to avoid syntax errors if the value is a number or dict (object).
5) Escaped for insertion into a HTML inline <script> element
>>> print h.js(s) ("\x3cscript\x3ealert(\"It's a trap!\");\x3c/script\x3e")
Here, we need to combine JS and HTML escaping, further complicated by the fact that "<script>" tag contents can either be parsed in XHTML mode (in which case '<', '>' and '&' must additionally be XML escaped) or HTML mode (in which case '</script>' must be escaped, but not using HTML escaping, which is not available in HTML "<script>" tags). Therefore, the XML special characters (which can only occur in string literals) are escaped using JavaScript string literal escape sequences.
(This, incidentally, is why modern web security best practices ban all use of inline JavaScript...)
Unsurprisingly, Kallithea does not do (5) correctly. In most cases, Kallithea might slap a pair of single quotes around the HTML escaped Python value. A typical benign example:
$('#child_link').html('${_('No revisions')}');
This works in English, but if a localized version of the string contains an apostrophe, the result will be broken JavaScript. In the more severe cases, where the text is user controllable, it leaves the door open to injections. In this example, the script inserts the string as HTML, so Mako's implicit HTML escaping makes sense; but in many other cases, HTML escaping is actually an error, because the value is not used by the script in an HTML context.
The good news is that the HTML escaping thwarts attempts at XSS, since it's impossible to inject syntactically valid JavaScript of any useful complexity. It does allow JavaScript errors and gibberish to appear on the page, though.
In these cases, the escaping has been fixed to use either the new 'h.js' helper, which does JavaScript escaping (but not HTML escaping), OR the new 'h.jshtml' helper (which does both), in those cases where it was unclear if the value might be used (by the script) in an HTML context. Some of these can probably be "relaxed" from h.jshtml to h.js later, but for now, using h.jshtml fixes escaping and doesn't introduce new errors.
In a few places, Kallithea JSON encodes values in the controller, then inserts the JSON (without any further escaping) into <script> tags. This is also wrong, and carries actual risk of XSS vulnerabilities. However, in all cases, security vulnerabilities were narrowly avoided due to other filtering in Kallithea. (E.g. many special characters are banned from appearing in usernames.) In these cases, the escaping has been fixed and moved to the template, making it immediately visible that proper escaping has been performed.
Mini-FAQ (frequently anticipated questions):
Q: Why do everything in one big, hard to review patch? Q: Why add escaping in specific case FOO, it doesn't seem needed?
Because the goal here is to have "escape everywhere" as the default policy, rather than identifying individual bugs and fixing them one by one by adding escaping where needed. As such, this patch surely introduces a lot of needless escaping. This is no different from how Mako/Pylons HTML escape everything by default, even when not needed: it's errs on the side of needless work, to prevent erring on the side of skipping required (and security critical) work.
As for reviewability, the most important thing to notice is not where escaping has been introduced, but any places where it might have been missed (or where h.jshtml is needed, but h.js is used).
Q: The added escaping is kinda verbose/ugly.
That is not a question, but yes, I agree. Hopefully it'll encourage us to move away from inline JavaScript altogether. That's a significantly larger job, though; with luck this patch will keep us safe and secure until such a time as we can implement the real fix.
Q: Why not use Mako filter syntax ("${val|h.js}")?
Because of long-standing Mako bug #140, preventing use of 'h' in filters.
Q: Why not work around bug #140, or even use straight "${val|js}"?
Because Mako still applies the default h.escape filter before the explicitly specified filters.
Q: Where do we go from here?
Longer term, we should stop doing variable expansions in script blocks, and instead pass data to JS via e.g. data attributes, or asynchronously using AJAX calls. Once we've done that, we can remove inline JavaScript altogether in favor of separate script files, and set a strict Content Security Policy explicitly blocking inline scripting, and thus also the most common kind of cross-site scripting attack.
|
|
|
Søren Løvborg
|
3760df6251e0
|
9 years ago
|
|
model: remove BaseModel class
The only remaining purpose of this class was to provide the "sa" field, allowing a custom SQLAlchemy session to be used for model operations. However, this never actually worked, nor was it used anywhere.
There's always a global SQLAlchemy session associated with the current thread; using another session for a single function call does not make any sense (as sessions cannot be mixed), unless the code works carefully to ensure the two sessions (and all objects loaded from them) are kept completely separate. Suffice to say that Kallithea does no such thing, thus there's no need to pretend to support multiple concurrent sessions.
|
|
|
Søren Løvborg
|
6edba875451d
|
9 years ago
|
|
cleanup: drop superfluous Session.add calls
Session.add should only be called on newly created database objects.
Per the Kallithea contribution guidelines:
When getting an object from the session (via Session().query or any of the utility functions that look up objects in the database), it's already part of the session, and should not be added again.
|
|
|
Søren Løvborg
|
62e9be5eb783
|
9 years ago
|
|
cleanup: do Session.add directly inside _create_default_perms
Let the various _create_default_perms functions add the created object to the SQLAlchemy database session, instead of having the caller do it.
This is in accordance with the Kallithea contribution guidelines:
When creating an object using a factory function (like create_repo), the returned object has already (by convention) been added to the session, and should not be added again.
|
|
|
Søren Løvborg
|
ca77c6da2d34
|
9 years ago
|
|
auth: simplify user group permission checks
In practice, Kallithea has the 'usergroup.admin' permission imply the 'usergroup.write' permission, which again implies 'usergroup.read'.
This codifies this practice by replacing the HasUserGroupPermissionAny "perm function" with the new HasUserGroupLevel function, reducing the risk of errors and saving quite a lot of typing.
|
|
|
Søren Løvborg
|
a17c8e5f6712
|
9 years ago
|
|
auth: simplify repository permission checks
In practice, Kallithea has the 'repository.admin' permission imply the 'repository.write' permission, which again implies 'repository.read'.
This codifies/enforces this practice by replacing HasRepoPermissionAny "perm function" with the new HasRepositoryLevel function, reducing the risk of errors and saving quite a lot of typing.
|
|
|
Søren Løvborg
|
0a3e1a620edf
|
9 years ago
|
|
|
|
|
Søren Løvborg
|
c706a8dae2c8
|
9 years ago
|
|
|
|
|
Søren Løvborg
|
d7d1e0a3850a
|
9 years ago
|
|
|
|
|
Søren Løvborg
|
eb1a4c3cb76c
|
9 years ago
|
|
|
|
|
Søren Løvborg
|
c8f34ad333a2
|
9 years ago
|
|
model: simplify guess_instance invocations
The second argument to the guess_instance classmethod is in practice fixed for Gist, Permission, RepoGroup, Repository, User, UserGroup; so might as well move this logic into per-class specializations of guess_instance.
|
|
|
Mads Kiilerich
|
3dcf1f82311a
|
9 years ago
|
|
controllers: avoid setting request state in controller instances - set it in the thread global request variable
In TurboGears, controllers are singletons and we should avoid using instance variables for any volatile data. Instead, use the "global thread local" request context.
With everything in request, some use of c is dropped.
Note: kallithea/controllers/api/__init__.py still use instance variables that will cause problems with TurboGears.
|
|
|
domruf
|
b6eba3ea7af9
|
9 years ago
|
|
datatables: use more robust filter function for filtering repository names
This way it does not depend on a class attribute and it is more clear what it does.
|
|
|
Mads Kiilerich
|
184c78cfded1
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
a6af26b5ffc1
|
9 years ago
|
|
|
|
|
Thomas De Schampheleire
|
d75d9ce1320d
|
9 years ago
|
|
model: move code from __init__.py to base.py Having too much code, in particular too much imports, inside a package's __init__.py is a recipe for circular imports, and considered bad practice in Python [1] Move out everything from kallithea/model/__init__.py to a new file kallithea/model/base.py and adapt the existing imports. [1] http://docs.python-guide.org/en/latest/writing/structure/#packages
|
|
|
Søren Løvborg
|
dd6e3441b4f4
|
9 years ago
|
|
cleanup: remove redundant database loads
Don't take a database object, grab its ID, then use the ID to load the same database object once again. This also applies to creating AuthUser objects, which will happily take a User object instead of a user_id.
|
|
|
Søren Løvborg
|
cd6176c0634a
|
9 years ago
|
|
db: PullRequest/Repository/RepoGroup/UserGroup: change 'user' to 'owner'
Rename the 'user' and 'user_id' fields on the four classes to something more informative. The database column names remain unchanged for now; a later Alembic script can fix the name of these and other columns to match their Python name.
This might break rcextensions, though, and external scripts that use the HTML form interface.
|
|
|
Søren Løvborg
|
f35ddb654668
|
9 years ago
|
|
repos: inline RepoModel.update_repoinfo
It had only two invocations, each triggering separate code paths, all to do a simple loop.
|
|
|
Søren Løvborg
|
7bffccee3a49
|
9 years ago
|
|
db: inline calls to get_all
This method saves basically no typing, compared to "query().all()". Additionally, "all()" returns a list, forcing all records to be loaded into a memory at the same time, but some callers just need to iterate over the objects one at a time, in which case "query()" alone is more efficient. In one case, the caller can even use "count()" and avoid loading any objects from the database at all.
|
|
|
Mads Kiilerich
|
82662f9faaf4
|
9 years ago
|
|
celeryd: annotate tasks so they can be run directly without run_task
This also makes the system less forgiving about celery configuration problems and thus easier to debug. I like that.
|
|
|
Søren Løvborg
|
91b38dc6d891
|
9 years ago
|
|
model: refactor and simplify _get_instance
_get_instance is a BaseModel method, but never uses "self". Instead it takes a class argument, which indicates that it's better suited as a classmethod on said classes.
Also rename to something more descriptive, remove leading underscore since it's not a private API, and refactor for readability.
|
|
|
Søren Løvborg
|
3d1fcf67f299
|
9 years ago
|
|
model: drop BaseModel.cls
It no longer serves a purpose.
|
|
|
Søren Løvborg
|
1e52ed5c37aa
|
9 years ago
|
|
db: remove deprecated getAll method
Not sure why this wasn't done immediately when get_all was added. Maybe search and replace was out of order at the time.
|
|
|
Mads Kiilerich
|
bf0a587334ea
|
9 years ago
|
|
repo: better handling of situation where there is no repo to remove
Change internal method _delete_filesystem_repo. We should never end up in such situations, but this helps debugging if it should happen.
|
|
|
Mads Kiilerich
|
7d0052c68a6f
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
ffe4d5060d91
|
9 years ago
|
|
api: avoid duplicating group name when updating repo (Issue #37)
The api incorrectly passed repo.repo_name as repo_name, and the model update function incorrectly always required repo_name.
|
|
|
Daniel Hobley
|
b8830c373681
|
10 years ago
|
|
datatables: use jQuery DataTables instead of base.js YUI_datatable wrapper of YAHOO.widget.DataTable
Sorting and searching fixes by Mads Kiilerich.
|
|
|
Mads Kiilerich
|
73e44865f204
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
db2e1fb6aec7
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
8d01c8a72bb5
|
10 years ago
|
|
|
|
|
Mads Kiilerich
|
98c3d9515cad
|
10 years ago
|
|
|
|
|
domruf
|
a9e0ea9ecc91
|
10 years ago
|
|
|
|
|
Mads Kiilerich
|
964aa663deca
|
10 years ago
|
|
|
|
|
Mads Kiilerich
|
737c3704b44a
|
10 years ago
|
|
cleanup: fixes of checking for None
Don't update repoinfo for all repos if an invalid repo is specified.
|
|
|
Søren Løvborg
|
431689d7f37d
|
10 years ago
|
|
remove vestiges of Python 2.5 support
We only support Python 2.6 and 2.7; hence we do not need to import with-statement support from __future__.
|
|
|
branko
|
c3d83238afa1
|
10 years ago
|
|
git: add option for forcing overwrite of Git hooks when remapping and rescanning the repositories. (Issue #153)
README file was updated to include some information on updating Git hooks after migrating to Kallithea.
|
|
|
Mads Kiilerich
|
7d0727d11104
|
10 years ago
|
|
cleanup: remove unused imports
Found with pyflakes.
|
|
|
Mads Kiilerich
|
0210d0b769d4
|
10 years ago
|
|
|
|
|
Mads Kiilerich
|
63bed817308c
|
10 years ago
|
|
cleanup: check for None object identity in cases where that is what the 'contract' says
Avoid applying bool() on complex objects - it might return something unexpected such as the key (which might be 0 and thus be false). Checking for None is more safe and faster.
|
|
|
Mads Kiilerich
|
fdf6df128d89
|
10 years ago
|
|
remote: simplify clone_uri UI
The UI was a bit weird ... probably in an attempt of making it editable while hiding passwords. Instead, just show the URL with password hidden, and only save it back if it changed.
The UI only contains the clone_uri with passwords hidden. It will thus only be saved when the form result is different from the value that was shown to the user.
|
|
|
Mads Kiilerich
|
53f19cdfa40c
|
10 years ago
|
|
|