Skip to content

Commit

Permalink
Merge pull request #1473 from itglob/master
Browse files Browse the repository at this point in the history
Ability to create predefined calendar or(and) addressbook for new user
  • Loading branch information
pbiering authored Jun 11, 2024
2 parents b4967f8 + 515afb5 commit e9c7d4a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
20 changes: 20 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,26 @@ Command that is run after changes to storage. Take a look at the

Default:

##### predefined_collections

Create predefined user collections

Example:

{
"def-addressbook": {
"D:displayname": "Personal Address Book",
"tag": "VADDRESSBOOK"
},
"def-calendar": {
"C:supported-calendar-component-set": "VEVENT,VJOURNAL,VTODO",
"D:displayname": "Personal Calendar",
"tag": "VCALENDAR"
}
}

Default:

#### web

##### type
Expand Down
18 changes: 18 additions & 0 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@
# Example: ([ -d .git ] || git init) && git add -A && (git diff --cached --quiet || git commit -m "Changes by \"%(user)s\"")
#hook =

# Create predefined user collections
#
# json format:
#
# {
# "def-addressbook": {
# "D:displayname": "Personal Address Book",
# "tag": "VADDRESSBOOK"
# },
# "def-calendar": {
# "C:supported-calendar-component-set": "VEVENT,VJOURNAL,VTODO",
# "D:displayname": "Personal Calendar",
# "tag": "VCALENDAR"
# }
# }
#
#predefined_collections =


[web]

Expand Down
9 changes: 8 additions & 1 deletion radicale/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,14 @@ def response(status: int, headers: types.WSGIResponseHeaders,
if "W" in self._rights.authorization(user, principal_path):
with self._storage.acquire_lock("w", user):
try:
self._storage.create_collection(principal_path)
new_coll = self._storage.create_collection(principal_path)
if new_coll:
jsn_coll = self.configuration.get("storage", "predefined_collections")
for (name_coll, props) in jsn_coll.items():
try:
self._storage.create_collection(principal_path + name_coll, props=props)
except ValueError as e:
logger.warning("Failed to create predefined collection %r: %s", name_coll, e)
except ValueError as e:
logger.warning("Failed to create principal "
"collection %r: %s", user, e)
Expand Down
18 changes: 17 additions & 1 deletion radicale/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"""

import contextlib
import json
import math
import os
import string
Expand All @@ -37,6 +38,7 @@
Sequence, Tuple, TypeVar, Union)

from radicale import auth, hook, rights, storage, types, web
from radicale.item import check_and_sanitize_props

DEFAULT_CONFIG_PATH: str = os.pathsep.join([
"?/etc/radicale/config",
Expand Down Expand Up @@ -102,6 +104,16 @@ def _convert_to_bool(value: Any) -> bool:
return RawConfigParser.BOOLEAN_STATES[value.lower()]


def json_str(value: Any) -> dict:
if not value:
return {}
ret = json.loads(value)
for (name_coll, props) in ret.items():
checked_props = check_and_sanitize_props(props)
ret[name_coll] = checked_props
return ret


INTERNAL_OPTIONS: Sequence[str] = ("_allow_extra",)
# Default configuration
DEFAULT_CONFIG_SCHEMA: types.CONFIG_SCHEMA = OrderedDict([
Expand Down Expand Up @@ -222,7 +234,11 @@ def _convert_to_bool(value: Any) -> bool:
("_filesystem_fsync", {
"value": "True",
"help": "sync all changes to filesystem during requests",
"type": bool})])),
"type": bool}),
("predefined_collections", {
"value": "",
"help": "predefined user collections",
"type": json_str})])),
("hook", OrderedDict([
("type", {
"value": "none",
Expand Down

0 comments on commit e9c7d4a

Please sign in to comment.