scragg0x / realms-wiki

Git based wiki inspired by Gollum
http://realms.io
GNU General Public License v2.0
831 stars 90 forks source link

saving a page fails when using a relative path #120

Open larsimmisch opened 8 years ago

larsimmisch commented 8 years ago

My realms instance has a relative base URL - something like https://example.org/wiki

In this setup, I cannot save pages, because I get redirected to https://example.org/foo (if foo is the page name) and not https://example.org/wiki/foo.

I tried looking into the issue, but only have found one clue so far. The page source for the edit page has this snippet:

      var Config = {};

        Config.RELATIVE_PATH = "";

      var User = {};
      User.is_authenticated = true;

        User.username = "lars";

        User.email = "lars@ibp.de";

That's puzzling. I'd expect Config.RELATIVE_PATH to be wiki, not the empty string. The BASE_URL in my (only) realms-wiki.json is https://example.org/wiki.

(I hope this is not a red herring)

larsimmisch commented 8 years ago

(fixed typos in original report)

gazpachoking commented 8 years ago

It looks like the problem might be to do with the order the config defaults are generated. https://github.com/scragg0x/realms-wiki/blob/master/realms/config/__init__.py#L180-L186

RELATIVE_PATH is generated based on BASE_URL before the user's custom BASE_URL is set. I bet if you manually specify your RELATIVE_PATH it would work.

I think the proper fix is re-considering the order in which certain defaults get set in the config package. I think any defaults based on other config values needs to happen after the user config import, then it needs to check that the user didn't set them explicitly before overriding with the generated default.

larsimmisch commented 8 years ago

Thanks @gazpachoking,

good catch! Unfortunately this is no fix, but that is a different matter.

The relevant fragment from my realms-wiki.json looks like this:

{
    "ALLOW_ANON": false,
    "PRIVATE_WIKI": true,
    "BASE_URL": "https://example.org",
    "RELATIVE_PATH": "/wiki",
    ...
}

With this I surprisingly get redirected to https://example.org/wiki/wiki. If I reorder https://github.com/scragg0x/realms-wiki/blob/master/realms/config/__init__.py, the same thing happens (obviously).

I agree RELATIVE_PATH should be evaluated after https://github.com/scragg0x/realms-wiki/blob/master/realms/config/__init__.py#L199.

larsimmisch commented 8 years ago

Ah. I should mention that I have these problems when I run realms-wiki as a wsgi script. My relevant apache configuration is:

        WSGIDaemonProcess realms_wsgi user=www-data group=www-data \
            home=/usr/local/src/realms-wiki display-name=%{GROUP}
    WSGIProcessGroup realms_wsgi
        WSGIScriptAlias /wiki /Library/SSL/wiki/wsgi.py
        Alias /wiki/static /usr/local/src/realms-wiki/realms/static

        <Directory /Library/SSL/wiki>
          Options -Indexes
          Require all granted
        </Directory>