If you haven’t yet, check out this answer from another thread.
In my case, I needed to change it after the users were created. Impersonating each single user or changing all passwords and logging into their accounts was not a feasible option.
So I resorted to manually updating the DB. I anyone is in the same situation, the following might work to make the email private for all users:
- Get the desired set of users. In my example, I use all
- Iterate each uid and get the json data of their respective account from the database
- Use
jqto changeemail.scopefromcontactstoprivate.
So far so good, we now have the json we want to update the db with. But the tricky part for me was to update the db with the manipulated json string. I ran into encoding issues using postgres on the shell. So my solution was:
- Create an SQL update statement for each UID using
awkand saved it to a.sqlfile. - Run the update statements of the
.sqlthrough the db
IMPORTANT: Backup your DB before trying this!
Example code using postgres and docker/docker-compose:
docker-compose exec -T [DB_CONTAINER_COMPOSE] psql -tU [DB_NAME] -c "select uid from oc_accounts;" |
# Remove trailing newline that postgres adds for some reason.
head -n -1 |
# iterate each UID from the last query
while read line; do
# retrieve data of UID from DB
docker exec [DB_CONTAINER_FULL_NAME] \
psql -tU [DB_NAME] -c "select data from oc_accounts where uid='$line';" |
# set email.scope to `private`
jq --raw-output --compact-output -e '.email.scope = "private"' |
# create update statement using awk
awk -v q="'" -v uid="$line" \
'{ print "UPDATE oc_accounts SET data = " q $0 q " WHERE uid = " q uid q ";" }'
# redirect all update statements to a single .sql file
done > update.sql
Ok, quite terrible, but at least it’s a “one” liner. Now if using docker:
docker cp update.sql [DB_CONTAINER_FULL_NAME]:/
And finally, execute the statement, after you made a backup of the DB and double checked the generated update.sql!
docker-compose exec nc-db psql -U [DB_NAME] -f /update.sql
Would be great if such simple tasks could be performed more productively with NC! Best solution: Don’t need to perform them at all; just make everything private by default except the username! Users can be informed that their personal info can be made public. But users can not be told “eerr…btw…your email is public. turn it private if you want, so that at least not any more users see it from now on.”