Merge remote-tracking branch 'origin/develop' into shigusegubu
* origin/develop: (159 commits) [#1043] fix search accounts. tasks/pleroma/instance.ex: Change :upload_dir to :uploads_dir Expose `skip_thread_containment` in nodeinfo Split alters rather than work with indexes Use fallback values for search queries Fix migration [#1048] Fixed version parsing in pleroma_ctl. Closes #1036. [#1048] Resolved violations of SemVer version format. Refactoring. Add fallback value to the admin report view. Move changelog entries [#1033] Fix database migrations Update changelog and admin API docs with tags, display_name, avatar additions OTP Release install docs: Remove --dry-run in cron certbot command Add hashtag filter to user statuses (GET /api/v1/accounts/:id/statuses) [#1026] Filter.AnonymizeFilename added ability to retain file extension with custom text Fix not being able to pin unlisted posts Add PLEROMA_BUILD_ENV to override env for the version generator and use it in the CI for building docs Add a caveat for docker deployment in the config docs Revert "Build releases only on tags or develop" Build releases only on tags or develop ...
This commit is contained in:
commit
ae4d15503b
581 changed files with 6096 additions and 1582 deletions
|
|
@ -35,6 +35,7 @@ docs-build:
|
|||
- develop@pleroma/pleroma
|
||||
variables:
|
||||
MIX_ENV: dev
|
||||
PLEROMA_BUILD_ENV: prod
|
||||
script:
|
||||
- mix deps.get
|
||||
- mix compile
|
||||
|
|
@ -173,6 +174,7 @@ amd64:
|
|||
script: &release
|
||||
- mix deps.get --only prod
|
||||
- mkdir release
|
||||
- export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
|
||||
- mix release --path release
|
||||
|
||||
|
||||
|
|
|
|||
30
CHANGELOG.md
30
CHANGELOG.md
|
|
@ -3,7 +3,28 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
## [unreleased]
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- MRF: Support for priming the mediaproxy cache (`Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy`)
|
||||
- Mastodon API: Support for the [`tagged` filter](https://github.com/tootsuite/mastodon/pull/9755) in [`GET /api/v1/accounts/:id/statuses`](https://docs.joinmastodon.org/api/rest/accounts/#get-api-v1-accounts-id-statuses)
|
||||
- Admin API: Return users' tags when querying reports
|
||||
- Admin API: Return avatar and display name when querying users
|
||||
|
||||
### Fixed
|
||||
- Not being able to pin unlisted posts
|
||||
- Mastodon API: Handling of search timeouts (`/api/v1/search` and `/api/v2/search`)
|
||||
|
||||
### Changed
|
||||
- Configuration: Filter.AnonymizeFilename added ability to retain file extension with custom text
|
||||
|
||||
### Changed
|
||||
- NodeInfo: Return `skipThreadContainment` in `metadata` for the `skip_thread_containment` option
|
||||
|
||||
## [1.0.0] - 2019-06-29
|
||||
### Security
|
||||
- Mastodon API: Fix display names not being sanitized
|
||||
- Rich media: Do not crawl private IP ranges
|
||||
|
||||
### Added
|
||||
- Add a generic settings store for frontends / clients to use.
|
||||
- Explicit addressing option for posting.
|
||||
|
|
@ -24,6 +45,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- Federation: Support for `Question` and `Answer` objects
|
||||
- Federation: Support for reports
|
||||
- Configuration: `poll_limits` option
|
||||
- Configuration: `pack_extensions` option
|
||||
- Configuration: `safe_dm_mentions` option
|
||||
- Configuration: `link_name` option
|
||||
- Configuration: `fetch_initial_posts` option
|
||||
|
|
@ -60,8 +82,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- MRF: Support for running subchains.
|
||||
- Configuration: `skip_thread_containment` option
|
||||
- Configuration: `rate_limit` option. See `Pleroma.Plugs.RateLimiter` documentation for details.
|
||||
- MRF: Support for filtering out likely spam messages by rejecting posts from new users that contain links.
|
||||
- Configuration: `ignore_hosts` option
|
||||
- Configuration: `ignore_tld` option
|
||||
- Configuration: default syslog tag "Pleroma" is now lowercased to "pleroma"
|
||||
|
||||
### Changed
|
||||
- **Breaking:** bind to 127.0.0.1 instead of 0.0.0.0 by default
|
||||
- **Breaking:** Configuration: move from Pleroma.Mailer to Pleroma.Emails.Mailer
|
||||
- Thread containment / test for complete visibility will be skipped by default.
|
||||
- Enforcement of OAuth scopes
|
||||
|
|
@ -98,6 +125,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- Posts which are marked sensitive or tagged nsfw no longer have link previews.
|
||||
- HTTP connection timeout is now set to 10 seconds.
|
||||
- Respond with a 404 Not implemented JSON error message when requested API is not implemented
|
||||
- Rich Media: crawl only https URLs.
|
||||
|
||||
### Fixed
|
||||
- Follow requests don't get 'stuck' anymore.
|
||||
|
|
|
|||
|
|
@ -15,9 +15,12 @@ For clients it supports both the [GNU Social API with Qvitter extensions](https:
|
|||
If you want to run your own server, feel free to contact us at @lain@pleroma.soykaf.com or in our dev chat at #pleroma on freenode or via matrix at <https://matrix.heldscal.la/#/room/#freenode_#pleroma:matrix.org>.
|
||||
|
||||
## Installation
|
||||
**Note:** The guide below may be outdated and in most cases shouldn't be used. Instead check out our [wiki](https://docs.pleroma.social) for platform-specific installation instructions, most likely [Installing on Linux using OTP releases](https://docs.pleroma.social/otp_en.html) is the guide you need.
|
||||
|
||||
### OS/Distro packages
|
||||
Currently Pleroma is not packaged by any OS/Distros, but feel free to reach out to us at [#pleroma-dev on freenode](https://webchat.freenode.net/?channels=%23pleroma-dev) or via matrix at <https://matrix.heldscal.la/#/room/#freenode_#pleroma-dev:matrix.org> for assistance. If you want to change default options in your Pleroma package, please **discuss it with us first**.
|
||||
|
||||
### Docker
|
||||
|
||||
While we don’t provide docker files, other people have written very good ones. Take a look at <https://github.com/angristan/docker-pleroma> or <https://github.com/sn0w/pleroma-docker>.
|
||||
|
||||
### Dependencies
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ config :pleroma, Pleroma.Uploaders.MDII,
|
|||
|
||||
config :pleroma, :emoji,
|
||||
shortcode_globs: ["/emoji/custom/**/*.png"],
|
||||
pack_extensions: [".png", ".gif"],
|
||||
groups: [
|
||||
# Put groups that have higher priority than defaults here. Example in `docs/config/custom_emoji.md`
|
||||
Custom: ["/emoji/*.png", "/emoji/**/*.png"]
|
||||
|
|
@ -139,6 +140,7 @@ config :pleroma, Pleroma.Web.Endpoint,
|
|||
instrumenters: [Pleroma.Web.Endpoint.Instrumenter],
|
||||
url: [host: "localhost"],
|
||||
http: [
|
||||
ip: {127, 0, 0, 1},
|
||||
dispatch: [
|
||||
{:_,
|
||||
[
|
||||
|
|
@ -167,7 +169,7 @@ config :logger, :console,
|
|||
|
||||
config :logger, :ex_syslogger,
|
||||
level: :debug,
|
||||
ident: "Pleroma",
|
||||
ident: "pleroma",
|
||||
format: "$metadata[$level] $message",
|
||||
metadata: [:request_id]
|
||||
|
||||
|
|
@ -342,7 +344,10 @@ config :pleroma, :mrf_keyword,
|
|||
|
||||
config :pleroma, :mrf_subchain, match_actor: %{}
|
||||
|
||||
config :pleroma, :rich_media, enabled: true
|
||||
config :pleroma, :rich_media,
|
||||
enabled: true,
|
||||
ignore_hosts: [],
|
||||
ignore_tld: ["local", "localdomain", "lan"]
|
||||
|
||||
config :pleroma, :media_proxy,
|
||||
enabled: false,
|
||||
|
|
@ -455,6 +460,8 @@ config :auto_linker,
|
|||
opts: [
|
||||
scheme: true,
|
||||
extra: true,
|
||||
# TODO: Set to :no_scheme when it works properly
|
||||
validate_tld: true,
|
||||
class: false,
|
||||
strip_prefix: false,
|
||||
new_window: false,
|
||||
|
|
|
|||
|
|
@ -60,5 +60,5 @@ else
|
|||
)
|
||||
end
|
||||
|
||||
if File.exists?("./config/dev.migrated.secret.exs"),
|
||||
do: import_config("./config/dev.migrated.secret.exs")
|
||||
if File.exists?("./config/dev.exported_from_db.secret.exs"),
|
||||
do: import_config("dev.exported_from_db.secret.exs")
|
||||
|
|
|
|||
|
|
@ -64,5 +64,5 @@ config :logger, level: :warn
|
|||
# which should be versioned separately.
|
||||
import_config "prod.secret.exs"
|
||||
|
||||
if File.exists?("./config/prod.migrated.secret.exs"),
|
||||
do: import_config("./config/prod.migrated.secret.exs")
|
||||
if File.exists?("./config/prod.exported_from_db.secret.exs"),
|
||||
do: import_config("prod.exported_from_db.secret.exs")
|
||||
|
|
|
|||
|
|
@ -43,7 +43,11 @@ config :pleroma, Pleroma.Repo,
|
|||
config :pbkdf2_elixir, rounds: 1
|
||||
|
||||
config :tesla, adapter: Tesla.Mock
|
||||
config :pleroma, :rich_media, enabled: false
|
||||
|
||||
config :pleroma, :rich_media,
|
||||
enabled: false,
|
||||
ignore_hosts: [],
|
||||
ignore_tld: ["local", "localdomain", "lan"]
|
||||
|
||||
config :web_push_encryption, :vapid_details,
|
||||
subject: "mailto:administrator@example.com",
|
||||
|
|
|
|||
|
|
@ -38,7 +38,9 @@ Authentication is required and the user must be an admin.
|
|||
"moderator": bool
|
||||
},
|
||||
"local": bool,
|
||||
"tags": array
|
||||
"tags": array,
|
||||
"avatar": string,
|
||||
"display_name": string
|
||||
},
|
||||
...
|
||||
]
|
||||
|
|
@ -331,6 +333,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||
"pleroma": {},
|
||||
"sensitive": false
|
||||
},
|
||||
"tags": ["force_unlisted"],
|
||||
"statuses_count": 3,
|
||||
"url": "https://pleroma.example.org/users/user",
|
||||
"username": "user"
|
||||
|
|
@ -366,6 +369,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||
"pleroma": {},
|
||||
"sensitive": false
|
||||
},
|
||||
"tags": ["force_unlisted"],
|
||||
"statuses_count": 1,
|
||||
"url": "https://pleroma.example.org/users/lain",
|
||||
"username": "lain"
|
||||
|
|
@ -568,8 +572,9 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||
{
|
||||
configs: [
|
||||
{
|
||||
"group": string,
|
||||
"key": string,
|
||||
"value": string or {} or []
|
||||
"value": string or {} or [] or {"tuple": []}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -578,8 +583,10 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||
## `/api/pleroma/admin/config`
|
||||
### Update config settings
|
||||
Module name can be passed as string, which starts with `Pleroma`, e.g. `"Pleroma.Upload"`.
|
||||
Atom or boolean value can be passed with `:` in the beginning, e.g. `":true"`, `":upload"`.
|
||||
Atom or boolean value can be passed with `:` in the beginning, e.g. `":true"`, `":upload"`. For keys it is not needed.
|
||||
Integer with `i:`, e.g. `"i:150"`.
|
||||
Tuple with more than 2 values with `{"tuple": ["first_val", Pleroma.Module, []]}`.
|
||||
`{"tuple": ["some_string", "Pleroma.Some.Module", []]}` will be converted to `{"some_string", Pleroma.Some.Module, []}`.
|
||||
|
||||
Compile time settings (need instance reboot):
|
||||
- all settings by this keys:
|
||||
|
|
@ -595,8 +602,9 @@ Compile time settings (need instance reboot):
|
|||
- Method `POST`
|
||||
- Params:
|
||||
- `configs` => [
|
||||
- `group` (string)
|
||||
- `key` (string)
|
||||
- `value` (string, [], {})
|
||||
- `value` (string, [], {} or {"tuple": []})
|
||||
- `delete` = true (optional, if parameter must be deleted)
|
||||
]
|
||||
|
||||
|
|
@ -606,6 +614,7 @@ Compile time settings (need instance reboot):
|
|||
{
|
||||
configs: [
|
||||
{
|
||||
"group": "pleroma",
|
||||
"key": "Pleroma.Upload",
|
||||
"value": {
|
||||
"uploader": "Pleroma.Uploaders.Local",
|
||||
|
|
@ -619,6 +628,9 @@ Compile time settings (need instance reboot):
|
|||
"follow_redirect": ":true",
|
||||
"pool": ":upload"
|
||||
}
|
||||
},
|
||||
"dispatch": {
|
||||
"tuple": ["/api/v1/streaming", "Pleroma.Web.MastodonAPI.WebsocketHandler", []]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -631,8 +643,9 @@ Compile time settings (need instance reboot):
|
|||
{
|
||||
configs: [
|
||||
{
|
||||
"group": string,
|
||||
"key": string,
|
||||
"value": string or {} or []
|
||||
"value": string or {} or [] or {"tuple": []}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,13 +49,6 @@ Feel free to contact us to be added to this list!
|
|||
- Platforms: iOS, Android
|
||||
- Features: No Streaming
|
||||
|
||||
### Tootdon
|
||||
- Homepage: <http://tootdon.club/>, <http://blog.mastodon-tootdon.com/>
|
||||
- Source Code: ???
|
||||
- Contact: [@tootdon@mstdn.jp](https://mstdn.jp/users/tootdon)
|
||||
- Platforms: Android, iOS
|
||||
- Features: No Streaming
|
||||
|
||||
### Tusky
|
||||
- Homepage: <https://tuskyapp.github.io/>
|
||||
- Source Code: <https://github.com/tuskyapp/Tusky>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,13 @@ Note: `strip_exif` has been replaced by `Pleroma.Upload.Filter.Mogrify`.
|
|||
## Pleroma.Uploaders.Local
|
||||
* `uploads`: Which directory to store the user-uploads in, relative to pleroma’s working directory
|
||||
|
||||
## Pleroma.Uploaders.S3
|
||||
* `bucket`: S3 bucket name
|
||||
* `public_endpoint`: S3 endpoint that the user finally accesses(ex. "https://s3.dualstack.ap-northeast-1.amazonaws.com")
|
||||
* `truncated_namespace`: If you use S3 compatible service such as Digital Ocean Spaces or CDN, set folder name or "" etc.
|
||||
For example, when using CDN to S3 virtual host format, set "".
|
||||
At this time, write CNAME to CDN in public_endpoint.
|
||||
|
||||
## Pleroma.Upload.Filter.Mogrify
|
||||
|
||||
* `args`: List of actions for the `mogrify` command like `"strip"` or `["strip", "auto-orient", {"impode", "1"}]`.
|
||||
|
|
@ -29,7 +36,7 @@ No specific configuration.
|
|||
This filter replaces the filename (not the path) of an upload. For complete obfuscation, add
|
||||
`Pleroma.Upload.Filter.Dedupe` before AnonymizeFilename.
|
||||
|
||||
* `text`: Text to replace filenames in links. If empty, `{random}.extension` will be used.
|
||||
* `text`: Text to replace filenames in links. If empty, `{random}.extension` will be used. You can get the original filename extension by using `{extension}`, for example `custom-file-name.{extension}`.
|
||||
|
||||
## Pleroma.Emails.Mailer
|
||||
* `adapter`: one of the mail adapters listed in [Swoosh readme](https://github.com/swoosh/swoosh#adapters), or `Swoosh.Adapters.Local` for in-memory mailbox.
|
||||
|
|
@ -90,6 +97,8 @@ config :pleroma, Pleroma.Emails.Mailer,
|
|||
* `Pleroma.Web.ActivityPub.MRF.SubchainPolicy`: Selectively runs other MRF policies when messages match (see ``:mrf_subchain`` section)
|
||||
* `Pleroma.Web.ActivityPub.MRF.RejectNonPublic`: Drops posts with non-public visibility settings (See ``:mrf_rejectnonpublic`` section)
|
||||
* `Pleroma.Web.ActivityPub.MRF.EnsureRePrepended`: Rewrites posts to ensure that replies to posts with subjects do not have an identical subject and instead begin with re:.
|
||||
* `Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy`: Rejects posts from likely spambots by rejecting posts from new users that contain links.
|
||||
* `Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy`: Crawls attachments using their MediaProxy URLs so that the MediaProxy cache is primed.
|
||||
* `public`: Makes the client API in authentificated mode-only except for user-profiles. Useful for disabling the Local Timeline and The Whole Known Network.
|
||||
* `quarantined_instances`: List of ActivityPub instances where private(DMs, followers-only) activities will not be send.
|
||||
* `managed_config`: Whenether the config for pleroma-fe is configured in this config or in ``static/config.json``
|
||||
|
|
@ -271,7 +280,7 @@ config :pleroma, :mrf_subchain,
|
|||
|
||||
## Pleroma.Web.Endpoint
|
||||
`Phoenix` endpoint configuration, all configuration options can be viewed [here](https://hexdocs.pm/phoenix/Phoenix.Endpoint.html#module-dynamic-configuration), only common options are listed here
|
||||
* `http` - a list containing http protocol configuration, all configuration options can be viewed [here](https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html#module-options), only common options are listed here
|
||||
* `http` - a list containing http protocol configuration, all configuration options can be viewed [here](https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html#module-options), only common options are listed here. For deployment using docker, you need to set this to `[ip: {0,0,0,0}, port: 4000]` to make pleroma accessible from other containers (such as your nginx server).
|
||||
- `ip` - a tuple consisting of 4 integers
|
||||
- `port`
|
||||
* `url` - a list containing the configuration for generating urls, accepts
|
||||
|
|
@ -409,6 +418,8 @@ This config contains two queues: `federator_incoming` and `federator_outgoing`.
|
|||
|
||||
## :rich_media
|
||||
* `enabled`: if enabled the instance will parse metadata from attached links to generate link previews
|
||||
* `ignore_hosts`: list of hosts which will be ignored by the metadata parser. For example `["accounts.google.com", "xss.website"]`, defaults to `[]`.
|
||||
* `ignore_tld`: list TLDs (top-level domains) which will ignore for parse metadata. default is ["local", "localdomain", "lan"]
|
||||
|
||||
## :fetch_initial_posts
|
||||
* `enabled`: if enabled, when a new user is federated with, fetch some of their latest posts
|
||||
|
|
@ -596,6 +607,7 @@ Configure OAuth 2 provider capabilities:
|
|||
|
||||
## :emoji
|
||||
* `shortcode_globs`: Location of custom emoji files. `*` can be used as a wildcard. Example `["/emoji/custom/**/*.png"]`
|
||||
* `pack_extensions`: A list of file extensions for emojis, when no emoji.txt for a pack is present. Example `[".png", ".gif"]`
|
||||
* `groups`: Emojis are ordered in groups (tags). This is an array of key-value pairs where the key is the groupname and the value the location or array of locations. `*` can be used as a wildcard. Example `[Custom: ["/emoji/*.png", "/emoji/custom/*.png"]]`
|
||||
* `default_manifest`: Location of the JSON-manifest. This manifest contains information about the emoji-packs you can download. Currently only one manifest can be added (no arrays).
|
||||
|
||||
|
|
|
|||
|
|
@ -203,12 +203,12 @@ sudo -Hu pleroma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress
|
|||
#### Further reading
|
||||
|
||||
* [Admin tasks](Admin tasks)
|
||||
* [Backup your instance](Backup-your-instance)
|
||||
* [Configuration tips](General tips for customizing pleroma fe)
|
||||
* [Hardening your instance](Hardening-your-instance)
|
||||
* [How to activate mediaproxy](How-to-activate-mediaproxy)
|
||||
* [Small Pleroma-FE customizations](Small customizations)
|
||||
* [Updating your instance](Updating-your-instance)
|
||||
* [Backup your instance](backup.html)
|
||||
* [Configuration tips](general-tips-for-customizing-pleroma-fe.html)
|
||||
* [Hardening your instance](hardening.html)
|
||||
* [How to activate mediaproxy](howto_mediaproxy.html)
|
||||
* [Small Pleroma-FE customizations](small_customizations.html)
|
||||
* [Updating your instance](updating.html)
|
||||
|
||||
## Questions
|
||||
|
||||
|
|
|
|||
|
|
@ -201,12 +201,12 @@ sudo -Hu pleroma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress
|
|||
#### Further reading
|
||||
|
||||
* [Admin tasks](Admin tasks)
|
||||
* [Backup your instance](Backup-your-instance)
|
||||
* [Configuration tips](General tips for customizing pleroma fe)
|
||||
* [Hardening your instance](Hardening-your-instance)
|
||||
* [How to activate mediaproxy](How-to-activate-mediaproxy)
|
||||
* [Small Pleroma-FE customizations](Small customizations)
|
||||
* [Updating your instance](Updating-your-instance)
|
||||
* [Backup your instance](backup.html)
|
||||
* [Configuration tips](general-tips-for-customizing-pleroma-fe.html)
|
||||
* [Hardening your instance](hardening.html)
|
||||
* [How to activate mediaproxy](howto_mediaproxy.html)
|
||||
* [Small Pleroma-FE customizations](small_customizations.html)
|
||||
* [Updating your instance](updating.html)
|
||||
|
||||
## Questions
|
||||
|
||||
|
|
|
|||
|
|
@ -265,12 +265,12 @@ sudo -Hu pleroma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress
|
|||
#### Further reading
|
||||
|
||||
* [Admin tasks](Admin tasks)
|
||||
* [Backup your instance](Backup-your-instance)
|
||||
* [Configuration tips](General tips for customizing pleroma fe)
|
||||
* [Hardening your instance](Hardening-your-instance)
|
||||
* [How to activate mediaproxy](How-to-activate-mediaproxy)
|
||||
* [Small Pleroma-FE customizations](Small customizations)
|
||||
* [Updating your instance](Updating-your-instance)
|
||||
* [Backup your instance](backup.html)
|
||||
* [Configuration tips](general-tips-for-customizing-pleroma-fe.html)
|
||||
* [Hardening your instance](hardening.html)
|
||||
* [How to activate mediaproxy](howto_mediaproxy.html)
|
||||
* [Small Pleroma-FE customizations](small_customizations.html)
|
||||
* [Updating your instance](updating.html)
|
||||
|
||||
## Questions
|
||||
|
||||
|
|
|
|||
|
|
@ -191,12 +191,12 @@ sudo -Hu pleroma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress
|
|||
#### Further reading
|
||||
|
||||
* [Admin tasks](Admin tasks)
|
||||
* [Backup your instance](Backup-your-instance)
|
||||
* [Configuration tips](General tips for customizing pleroma fe)
|
||||
* [Hardening your instance](Hardening-your-instance)
|
||||
* [How to activate mediaproxy](How-to-activate-mediaproxy)
|
||||
* [Small Pleroma-FE customizations](Small customizations)
|
||||
* [Updating your instance](Updating-your-instance)
|
||||
* [Backup your instance](backup.html)
|
||||
* [Configuration tips](general-tips-for-customizing-pleroma-fe.html)
|
||||
* [Hardening your instance](hardening.html)
|
||||
* [How to activate mediaproxy](howto_mediaproxy.html)
|
||||
* [Small Pleroma-FE customizations](small_customizations.html)
|
||||
* [Updating your instance](updating.html)
|
||||
|
||||
## Questions
|
||||
|
||||
|
|
|
|||
|
|
@ -180,9 +180,13 @@ mix set_moderator username [true|false]
|
|||
|
||||
#### コンフィギュレーションとカスタマイズ
|
||||
|
||||
* [Configuration tips](General tips for customizing pleroma fe)
|
||||
* [Small Pleroma-FE customizations](Small customizations)
|
||||
* [Admin tasks](Admin tasks)
|
||||
* [Backup your instance](backup.html)
|
||||
* [Configuration tips](general-tips-for-customizing-pleroma-fe.html)
|
||||
* [Hardening your instance](hardening.html)
|
||||
* [How to activate mediaproxy](howto_mediaproxy.html)
|
||||
* [Small Pleroma-FE customizations](small_customizations.html)
|
||||
* [Updating your instance](updating.html)
|
||||
|
||||
## 質問ある?
|
||||
|
||||
|
|
|
|||
|
|
@ -284,12 +284,12 @@ If you opted to allow sudo for the `pleroma` user but would like to remove the a
|
|||
#### Further reading
|
||||
|
||||
* [Admin tasks](Admin tasks)
|
||||
* [Backup your instance](Backup-your-instance)
|
||||
* [Configuration tips](General tips for customizing pleroma fe)
|
||||
* [Hardening your instance](Hardening-your-instance)
|
||||
* [How to activate mediaproxy](How-to-activate-mediaproxy)
|
||||
* [Small Pleroma-FE customizations](Small customizations)
|
||||
* [Updating your instance](Updating-your-instance)
|
||||
* [Backup your instance](backup.html)
|
||||
* [Configuration tips](general-tips-for-customizing-pleroma-fe.html)
|
||||
* [Hardening your instance](hardening.html)
|
||||
* [How to activate mediaproxy](howto_mediaproxy.html)
|
||||
* [Small Pleroma-FE customizations](small_customizations.html)
|
||||
* [Updating your instance](updating.html)
|
||||
|
||||
## Questions
|
||||
|
||||
|
|
|
|||
153
docs/installation/migrating_from_source_otp_en.md
Normal file
153
docs/installation/migrating_from_source_otp_en.md
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
# Switching a from-source install to OTP releases
|
||||
## What are OTP releases?
|
||||
OTP releases are as close as you can get to binary releases with Erlang/Elixir. The release is self-contained, and provides everything needed to boot it, it is easily administered via the provided shell script to open up a remote console, start/stop/restart the release, start in the background, send remote commands, and more.
|
||||
### Can I still run the develop branch if I decide to use them?
|
||||
Yes, we produce builds for every commit in `develop`. However `develop` is considered unstable, please don't use it in production because of faster access to new features, unless you need them as an app developer.
|
||||
## Why would one want to switch?
|
||||
Benefits of OTP releases over from-source installs include:
|
||||
* **Less space used.** OTP releases come without source code, build tools, have docs and debug symbols stripped from the compiled bytecode and do not cointain tests, docs, revision history.
|
||||
* **Minimal system dependencies.** Excluding the database and reverse proxy, only `curl`, `unzip` and `ncurses` are needed to download and run the release. Because Erlang runtime and Elixir are shipped with Pleroma, one can use the latest BEAM optimizations and Pleroma features, without having to worry about outdated system repos or a missing `erlang-*` package.
|
||||
* **Potentially less bugs and better performance.** This extends on the previous point, because we have control over exactly what gets shipped, we can tweak the VM arguments and forget about weird bugs due to Erlang/Elixir version mismatches.
|
||||
* **Faster and less bug-prone mix tasks.** On a from-source install one has to wait untill a new Pleroma node is started for each mix task and they execute outside of the instance context (for example if a user was deleted via a mix task, the instance will have no knowledge of that and continue to display status count and follows before the cache expires). Mix tasks in OTP releases are executed by calling into a running instance via RPC, which solves both of these problems.
|
||||
|
||||
### Sounds great, how do I switch?
|
||||
Currently we support Linux machines with GNU (e.g. Debian, Ubuntu) or musl (e.g. Alpine) libc and `x86_64`, `aarch64` or `armv7l` CPUs. If you are unsure, check the [Detecting flavour](otp_en.html#detecting-flavour) section in OTP install guide. If your platform is supported, proceed with the guide, if not check the [My platform is not supported](#my-platform-is-not-supported) section.
|
||||
### I don't think it is worth the effort, can I stay on a from-source install?
|
||||
Yes, currently there are no plans to deprecate them.
|
||||
|
||||
### My platform is not supported
|
||||
If you think your platform is a popular choice for running Pleroma instances, or has the potential to become one, you can [file an issue on our Gitlab](https://git.pleroma.social/pleroma/pleroma/issues/new). If not, guides on how to build and update releases by yourself will be available soon.
|
||||
## Pre-requisites
|
||||
You will be running commands as root. If you aren't root already, please elevate your priviledges by executing `sudo su`/`su`.
|
||||
|
||||
The system needs to have `curl` and `unzip` installed for downloading and unpacking release builds.
|
||||
|
||||
Debian/Ubuntu:
|
||||
```sh
|
||||
apt install curl unzip
|
||||
```
|
||||
Alpine:
|
||||
```
|
||||
apk add curl unzip
|
||||
|
||||
```
|
||||
## Moving content out of the application directory
|
||||
When using OTP releases the application directory changes with every version so it would be a bother to keep content there (and also dangerous unless `--no-rm` option is used when updating). Fortunately almost all paths in Pleroma are configurable, so it is possible to move them out of there.
|
||||
|
||||
Pleroma should be stopped before proceeding.
|
||||
|
||||
### Moving uploads/custom public files directory
|
||||
```sh
|
||||
# Create uploads directory and set proper permissions (skip if using a remote uploader)
|
||||
# Note: It does not have to be `/var/lib/pleroma/uploads`, you can configure it to be something else later
|
||||
mkdir -p /var/lib/pleroma/uploads
|
||||
chown -R pleroma /var/lib/pleroma
|
||||
|
||||
# Create custom public files directory
|
||||
# Note: It does not have to be `/var/lib/pleroma/static`, you can configure it to be something else later
|
||||
mkdir -p /var/lib/pleroma/static
|
||||
chown -R pleroma /var/lib/pleroma
|
||||
|
||||
# If you use the local uploader with default settings your uploads should be located in `~pleroma/uploads`
|
||||
mv ~pleroma/uploads/* /var/lib/pleroma/uploads
|
||||
|
||||
# If you have created the custom public files directory with default settings it should be located in `~pleroma/instance/static`
|
||||
mv ~pleroma/instance/static /var/lib/pleroma/static
|
||||
```
|
||||
|
||||
### Moving emoji
|
||||
Assuming you have all emojis in subdirectories of `priv/static/emoji` moving them can be done with
|
||||
```sh
|
||||
mkdir /var/lib/pleroma/static/emoji
|
||||
ls -d ~pleroma/priv/static/emoji/*/ | xargs -i sh -c 'mv "{}" "/var/lib/pleroma/static/emoji/$(basename {})"'
|
||||
```
|
||||
|
||||
But, if for some reason you have custom emojis in the root directory you should copy the whole directory instead.
|
||||
```sh
|
||||
mv ~pleroma/priv/static/emoji /var/lib/pleroma/static/emoji
|
||||
```
|
||||
and then copy custom emojis to `/var/lib/pleroma/static/emoji/custom`.
|
||||
|
||||
This is needed because storing custom emojis in the root directory is deprecated, but if you just move them to `/var/lib/pleroma/static/emoji/custom` it will break emoji urls on old posts.
|
||||
|
||||
Note that globs have been replaced with `pack_extensions`, so if your emojis are not in png/gif you should [modify the default value](config.html#emoji).
|
||||
|
||||
### Moving the config
|
||||
```sh
|
||||
# Create the config directory
|
||||
# The default path for Pleroma config is /etc/pleroma/config.exs
|
||||
# but it can be set via PLEROMA_CONFIG_PATH environment variable
|
||||
mkdir -p /etc/pleroma
|
||||
|
||||
# Move the config file
|
||||
mv ~pleroma/config/prod.secret.exs /etc/pleroma/config.exs
|
||||
|
||||
# Change `use Mix.Config` at the top to `import Config`
|
||||
$EDITOR /etc/pleroma/config.exs
|
||||
```
|
||||
## Installing the release
|
||||
Before proceeding, get the flavour from [Detecting flavour](otp_en.html#detecting-flavour) section in OTP installation guide.
|
||||
```sh
|
||||
# Delete all files in pleroma user's directory
|
||||
rm -r ~pleroma/*
|
||||
|
||||
# Set the flavour environment variable to the string you got in Detecting flavour section.
|
||||
# For example if the flavour is `arm64-musl` the command will be
|
||||
export FLAVOUR="arm64-musl"
|
||||
|
||||
# Clone the release build into a temporary directory and unpack it
|
||||
# Replace `master` with `develop` if you want to run the develop branch
|
||||
su pleroma -s $SHELL -lc "
|
||||
curl 'https://git.pleroma.social/api/v4/projects/2/jobs/artifacts/master/download?job=$FLAVOUR' -o /tmp/pleroma.zip
|
||||
unzip /tmp/pleroma.zip -d /tmp/
|
||||
"
|
||||
|
||||
# Move the release to the home directory and delete temporary files
|
||||
su pleroma -s $SHELL -lc "
|
||||
mv /tmp/release/* ~pleroma/
|
||||
rmdir /tmp/release
|
||||
rm /tmp/pleroma.zip
|
||||
"
|
||||
|
||||
# Start the instance to verify that everything is working as expected
|
||||
su pleroma -s $SHELL -lc "./bin/pleroma daemon"
|
||||
|
||||
# Wait for about 20 seconds and query the instance endpoint, if it shows your uri, name and email correctly, you are configured correctly
|
||||
sleep 20 && curl http://localhost:4000/api/v1/instance
|
||||
|
||||
# Stop the instance
|
||||
su pleroma -s $SHELL -lc "./bin/pleroma stop"
|
||||
```
|
||||
|
||||
## Setting up a system service
|
||||
OTP releases have different service files than from-source installs so they need to be copied over again.
|
||||
|
||||
**Warning:** The service files assume pleroma user's home directory is `/opt/pleroma`, please make sure all paths fit your installation.
|
||||
|
||||
Debian/Ubuntu:
|
||||
```sh
|
||||
# Copy the service into a proper directory
|
||||
cp ~pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
|
||||
|
||||
# Reload service files
|
||||
systemctl daemon-reload
|
||||
|
||||
# Reenable pleroma to start on boot
|
||||
systemctl reenable pleroma
|
||||
|
||||
# Start pleroma
|
||||
systemctl start pleroma
|
||||
```
|
||||
|
||||
Alpine:
|
||||
```sh
|
||||
# Copy the service into a proper directory
|
||||
cp -f ~pleroma/installation/init.d/pleroma /etc/init.d/pleroma
|
||||
|
||||
# Start pleroma
|
||||
rc-service pleroma start
|
||||
```
|
||||
## Running mix tasks
|
||||
Refer to [Running mix tasks](otp_en.html#running-mix-tasks) section from OTP release installation guide.
|
||||
## Updating
|
||||
Refer to [Updating](otp_en.html#updating) section from OTP release installation guide.
|
||||
261
docs/installation/otp_en.md
Normal file
261
docs/installation/otp_en.md
Normal file
|
|
@ -0,0 +1,261 @@
|
|||
# Installing on Linux using OTP releases
|
||||
|
||||
## Pre-requisites
|
||||
* A machine running Linux with GNU (e.g. Debian, Ubuntu) or musl (e.g. Alpine) libc and `x86_64`, `aarch64` or `armv7l` CPU, you have root access to. If you are not sure if it's compatible see [Detecting flavour section](#detecting-flavour) below
|
||||
* A (sub)domain pointed to the machine
|
||||
|
||||
You will be running commands as root. If you aren't root already, please elevate your priviledges by executing `sudo su`/`su`.
|
||||
|
||||
While in theory OTP releases are possbile to install on any compatible machine, for the sake of simplicity this guide focuses only on Debian/Ubuntu/Alpine.
|
||||
|
||||
### Detecting flavour
|
||||
|
||||
Paste the following into the shell:
|
||||
```sh
|
||||
arch="$(uname -m)";if [ "$arch" = "x86_64" ];then arch="amd64";elif [ "$arch" = "armv7l" ];then arch="arm";elif [ "$arch" = "aarch64" ];then arch="arm64";else echo "Unsupported arch: $arch">&2;fi;if getconf GNU_LIBC_VERSION>/dev/null;then libc_postfix="";elif [ "$(ldd 2>&1|head -c 9)" = "musl libc" ];then libc_postfix="-musl";elif [ "$(find /lib/libc.musl*|wc -l)" ];then libc_postfix="-musl";else echo "Unsupported libc">&2;fi;echo "$arch$libc_postfix"
|
||||
```
|
||||
|
||||
If your platform is supported the output will contain the flavour string, you will need it later. If not, this just means that we don't build releases for your platform, you can still try installing from source.
|
||||
|
||||
### Installing the required packages
|
||||
|
||||
Other than things bundled in the OTP release Pleroma depends on:
|
||||
* curl (to download the release build)
|
||||
* unzip (needed to unpack release builds)
|
||||
* ncurses (ERTS won't run without it)
|
||||
* PostgreSQL (also utilizes extensions in postgresql-contrib)
|
||||
* nginx (could be swapped with another reverse proxy but this guide covers only it)
|
||||
* certbot (for Let's Encrypt certificates, could be swapped with another ACME client, but this guide covers only it)
|
||||
|
||||
Debian/Ubuntu:
|
||||
```sh
|
||||
apt install curl unzip libncurses5 postgresql postgresql-contrib nginx certbot
|
||||
```
|
||||
Alpine:
|
||||
|
||||
```sh
|
||||
echo "http://nl.alpinelinux.org/alpine/latest-stable/community" >> /etc/apk/repositories
|
||||
apk update
|
||||
apk add curl unzip ncurses postgresql postgresql-contrib nginx certbot
|
||||
```
|
||||
|
||||
## Setup
|
||||
### Configuring PostgreSQL
|
||||
#### (Optional) Installing RUM indexes
|
||||
RUM indexes are an alternative indexing scheme that is not included in PostgreSQL by default. You can read more about them on the [Configuration page](config.html#rum-indexing-for-full-text-search). They are completely optional and most of the time are not worth it, especially if you are running a single user instance (unless you absolutely need ordered search results).
|
||||
|
||||
Debian/Ubuntu (available only on Buster/19.04):
|
||||
```sh
|
||||
apt install postgresql-11-rum
|
||||
```
|
||||
Alpine:
|
||||
```sh
|
||||
apk add git build-base postgresql-dev
|
||||
git clone https://github.com/postgrespro/rum /tmp/rum
|
||||
cd /tmp/rum
|
||||
make USE_PGXS=1
|
||||
make USE_PGXS=1 install
|
||||
cd
|
||||
rm -r /tmp/rum
|
||||
```
|
||||
#### (Optional) Performance configuration
|
||||
For optimal performance, you may use [PGTune](https://pgtune.leopard.in.ua), don't forget to restart postgresql after editing the configuration
|
||||
|
||||
Debian/Ubuntu:
|
||||
```sh
|
||||
systemctl restart postgresql
|
||||
```
|
||||
Alpine:
|
||||
```sh
|
||||
rc-service postgresql restart
|
||||
```
|
||||
### Installing Pleroma
|
||||
```sh
|
||||
# Create the Pleroma user
|
||||
adduser --system --shell /bin/false --home /opt/pleroma pleroma
|
||||
|
||||
# Set the flavour environment variable to the string you got in Detecting flavour section.
|
||||
# For example if the flavour is `arm64-musl` the command will be
|
||||
export FLAVOUR="arm64-musl"
|
||||
|
||||
# Clone the release build into a temporary directory and unpack it
|
||||
su pleroma -s $SHELL -lc "
|
||||
curl 'https://git.pleroma.social/api/v4/projects/2/jobs/artifacts/master/download?job=$FLAVOUR' -o /tmp/pleroma.zip
|
||||
unzip /tmp/pleroma.zip -d /tmp/
|
||||
"
|
||||
|
||||
# Move the release to the home directory and delete temporary files
|
||||
su pleroma -s $SHELL -lc "
|
||||
mv /tmp/release/* /opt/pleroma
|
||||
rmdir /tmp/release
|
||||
rm /tmp/pleroma.zip
|
||||
"
|
||||
# Create uploads directory and set proper permissions (skip if planning to use a remote uploader)
|
||||
# Note: It does not have to be `/var/lib/pleroma/uploads`, the config generator will ask about the upload directory later
|
||||
|
||||
mkdir -p /var/lib/pleroma/uploads
|
||||
chown -R pleroma /var/lib/pleroma
|
||||
|
||||
# Create custom public files directory (custom emojis, frontend bundle overrides, robots.txt, etc.)
|
||||
# Note: It does not have to be `/var/lib/pleroma/static`, the config generator will ask about the custom public files directory later
|
||||
mkdir -p /var/lib/pleroma/static
|
||||
chown -R pleroma /var/lib/pleroma
|
||||
|
||||
# Create a config directory
|
||||
mkdir -p /etc/pleroma
|
||||
chown -R pleroma /etc/pleroma
|
||||
|
||||
# Run the config generator
|
||||
su pleroma -s $SHELL -lc "./bin/pleroma_ctl instance gen --output /etc/pleroma/config.exs --output-psql /tmp/setup_db.psql"
|
||||
|
||||
# Create the postgres database
|
||||
su postgres -s $SHELL -lc "psql -f /tmp/setup_db.psql"
|
||||
|
||||
# Create the database schema
|
||||
su pleroma -s $SHELL -lc "./bin/pleroma_ctl migrate"
|
||||
|
||||
# If you have installed RUM indexes uncommend and run
|
||||
# su pleroma -s $SHELL -lc "./bin/pleroma_ctl migrate --migrations-path priv/repo/optional_migrations/rum_indexing/"
|
||||
|
||||
# Start the instance to verify that everything is working as expected
|
||||
su pleroma -s $SHELL -lc "./bin/pleroma daemon"
|
||||
|
||||
# Wait for about 20 seconds and query the instance endpoint, if it shows your uri, name and email correctly, you are configured correctly
|
||||
sleep 20 && curl http://localhost:4000/api/v1/instance
|
||||
|
||||
# Stop the instance
|
||||
su pleroma -s $SHELL -lc "./bin/pleroma stop"
|
||||
```
|
||||
|
||||
### Setting up nginx and getting Let's Encrypt SSL certificaties
|
||||
|
||||
```sh
|
||||
# Get a Let's Encrypt certificate
|
||||
certbot certonly --standalone --preferred-challenges http -d yourinstance.tld
|
||||
|
||||
# Copy the Pleroma nginx configuration to the nginx folder
|
||||
# The location of nginx configs is dependent on the distro
|
||||
|
||||
# For Debian/Ubuntu:
|
||||
cp /opt/pleroma/installation/pleroma.nginx /etc/nginx/sites-available/pleroma.nginx
|
||||
ln -s /etc/nginx/sites-available/pleroma.nginx /etc/nginx/sites-enabled/pleroma.nginx
|
||||
# For Alpine:
|
||||
cp /opt/pleroma/installation/pleroma.nginx /etc/nginx/conf.d/pleroma.conf
|
||||
# If your distro does not have either of those you can append
|
||||
# `include /etc/nginx/pleroma.conf` to the end of the http section in /etc/nginx/nginx.conf and
|
||||
cp /opt/pleroma/installation/pleroma.nginx /etc/nginx/pleroma.conf
|
||||
|
||||
# Edit the nginx config replacing example.tld with your (sub)domain
|
||||
$EDITOR path-to-nginx-config
|
||||
|
||||
# Verify that the config is valid
|
||||
nginx -t
|
||||
|
||||
# Start nginx
|
||||
# For Debian/Ubuntu:
|
||||
systemctl start nginx
|
||||
# For Alpine:
|
||||
rc-service nginx start
|
||||
```
|
||||
|
||||
At this point if you open your (sub)domain in a browser you should see a 502 error, that's because pleroma is not started yet.
|
||||
|
||||
### Setting up a system service
|
||||
Debian/Ubuntu:
|
||||
```sh
|
||||
# Copy the service into a proper directory
|
||||
cp /opt/pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
|
||||
|
||||
# Start pleroma and enable it on boot
|
||||
systemctl start pleroma
|
||||
systemctl enable pleroma
|
||||
```
|
||||
Alpine:
|
||||
```sh
|
||||
# Copy the service into a proper directory
|
||||
cp /opt/pleroma/installation/init.d/pleroma /etc/init.d/pleroma
|
||||
|
||||
# Start pleroma and enable it on boot
|
||||
rc-service pleroma start
|
||||
rc-update add pleroma
|
||||
```
|
||||
|
||||
If everything worked, you should see Pleroma-FE when visiting your domain. If that didn't happen, try reviewing the installation steps, starting Pleroma in the foreground and seeing if there are any errrors.
|
||||
|
||||
Still doesn't work? Feel free to contact us on [#pleroma on freenode](https://webchat.freenode.net/?channels=%23pleroma) or via matrix at <https://matrix.heldscal.la/#/room/#freenode_#pleroma:matrix.org>, you can also [file an issue on our Gitlab](https://git.pleroma.social/pleroma/pleroma/issues/new)
|
||||
|
||||
## Post installation
|
||||
|
||||
### Setting up auto-renew Let's Encrypt certificate
|
||||
```sh
|
||||
# Create the directory for webroot challenges
|
||||
mkdir -p /var/lib/letsencrypt
|
||||
|
||||
# Uncomment the webroot method
|
||||
$EDITOR path-to-nginx-config
|
||||
|
||||
# Verify that the config is valid
|
||||
nginx -t
|
||||
```
|
||||
Debian/Ubuntu:
|
||||
```sh
|
||||
# Restart nginx
|
||||
systemctl restart nginx
|
||||
|
||||
# Ensure the webroot menthod and post hook is working
|
||||
certbot renew --cert-name yourinstance.tld --webroot -w /var/lib/letsencrypt/ --dry-run --post-hook 'systemctl nginx reload'
|
||||
|
||||
# Add it to the daily cron
|
||||
echo '#!/bin/sh
|
||||
certbot renew --cert-name yourinstance.tld --webroot -w /var/lib/letsencrypt/ --post-hook "systemctl reload nginx"
|
||||
' > /etc/cron.daily/renew-pleroma-cert
|
||||
chmod +x /etc/cron.daily/renew-pleroma-cert
|
||||
|
||||
# If everything worked the output should contain /etc/cron.daily/renew-pleroma-cert
|
||||
run-parts --test /etc/cron.daily
|
||||
```
|
||||
Alpine:
|
||||
```sh
|
||||
# Restart nginx
|
||||
rc-service nginx restart
|
||||
|
||||
# Start the cron daemon and make it start on boot
|
||||
rc-service crond start
|
||||
rc-update add crond
|
||||
|
||||
# Ensure the webroot menthod and post hook is working
|
||||
certbot renew --cert-name yourinstance.tld --webroot -w /var/lib/letsencrypt/ --dry-run --post-hook 'rc-service nginx reload'
|
||||
|
||||
# Add it to the daily cron
|
||||
echo '#!/bin/sh
|
||||
certbot renew --cert-name yourinstance.tld --webroot -w /var/lib/letsencrypt/ --post-hook "rc-service nginx reload"
|
||||
' > /etc/periodic/daily/renew-pleroma-cert
|
||||
chmod +x /etc/periodic/daily/renew-pleroma-cert
|
||||
|
||||
# If everything worked this should output /etc/periodic/daily/renew-pleroma-cert
|
||||
run-parts --test /etc/periodic/daily
|
||||
```
|
||||
### Running mix tasks
|
||||
Throughout the wiki and guides there is a lot of references to mix tasks. Since `mix` is a build tool, you can't just call `mix pleroma.task`, instead you should call `pleroma_ctl` stripping pleroma/ecto namespace.
|
||||
|
||||
So for example, if the task is `mix pleroma.user set admin --admin`, you should run it like this:
|
||||
```sh
|
||||
su pleroma -s $SHELL -lc "./bin/pleroma_ctl user set admin --admin"
|
||||
```
|
||||
### Updating
|
||||
Generally, doing the following is enough:
|
||||
```sh
|
||||
# Download the new release
|
||||
su pleroma -s $SHELL -lc "./bin/pleroma_ctl update"
|
||||
|
||||
# Migrate the database, you are advised to stop the instance before doing that
|
||||
su pleroma -s $SHELL -lc "./bin/pleroma_ctl migrate"
|
||||
```
|
||||
But you should **always check the release notes/changelog** in case there are config deprecations, special update steps, etc.
|
||||
|
||||
## Further reading
|
||||
* [Configuration](config.html)
|
||||
* [Pleroma's base config.exs](https://git.pleroma.social/pleroma/pleroma/blob/master/config/config.exs)
|
||||
* [Hardening your instance](hardening.html)
|
||||
* [Pleroma Clients](clients.html)
|
||||
* [Emoji pack manager](Mix.Tasks.Pleroma.Emoji.html)
|
||||
|
|
@ -14,17 +14,19 @@ server {
|
|||
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
return 301 https://$server_name$request_uri;
|
||||
|
||||
# Uncomment this if you need to use the 'webroot' method with certbot. Make sure
|
||||
# that the directory exists and that it is accessible by the webserver. If you followed
|
||||
# the guide, you already ran 'sudo mkdir -p /var/lib/letsencrypt' to create the folder.
|
||||
# the guide, you already ran 'mkdir -p /var/lib/letsencrypt' to create the folder.
|
||||
# You may need to load this file with the ssl server block commented out, run certbot
|
||||
# to get the certificate, and then uncomment it.
|
||||
#
|
||||
# location ~ /\.well-known/acme-challenge {
|
||||
# root /var/lib/letsencrypt/.well-known/acme-challenge;
|
||||
# root /var/lib/letsencrypt/;
|
||||
# }
|
||||
location / {
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
}
|
||||
|
||||
# Enable SSL session caching for improved performance
|
||||
|
|
|
|||
|
|
@ -2,19 +2,23 @@
|
|||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.Common do
|
||||
defmodule Mix.Pleroma do
|
||||
@doc "Common functions to be reused in mix tasks"
|
||||
def start_pleroma do
|
||||
Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
|
||||
{:ok, _} = Application.ensure_all_started(:pleroma)
|
||||
end
|
||||
|
||||
def load_pleroma do
|
||||
Application.load(:pleroma)
|
||||
end
|
||||
|
||||
def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
|
||||
Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
|
||||
end
|
||||
|
||||
def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
|
||||
prompt_message = "#{prompt} [#{defname || defval}]"
|
||||
prompt_message = "#{prompt} [#{defname || defval}] "
|
||||
|
||||
input =
|
||||
if mix_shell?(),
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
defmodule Mix.Tasks.Pleroma.Benchmark do
|
||||
import Mix.Pleroma
|
||||
use Mix.Task
|
||||
alias Mix.Tasks.Pleroma.Common
|
||||
|
||||
def run(["search"]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
Benchee.run(%{
|
||||
"search" => fn ->
|
||||
|
|
@ -13,7 +13,7 @@ defmodule Mix.Tasks.Pleroma.Benchmark do
|
|||
end
|
||||
|
||||
def run(["tag"]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
Benchee.run(%{
|
||||
"tag" => fn ->
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
defmodule Mix.Tasks.Pleroma.Config do
|
||||
use Mix.Task
|
||||
alias Mix.Tasks.Pleroma.Common
|
||||
import Mix.Pleroma
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.AdminAPI.Config
|
||||
@shortdoc "Manages the location of the config"
|
||||
|
|
@ -17,14 +17,14 @@ defmodule Mix.Tasks.Pleroma.Config do
|
|||
"""
|
||||
|
||||
def run(["migrate_to_db"]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
if Pleroma.Config.get([:instance, :dynamic_configuration]) do
|
||||
Application.get_all_env(:pleroma)
|
||||
|> Enum.reject(fn {k, _v} -> k in [Pleroma.Repo, :env] end)
|
||||
|> Enum.each(fn {k, v} ->
|
||||
key = to_string(k) |> String.replace("Elixir.", "")
|
||||
{:ok, _} = Config.update_or_create(%{key: key, value: v})
|
||||
{:ok, _} = Config.update_or_create(%{group: "pleroma", key: key, value: v})
|
||||
Mix.shell().info("#{key} is migrated.")
|
||||
end)
|
||||
|
||||
|
|
@ -36,25 +36,36 @@ defmodule Mix.Tasks.Pleroma.Config do
|
|||
end
|
||||
end
|
||||
|
||||
def run(["migrate_from_db", env]) do
|
||||
Common.start_pleroma()
|
||||
def run(["migrate_from_db", env, delete?]) do
|
||||
start_pleroma()
|
||||
|
||||
delete? = if delete? == "true", do: true, else: false
|
||||
|
||||
if Pleroma.Config.get([:instance, :dynamic_configuration]) do
|
||||
config_path = "config/#{env}.migrated.secret.exs"
|
||||
config_path = "config/#{env}.exported_from_db.secret.exs"
|
||||
|
||||
{:ok, file} = File.open(config_path, [:write])
|
||||
IO.write(file, "use Mix.Config\r\n")
|
||||
|
||||
Repo.all(Config)
|
||||
|> Enum.each(fn config ->
|
||||
mark = if String.starts_with?(config.key, "Pleroma."), do: ",", else: ":"
|
||||
mark =
|
||||
if String.starts_with?(config.key, "Pleroma.") or
|
||||
String.starts_with?(config.key, "Ueberauth"),
|
||||
do: ",",
|
||||
else: ":"
|
||||
|
||||
IO.write(
|
||||
file,
|
||||
"config :pleroma, #{config.key}#{mark} #{inspect(Config.from_binary(config.value))}\r\n"
|
||||
"config :#{config.group}, #{config.key}#{mark} #{
|
||||
inspect(Config.from_binary(config.value))
|
||||
}\r\n"
|
||||
)
|
||||
|
||||
if delete? do
|
||||
{:ok, _} = Repo.delete(config)
|
||||
Mix.shell().info("#{config.key} deleted from DB.")
|
||||
end
|
||||
end)
|
||||
|
||||
File.close(file)
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.Database do
|
||||
alias Mix.Tasks.Pleroma.Common
|
||||
alias Pleroma.Conversation
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
require Logger
|
||||
import Mix.Pleroma
|
||||
use Mix.Task
|
||||
|
||||
@shortdoc "A collection of database related tasks"
|
||||
|
|
@ -45,7 +45,7 @@ defmodule Mix.Tasks.Pleroma.Database do
|
|||
]
|
||||
)
|
||||
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
Logger.info("Removing embedded objects")
|
||||
|
||||
Repo.query!(
|
||||
|
|
@ -66,12 +66,12 @@ defmodule Mix.Tasks.Pleroma.Database do
|
|||
end
|
||||
|
||||
def run(["bump_all_conversations"]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
Conversation.bump_for_all_activities()
|
||||
end
|
||||
|
||||
def run(["update_users_following_followers_counts"]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
users = Repo.all(User)
|
||||
Enum.each(users, &User.remove_duplicated_following/1)
|
||||
|
|
@ -89,7 +89,7 @@ defmodule Mix.Tasks.Pleroma.Database do
|
|||
]
|
||||
)
|
||||
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
deadline = Pleroma.Config.get([:instance, :remote_post_retention_days])
|
||||
|
||||
|
|
|
|||
49
lib/mix/tasks/pleroma/ecto/ecto.ex
Normal file
49
lib/mix/tasks/pleroma/ecto/ecto.ex
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-onl
|
||||
defmodule Mix.Tasks.Pleroma.Ecto do
|
||||
@doc """
|
||||
Ensures the given repository's migrations path exists on the file system.
|
||||
"""
|
||||
@spec ensure_migrations_path(Ecto.Repo.t(), Keyword.t()) :: String.t()
|
||||
def ensure_migrations_path(repo, opts) do
|
||||
path = opts[:migrations_path] || Path.join(source_repo_priv(repo), "migrations")
|
||||
|
||||
path =
|
||||
case Path.type(path) do
|
||||
:relative ->
|
||||
Path.join(Application.app_dir(:pleroma), path)
|
||||
|
||||
:absolute ->
|
||||
path
|
||||
end
|
||||
|
||||
if not File.dir?(path) do
|
||||
raise_missing_migrations(Path.relative_to_cwd(path), repo)
|
||||
end
|
||||
|
||||
path
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the private repository path relative to the source.
|
||||
"""
|
||||
def source_repo_priv(repo) do
|
||||
config = repo.config()
|
||||
priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
|
||||
Path.join(Application.app_dir(:pleroma), priv)
|
||||
end
|
||||
|
||||
defp raise_missing_migrations(path, repo) do
|
||||
raise("""
|
||||
Could not find migrations directory #{inspect(path)}
|
||||
for repo #{inspect(repo)}.
|
||||
This may be because you are in a new project and the
|
||||
migration directory has not been created yet. Creating an
|
||||
empty directory at the path above will fix this error.
|
||||
If you expected existing migrations to be found, please
|
||||
make sure your repository has been properly configured
|
||||
and the configured path exists.
|
||||
""")
|
||||
end
|
||||
end
|
||||
63
lib/mix/tasks/pleroma/ecto/migrate.ex
Normal file
63
lib/mix/tasks/pleroma/ecto/migrate.ex
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-onl
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.Ecto.Migrate do
|
||||
use Mix.Task
|
||||
import Mix.Pleroma
|
||||
require Logger
|
||||
|
||||
@shortdoc "Wrapper on `ecto.migrate` task."
|
||||
|
||||
@aliases [
|
||||
n: :step,
|
||||
v: :to
|
||||
]
|
||||
|
||||
@switches [
|
||||
all: :boolean,
|
||||
step: :integer,
|
||||
to: :integer,
|
||||
quiet: :boolean,
|
||||
log_sql: :boolean,
|
||||
strict_version_order: :boolean,
|
||||
migrations_path: :string
|
||||
]
|
||||
|
||||
@moduledoc """
|
||||
Changes `Logger` level to `:info` before start migration.
|
||||
Changes level back when migration ends.
|
||||
|
||||
## Start migration
|
||||
|
||||
mix pleroma.ecto.migrate [OPTIONS]
|
||||
|
||||
Options:
|
||||
- see https://hexdocs.pm/ecto/2.0.0/Mix.Tasks.Ecto.Migrate.html
|
||||
"""
|
||||
|
||||
@impl true
|
||||
def run(args \\ []) do
|
||||
load_pleroma()
|
||||
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
|
||||
|
||||
opts =
|
||||
if opts[:to] || opts[:step] || opts[:all],
|
||||
do: opts,
|
||||
else: Keyword.put(opts, :all, true)
|
||||
|
||||
opts =
|
||||
if opts[:quiet],
|
||||
do: Keyword.merge(opts, log: false, log_sql: false),
|
||||
else: opts
|
||||
|
||||
path = Mix.Tasks.Pleroma.Ecto.ensure_migrations_path(Pleroma.Repo, opts)
|
||||
|
||||
level = Logger.level()
|
||||
Logger.configure(level: :info)
|
||||
|
||||
{:ok, _, _} = Ecto.Migrator.with_repo(Pleroma.Repo, &Ecto.Migrator.run(&1, path, :up, opts))
|
||||
|
||||
Logger.configure(level: level)
|
||||
end
|
||||
end
|
||||
67
lib/mix/tasks/pleroma/ecto/rollback.ex
Normal file
67
lib/mix/tasks/pleroma/ecto/rollback.ex
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-onl
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.Ecto.Rollback do
|
||||
use Mix.Task
|
||||
import Mix.Pleroma
|
||||
require Logger
|
||||
@shortdoc "Wrapper on `ecto.rollback` task"
|
||||
|
||||
@aliases [
|
||||
n: :step,
|
||||
v: :to
|
||||
]
|
||||
|
||||
@switches [
|
||||
all: :boolean,
|
||||
step: :integer,
|
||||
to: :integer,
|
||||
start: :boolean,
|
||||
quiet: :boolean,
|
||||
log_sql: :boolean,
|
||||
migrations_path: :string
|
||||
]
|
||||
|
||||
@moduledoc """
|
||||
Changes `Logger` level to `:info` before start rollback.
|
||||
Changes level back when rollback ends.
|
||||
|
||||
## Start rollback
|
||||
|
||||
mix pleroma.ecto.rollback
|
||||
|
||||
Options:
|
||||
- see https://hexdocs.pm/ecto/2.0.0/Mix.Tasks.Ecto.Rollback.html
|
||||
"""
|
||||
|
||||
@impl true
|
||||
def run(args \\ []) do
|
||||
load_pleroma()
|
||||
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
|
||||
|
||||
opts =
|
||||
if opts[:to] || opts[:step] || opts[:all],
|
||||
do: opts,
|
||||
else: Keyword.put(opts, :step, 1)
|
||||
|
||||
opts =
|
||||
if opts[:quiet],
|
||||
do: Keyword.merge(opts, log: false, log_sql: false),
|
||||
else: opts
|
||||
|
||||
path = Mix.Tasks.Pleroma.Ecto.ensure_migrations_path(Pleroma.Repo, opts)
|
||||
|
||||
level = Logger.level()
|
||||
Logger.configure(level: :info)
|
||||
|
||||
if Pleroma.Config.get(:env) == :test do
|
||||
Logger.info("Rollback succesfully")
|
||||
else
|
||||
{:ok, _, _} =
|
||||
Ecto.Migrator.with_repo(Pleroma.Repo, &Ecto.Migrator.run(&1, path, :down, opts))
|
||||
end
|
||||
|
||||
Logger.configure(level: level)
|
||||
end
|
||||
end
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Mix.Tasks.Pleroma.Instance do
|
||||
use Mix.Task
|
||||
alias Mix.Tasks.Pleroma.Common
|
||||
import Mix.Pleroma
|
||||
|
||||
@shortdoc "Manages Pleroma instance"
|
||||
@moduledoc """
|
||||
|
|
@ -29,8 +29,11 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||
- `--dbname DBNAME` - the name of the database to use
|
||||
- `--dbuser DBUSER` - the user (aka role) to use for the database connection
|
||||
- `--dbpass DBPASS` - the password to use for the database connection
|
||||
- `--rum Y/N` - Whether to enable RUM indexes
|
||||
- `--indexable Y/N` - Allow/disallow indexing site by search engines
|
||||
- `--db-configurable Y/N` - Allow/disallow configuring instance from admin part
|
||||
- `--uploads-dir` - the directory uploads go in when using a local uploader
|
||||
- `--static-dir` - the directory custom public files should be read from (custom emojis, frontend bundle overrides, robots.txt, etc.)
|
||||
"""
|
||||
|
||||
def run(["gen" | rest]) do
|
||||
|
|
@ -49,8 +52,11 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||
dbname: :string,
|
||||
dbuser: :string,
|
||||
dbpass: :string,
|
||||
rum: :string,
|
||||
indexable: :string,
|
||||
db_configurable: :string
|
||||
db_configurable: :string,
|
||||
uploads_dir: :string,
|
||||
static_dir: :string
|
||||
],
|
||||
aliases: [
|
||||
o: :output,
|
||||
|
|
@ -70,7 +76,7 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||
if proceed? do
|
||||
[domain, port | _] =
|
||||
String.split(
|
||||
Common.get_option(
|
||||
get_option(
|
||||
options,
|
||||
:domain,
|
||||
"What domain will your instance use? (e.g pleroma.soykaf.com)"
|
||||
|
|
@ -79,16 +85,16 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||
) ++ [443]
|
||||
|
||||
name =
|
||||
Common.get_option(
|
||||
get_option(
|
||||
options,
|
||||
:instance_name,
|
||||
"What is the name of your instance? (e.g. Pleroma/Soykaf)"
|
||||
)
|
||||
|
||||
email = Common.get_option(options, :admin_email, "What is your admin email address?")
|
||||
email = get_option(options, :admin_email, "What is your admin email address?")
|
||||
|
||||
notify_email =
|
||||
Common.get_option(
|
||||
get_option(
|
||||
options,
|
||||
:notify_email,
|
||||
"What email address do you want to use for sending email notifications?",
|
||||
|
|
@ -96,7 +102,7 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||
)
|
||||
|
||||
indexable =
|
||||
Common.get_option(
|
||||
get_option(
|
||||
options,
|
||||
:indexable,
|
||||
"Do you want search engines to index your site? (y/n)",
|
||||
|
|
@ -104,21 +110,19 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||
) === "y"
|
||||
|
||||
db_configurable? =
|
||||
Common.get_option(
|
||||
get_option(
|
||||
options,
|
||||
:db_configurable,
|
||||
"Do you want to be able to configure instance from admin part? (y/n)",
|
||||
"y"
|
||||
"Do you want to store the configuration in the database (allows controlling it from admin-fe)? (y/n)",
|
||||
"n"
|
||||
) === "y"
|
||||
|
||||
dbhost =
|
||||
Common.get_option(options, :dbhost, "What is the hostname of your database?", "localhost")
|
||||
dbhost = get_option(options, :dbhost, "What is the hostname of your database?", "localhost")
|
||||
|
||||
dbname =
|
||||
Common.get_option(options, :dbname, "What is the name of your database?", "pleroma_dev")
|
||||
dbname = get_option(options, :dbname, "What is the name of your database?", "pleroma")
|
||||
|
||||
dbuser =
|
||||
Common.get_option(
|
||||
get_option(
|
||||
options,
|
||||
:dbuser,
|
||||
"What is the user used to connect to your database?",
|
||||
|
|
@ -126,7 +130,7 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||
)
|
||||
|
||||
dbpass =
|
||||
Common.get_option(
|
||||
get_option(
|
||||
options,
|
||||
:dbpass,
|
||||
"What is the password used to connect to your database?",
|
||||
|
|
@ -134,13 +138,38 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||
"autogenerated"
|
||||
)
|
||||
|
||||
rum_enabled =
|
||||
get_option(
|
||||
options,
|
||||
:rum,
|
||||
"Would you like to use RUM indices?",
|
||||
"n"
|
||||
) === "y"
|
||||
|
||||
uploads_dir =
|
||||
get_option(
|
||||
options,
|
||||
:uploads_dir,
|
||||
"What directory should media uploads go in (when using the local uploader)?",
|
||||
Pleroma.Config.get([Pleroma.Uploaders.Local, :uploads])
|
||||
)
|
||||
|
||||
static_dir =
|
||||
get_option(
|
||||
options,
|
||||
:static_dir,
|
||||
"What directory should custom public files be read from (custom emojis, frontend bundle overrides, robots.txt, etc.)?",
|
||||
Pleroma.Config.get([:instance, :static_dir])
|
||||
)
|
||||
|
||||
secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64)
|
||||
signing_salt = :crypto.strong_rand_bytes(8) |> Base.encode64() |> binary_part(0, 8)
|
||||
{web_push_public_key, web_push_private_key} = :crypto.generate_key(:ecdh, :prime256v1)
|
||||
template_dir = Application.app_dir(:pleroma, "priv") <> "/templates"
|
||||
|
||||
result_config =
|
||||
EEx.eval_file(
|
||||
"sample_config.eex" |> Path.expand(__DIR__),
|
||||
template_dir <> "/sample_config.eex",
|
||||
domain: domain,
|
||||
port: port,
|
||||
email: email,
|
||||
|
|
@ -150,47 +179,38 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||
dbname: dbname,
|
||||
dbuser: dbuser,
|
||||
dbpass: dbpass,
|
||||
version: Pleroma.Mixfile.project() |> Keyword.get(:version),
|
||||
secret: secret,
|
||||
signing_salt: signing_salt,
|
||||
web_push_public_key: Base.url_encode64(web_push_public_key, padding: false),
|
||||
web_push_private_key: Base.url_encode64(web_push_private_key, padding: false),
|
||||
db_configurable?: db_configurable?
|
||||
db_configurable?: db_configurable?,
|
||||
static_dir: static_dir,
|
||||
uploads_dir: uploads_dir,
|
||||
rum_enabled: rum_enabled
|
||||
)
|
||||
|
||||
result_psql =
|
||||
EEx.eval_file(
|
||||
"sample_psql.eex" |> Path.expand(__DIR__),
|
||||
template_dir <> "/sample_psql.eex",
|
||||
dbname: dbname,
|
||||
dbuser: dbuser,
|
||||
dbpass: dbpass
|
||||
dbpass: dbpass,
|
||||
rum_enabled: rum_enabled
|
||||
)
|
||||
|
||||
Common.shell_info(
|
||||
"Writing config to #{config_path}. You should rename it to config/prod.secret.exs or config/dev.secret.exs."
|
||||
)
|
||||
shell_info("Writing config to #{config_path}.")
|
||||
|
||||
File.write(config_path, result_config)
|
||||
Common.shell_info("Writing #{psql_path}.")
|
||||
shell_info("Writing the postgres script to #{psql_path}.")
|
||||
File.write(psql_path, result_psql)
|
||||
|
||||
write_robots_txt(indexable)
|
||||
write_robots_txt(indexable, template_dir)
|
||||
|
||||
Common.shell_info(
|
||||
"\n" <>
|
||||
"""
|
||||
To get started:
|
||||
1. Verify the contents of the generated files.
|
||||
2. Run `sudo -u postgres psql -f #{Common.escape_sh_path(psql_path)}`.
|
||||
""" <>
|
||||
if config_path in ["config/dev.secret.exs", "config/prod.secret.exs"] do
|
||||
""
|
||||
else
|
||||
"3. Run `mv #{Common.escape_sh_path(config_path)} 'config/prod.secret.exs'`."
|
||||
end
|
||||
shell_info(
|
||||
"\n All files successfully written! Refer to the installation instructions for your platform for next steps"
|
||||
)
|
||||
else
|
||||
Common.shell_error(
|
||||
shell_error(
|
||||
"The task would have overwritten the following files:\n" <>
|
||||
(Enum.map(paths, &"- #{&1}\n") |> Enum.join("")) <>
|
||||
"Rerun with `--force` to overwrite them."
|
||||
|
|
@ -198,10 +218,10 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||
end
|
||||
end
|
||||
|
||||
defp write_robots_txt(indexable) do
|
||||
defp write_robots_txt(indexable, template_dir) do
|
||||
robots_txt =
|
||||
EEx.eval_file(
|
||||
Path.expand("robots_txt.eex", __DIR__),
|
||||
template_dir <> "/robots_txt.eex",
|
||||
indexable: indexable
|
||||
)
|
||||
|
||||
|
|
@ -215,10 +235,10 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
|||
|
||||
if File.exists?(robots_txt_path) do
|
||||
File.cp!(robots_txt_path, "#{robots_txt_path}.bak")
|
||||
Common.shell_info("Backing up existing robots.txt to #{robots_txt_path}.bak")
|
||||
shell_info("Backing up existing robots.txt to #{robots_txt_path}.bak")
|
||||
end
|
||||
|
||||
File.write(robots_txt_path, robots_txt)
|
||||
Common.shell_info("Writing #{robots_txt_path}.")
|
||||
shell_info("Writing #{robots_txt_path}.")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Mix.Tasks.Pleroma.Relay do
|
||||
use Mix.Task
|
||||
alias Mix.Tasks.Pleroma.Common
|
||||
import Mix.Pleroma
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
|
||||
@shortdoc "Manages remote relays"
|
||||
|
|
@ -24,24 +24,24 @@ defmodule Mix.Tasks.Pleroma.Relay do
|
|||
Example: ``mix pleroma.relay unfollow https://example.org/relay``
|
||||
"""
|
||||
def run(["follow", target]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
with {:ok, _activity} <- Relay.follow(target) do
|
||||
# put this task to sleep to allow the genserver to push out the messages
|
||||
:timer.sleep(500)
|
||||
else
|
||||
{:error, e} -> Common.shell_error("Error while following #{target}: #{inspect(e)}")
|
||||
{:error, e} -> shell_error("Error while following #{target}: #{inspect(e)}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(["unfollow", target]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
with {:ok, _activity} <- Relay.unfollow(target) do
|
||||
# put this task to sleep to allow the genserver to push out the messages
|
||||
:timer.sleep(500)
|
||||
else
|
||||
{:error, e} -> Common.shell_error("Error while following #{target}: #{inspect(e)}")
|
||||
{:error, e} -> shell_error("Error while following #{target}: #{inspect(e)}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Mix.Tasks.Pleroma.Uploads do
|
||||
use Mix.Task
|
||||
alias Mix.Tasks.Pleroma.Common
|
||||
import Mix.Pleroma
|
||||
alias Pleroma.Upload
|
||||
alias Pleroma.Uploaders.Local
|
||||
require Logger
|
||||
|
|
@ -24,7 +24,7 @@ defmodule Mix.Tasks.Pleroma.Uploads do
|
|||
"""
|
||||
def run(["migrate_local", target_uploader | args]) do
|
||||
delete? = Enum.member?(args, "--delete")
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
local_path = Pleroma.Config.get!([Local, :uploads])
|
||||
uploader = Module.concat(Pleroma.Uploaders, target_uploader)
|
||||
|
||||
|
|
@ -38,10 +38,10 @@ defmodule Mix.Tasks.Pleroma.Uploads do
|
|||
Pleroma.Config.put([Upload, :uploader], uploader)
|
||||
end
|
||||
|
||||
Common.shell_info("Migrating files from local #{local_path} to #{to_string(uploader)}")
|
||||
shell_info("Migrating files from local #{local_path} to #{to_string(uploader)}")
|
||||
|
||||
if delete? do
|
||||
Common.shell_info(
|
||||
shell_info(
|
||||
"Attention: uploaded files will be deleted, hope you have backups! (--delete ; cancel with ^C)"
|
||||
)
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ defmodule Mix.Tasks.Pleroma.Uploads do
|
|||
|> Enum.filter(& &1)
|
||||
|
||||
total_count = length(uploads)
|
||||
Common.shell_info("Found #{total_count} uploads")
|
||||
shell_info("Found #{total_count} uploads")
|
||||
|
||||
uploads
|
||||
|> Task.async_stream(
|
||||
|
|
@ -90,7 +90,7 @@ defmodule Mix.Tasks.Pleroma.Uploads do
|
|||
:ok
|
||||
|
||||
error ->
|
||||
Common.shell_error("failed to upload #{inspect(upload.path)}: #{inspect(error)}")
|
||||
shell_error("failed to upload #{inspect(upload.path)}: #{inspect(error)}")
|
||||
end
|
||||
end,
|
||||
timeout: 150_000
|
||||
|
|
@ -99,10 +99,10 @@ defmodule Mix.Tasks.Pleroma.Uploads do
|
|||
# credo:disable-for-next-line Credo.Check.Warning.UnusedEnumOperation
|
||||
|> Enum.reduce(0, fn done, count ->
|
||||
count = count + length(done)
|
||||
Common.shell_info("Uploaded #{count}/#{total_count} files")
|
||||
shell_info("Uploaded #{count}/#{total_count} files")
|
||||
count
|
||||
end)
|
||||
|
||||
Common.shell_info("Done!")
|
||||
shell_info("Done!")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@
|
|||
defmodule Mix.Tasks.Pleroma.User do
|
||||
use Mix.Task
|
||||
import Ecto.Changeset
|
||||
alias Mix.Tasks.Pleroma.Common
|
||||
import Mix.Pleroma
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserInviteToken
|
||||
alias Pleroma.Web.OAuth
|
||||
|
||||
@shortdoc "Manages Pleroma users"
|
||||
@moduledoc """
|
||||
|
|
@ -49,6 +50,10 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
|
||||
mix pleroma.user delete_activities NICKNAME
|
||||
|
||||
## Sign user out from all applications (delete user's OAuth tokens and authorizations).
|
||||
|
||||
mix pleroma.user sign_out NICKNAME
|
||||
|
||||
## Deactivate or activate the user's account.
|
||||
|
||||
mix pleroma.user toggle_activated NICKNAME
|
||||
|
|
@ -115,7 +120,7 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
admin? = Keyword.get(options, :admin, false)
|
||||
assume_yes? = Keyword.get(options, :assume_yes, false)
|
||||
|
||||
Common.shell_info("""
|
||||
shell_info("""
|
||||
A user will be created with the following information:
|
||||
- nickname: #{nickname}
|
||||
- email: #{email}
|
||||
|
|
@ -128,10 +133,10 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
- admin: #{if(admin?, do: "true", else: "false")}
|
||||
""")
|
||||
|
||||
proceed? = assume_yes? or Common.shell_yes?("Continue?")
|
||||
proceed? = assume_yes? or shell_yes?("Continue?")
|
||||
|
||||
if proceed? do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
params = %{
|
||||
nickname: nickname,
|
||||
|
|
@ -145,7 +150,7 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
changeset = User.register_changeset(%User{}, params, need_confirmation: false)
|
||||
{:ok, _user} = User.register(changeset)
|
||||
|
||||
Common.shell_info("User #{nickname} created")
|
||||
shell_info("User #{nickname} created")
|
||||
|
||||
if moderator? do
|
||||
run(["set", nickname, "--moderator"])
|
||||
|
|
@ -159,64 +164,64 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
run(["reset_password", nickname])
|
||||
end
|
||||
else
|
||||
Common.shell_info("User will not be created.")
|
||||
shell_info("User will not be created.")
|
||||
end
|
||||
end
|
||||
|
||||
def run(["rm", nickname]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||
User.perform(:delete, user)
|
||||
Common.shell_info("User #{nickname} deleted.")
|
||||
shell_info("User #{nickname} deleted.")
|
||||
else
|
||||
_ ->
|
||||
Common.shell_error("No local user #{nickname}")
|
||||
shell_error("No local user #{nickname}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(["toggle_activated", nickname]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||
{:ok, user} = User.deactivate(user, !user.info.deactivated)
|
||||
|
||||
Common.shell_info(
|
||||
shell_info(
|
||||
"Activation status of #{nickname}: #{if(user.info.deactivated, do: "de", else: "")}activated"
|
||||
)
|
||||
else
|
||||
_ ->
|
||||
Common.shell_error("No user #{nickname}")
|
||||
shell_error("No user #{nickname}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(["reset_password", nickname]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname),
|
||||
{:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do
|
||||
Common.shell_info("Generated password reset token for #{user.nickname}")
|
||||
shell_info("Generated password reset token for #{user.nickname}")
|
||||
|
||||
IO.puts(
|
||||
"URL: #{
|
||||
Pleroma.Web.Router.Helpers.util_url(
|
||||
Pleroma.Web.Router.Helpers.reset_password_url(
|
||||
Pleroma.Web.Endpoint,
|
||||
:show_password_reset,
|
||||
:reset,
|
||||
token.token
|
||||
)
|
||||
}"
|
||||
)
|
||||
else
|
||||
_ ->
|
||||
Common.shell_error("No local user #{nickname}")
|
||||
shell_error("No local user #{nickname}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(["unsubscribe", nickname]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||
Common.shell_info("Deactivating #{user.nickname}")
|
||||
shell_info("Deactivating #{user.nickname}")
|
||||
User.deactivate(user)
|
||||
|
||||
{:ok, friends} = User.get_friends(user)
|
||||
|
|
@ -224,7 +229,7 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
Enum.each(friends, fn friend ->
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
Common.shell_info("Unsubscribing #{friend.nickname} from #{user.nickname}")
|
||||
shell_info("Unsubscribing #{friend.nickname} from #{user.nickname}")
|
||||
User.unfollow(user, friend)
|
||||
end)
|
||||
|
||||
|
|
@ -233,16 +238,16 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
if Enum.empty?(user.following) do
|
||||
Common.shell_info("Successfully unsubscribed all followers from #{user.nickname}")
|
||||
shell_info("Successfully unsubscribed all followers from #{user.nickname}")
|
||||
end
|
||||
else
|
||||
_ ->
|
||||
Common.shell_error("No user #{nickname}")
|
||||
shell_error("No user #{nickname}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(["set", nickname | rest]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
{options, [], []} =
|
||||
OptionParser.parse(
|
||||
|
|
@ -274,33 +279,33 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
end
|
||||
else
|
||||
_ ->
|
||||
Common.shell_error("No local user #{nickname}")
|
||||
shell_error("No local user #{nickname}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(["tag", nickname | tags]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||
user = user |> User.tag(tags)
|
||||
|
||||
Common.shell_info("Tags of #{user.nickname}: #{inspect(tags)}")
|
||||
shell_info("Tags of #{user.nickname}: #{inspect(tags)}")
|
||||
else
|
||||
_ ->
|
||||
Common.shell_error("Could not change user tags for #{nickname}")
|
||||
shell_error("Could not change user tags for #{nickname}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(["untag", nickname | tags]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||
user = user |> User.untag(tags)
|
||||
|
||||
Common.shell_info("Tags of #{user.nickname}: #{inspect(tags)}")
|
||||
shell_info("Tags of #{user.nickname}: #{inspect(tags)}")
|
||||
else
|
||||
_ ->
|
||||
Common.shell_error("Could not change user tags for #{nickname}")
|
||||
shell_error("Could not change user tags for #{nickname}")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -321,14 +326,12 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
end)
|
||||
|> Enum.into(%{})
|
||||
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
with {:ok, val} <- options[:expires_at],
|
||||
options = Map.put(options, :expires_at, val),
|
||||
{:ok, invite} <- UserInviteToken.create_invite(options) do
|
||||
Common.shell_info(
|
||||
"Generated user invite token " <> String.replace(invite.invite_type, "_", " ")
|
||||
)
|
||||
shell_info("Generated user invite token " <> String.replace(invite.invite_type, "_", " "))
|
||||
|
||||
url =
|
||||
Pleroma.Web.Router.Helpers.redirect_url(
|
||||
|
|
@ -340,14 +343,14 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
IO.puts(url)
|
||||
else
|
||||
error ->
|
||||
Common.shell_error("Could not create invite token: #{inspect(error)}")
|
||||
shell_error("Could not create invite token: #{inspect(error)}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(["invites"]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
Common.shell_info("Invites list:")
|
||||
shell_info("Invites list:")
|
||||
|
||||
UserInviteToken.list_invites()
|
||||
|> Enum.each(fn invite ->
|
||||
|
|
@ -361,7 +364,7 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
" | Max use: #{max_use} Left use: #{max_use - invite.uses}"
|
||||
end
|
||||
|
||||
Common.shell_info(
|
||||
shell_info(
|
||||
"ID: #{invite.id} | Token: #{invite.token} | Token type: #{invite.invite_type} | Used: #{
|
||||
invite.used
|
||||
}#{expire_info}#{using_info}"
|
||||
|
|
@ -370,40 +373,54 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
end
|
||||
|
||||
def run(["revoke_invite", token]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
with {:ok, invite} <- UserInviteToken.find_by_token(token),
|
||||
{:ok, _} <- UserInviteToken.update_invite(invite, %{used: true}) do
|
||||
Common.shell_info("Invite for token #{token} was revoked.")
|
||||
shell_info("Invite for token #{token} was revoked.")
|
||||
else
|
||||
_ -> Common.shell_error("No invite found with token #{token}")
|
||||
_ -> shell_error("No invite found with token #{token}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(["delete_activities", nickname]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||
{:ok, _} = User.delete_user_activities(user)
|
||||
Common.shell_info("User #{nickname} statuses deleted.")
|
||||
shell_info("User #{nickname} statuses deleted.")
|
||||
else
|
||||
_ ->
|
||||
Common.shell_error("No local user #{nickname}")
|
||||
shell_error("No local user #{nickname}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(["toggle_confirmed", nickname]) do
|
||||
Common.start_pleroma()
|
||||
start_pleroma()
|
||||
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||
{:ok, user} = User.toggle_confirmation(user)
|
||||
|
||||
message = if user.info.confirmation_pending, do: "needs", else: "doesn't need"
|
||||
|
||||
Common.shell_info("#{nickname} #{message} confirmation.")
|
||||
shell_info("#{nickname} #{message} confirmation.")
|
||||
else
|
||||
_ ->
|
||||
Common.shell_error("No local user #{nickname}")
|
||||
shell_error("No local user #{nickname}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(["sign_out", nickname]) do
|
||||
start_pleroma()
|
||||
|
||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||
OAuth.Token.delete_user_tokens(user)
|
||||
OAuth.Authorization.delete_user_authorizations(user)
|
||||
|
||||
shell_info("#{nickname} signed out from all apps.")
|
||||
else
|
||||
_ ->
|
||||
shell_error("No local user #{nickname}")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -416,7 +433,7 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
|
||||
{:ok, user} = User.update_and_set_cache(user_cng)
|
||||
|
||||
Common.shell_info("Moderator status of #{user.nickname}: #{user.info.is_moderator}")
|
||||
shell_info("Moderator status of #{user.nickname}: #{user.info.is_moderator}")
|
||||
user
|
||||
end
|
||||
|
||||
|
|
@ -429,7 +446,7 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
|
||||
{:ok, user} = User.update_and_set_cache(user_cng)
|
||||
|
||||
Common.shell_info("Admin status of #{user.nickname}: #{user.info.is_admin}")
|
||||
shell_info("Admin status of #{user.nickname}: #{user.info.is_admin}")
|
||||
user
|
||||
end
|
||||
|
||||
|
|
@ -442,7 +459,7 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
|
||||
{:ok, user} = User.update_and_set_cache(user_cng)
|
||||
|
||||
Common.shell_info("Locked status of #{user.nickname}: #{user.info.locked}")
|
||||
shell_info("Locked status of #{user.nickname}: #{user.info.locked}")
|
||||
user
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ defmodule Pleroma.Config do
|
|||
|
||||
def put([parent_key | keys], value) do
|
||||
parent =
|
||||
Application.get_env(:pleroma, parent_key)
|
||||
Application.get_env(:pleroma, parent_key, [])
|
||||
|> put_in(keys, value)
|
||||
|
||||
Application.put_env(:pleroma, parent_key, parent)
|
||||
|
|
|
|||
|
|
@ -11,8 +11,17 @@ defmodule Pleroma.Config.TransferTask do
|
|||
def load_and_update_env do
|
||||
if Pleroma.Config.get([:instance, :dynamic_configuration]) and
|
||||
Ecto.Adapters.SQL.table_exists?(Pleroma.Repo, "config") do
|
||||
for_restart =
|
||||
Pleroma.Repo.all(Config)
|
||||
|> Enum.each(&update_env(&1))
|
||||
|> Enum.map(&update_env(&1))
|
||||
|
||||
# We need to restart applications for loaded settings take effect
|
||||
for_restart
|
||||
|> Enum.reject(&(&1 in [:pleroma, :ok]))
|
||||
|> Enum.each(fn app ->
|
||||
Application.stop(app)
|
||||
:ok = Application.start(app)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -25,11 +34,15 @@ defmodule Pleroma.Config.TransferTask do
|
|||
setting.key
|
||||
end
|
||||
|
||||
group = String.to_existing_atom(setting.group)
|
||||
|
||||
Application.put_env(
|
||||
:pleroma,
|
||||
group,
|
||||
String.to_existing_atom(key),
|
||||
Config.from_binary(setting.value)
|
||||
)
|
||||
|
||||
group
|
||||
rescue
|
||||
e ->
|
||||
require Logger
|
||||
|
|
|
|||
|
|
@ -23,13 +23,8 @@ defmodule Pleroma.Emails.UserEmail do
|
|||
defp recipient(email, name), do: {name, email}
|
||||
defp recipient(%Pleroma.User{} = user), do: recipient(user.email, user.name)
|
||||
|
||||
def password_reset_email(user, password_reset_token) when is_binary(password_reset_token) do
|
||||
password_reset_url =
|
||||
Router.Helpers.util_url(
|
||||
Endpoint,
|
||||
:show_password_reset,
|
||||
password_reset_token
|
||||
)
|
||||
def password_reset_email(user, token) when is_binary(token) do
|
||||
password_reset_url = Router.Helpers.reset_password_url(Endpoint, :reset, token)
|
||||
|
||||
html_body = """
|
||||
<h3>Reset your password at #{instance_name()}</h3>
|
||||
|
|
|
|||
|
|
@ -148,11 +148,13 @@ defmodule Pleroma.Emoji do
|
|||
if File.exists?(emoji_txt) do
|
||||
load_from_file(emoji_txt, emoji_groups)
|
||||
else
|
||||
extensions = Pleroma.Config.get([:emoji, :pack_extensions])
|
||||
|
||||
Logger.info(
|
||||
"No emoji.txt found for pack \"#{pack_name}\", assuming all .png files are emoji"
|
||||
"No emoji.txt found for pack \"#{pack_name}\", assuming all #{Enum.join(extensions, ", ")} files are emoji"
|
||||
)
|
||||
|
||||
make_shortcode_to_file_map(pack_dir, [".png"])
|
||||
make_shortcode_to_file_map(pack_dir, extensions)
|
||||
|> Enum.map(fn {shortcode, rel_file} ->
|
||||
filename = Path.join("/emoji/#{pack_name}", rel_file)
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ defmodule Pleroma.HTML do
|
|||
Cachex.fetch!(:scrubber_cache, key, fn _key ->
|
||||
result =
|
||||
content
|
||||
|> Floki.filter_out("a.mention,a.hashtag")
|
||||
|> Floki.filter_out("a.mention,a.hashtag,a[rel~=\"tag\"]")
|
||||
|> Floki.attribute("a", "href")
|
||||
|> Enum.at(0)
|
||||
|
||||
|
|
|
|||
|
|
@ -127,8 +127,7 @@ defmodule Pleroma.Notification do
|
|||
end
|
||||
end
|
||||
|
||||
def create_notifications(%Activity{data: %{"to" => _, "type" => type}} = activity)
|
||||
when type in ["Create", "Like", "Announce", "Follow"] do
|
||||
def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = activity) do
|
||||
object = Object.normalize(activity)
|
||||
|
||||
unless object && object.data["type"] == "Answer" do
|
||||
|
|
@ -140,6 +139,13 @@ defmodule Pleroma.Notification do
|
|||
end
|
||||
end
|
||||
|
||||
def create_notifications(%Activity{data: %{"to" => _, "type" => type}} = activity)
|
||||
when type in ["Like", "Announce", "Follow"] do
|
||||
users = get_notified_from_activity(activity)
|
||||
notifications = Enum.map(users, fn user -> create_notification(activity, user) end)
|
||||
{:ok, notifications}
|
||||
end
|
||||
|
||||
def create_notifications(_), do: {:ok, []}
|
||||
|
||||
# TODO move to sql, too.
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ defmodule Pleroma.PasswordResetToken do
|
|||
|> put_change(:used, true)
|
||||
end
|
||||
|
||||
@spec reset_password(binary(), map()) :: {:ok, User.t()} | {:error, binary()}
|
||||
def reset_password(token, data) do
|
||||
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
|
||||
%User{} = user <- User.get_cached_by_id(token.user_id),
|
||||
84
lib/pleroma/plugs/idempotency_plug.ex
Normal file
84
lib/pleroma/plugs/idempotency_plug.ex
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.IdempotencyPlug do
|
||||
import Phoenix.Controller, only: [json: 2]
|
||||
import Plug.Conn
|
||||
|
||||
@behaviour Plug
|
||||
|
||||
@impl true
|
||||
def init(opts), do: opts
|
||||
|
||||
# Sending idempotency keys in `GET` and `DELETE` requests has no effect
|
||||
# and should be avoided, as these requests are idempotent by definition.
|
||||
|
||||
@impl true
|
||||
def call(%{method: method} = conn, _) when method in ["POST", "PUT", "PATCH"] do
|
||||
case get_req_header(conn, "idempotency-key") do
|
||||
[key] -> process_request(conn, key)
|
||||
_ -> conn
|
||||
end
|
||||
end
|
||||
|
||||
def call(conn, _), do: conn
|
||||
|
||||
def process_request(conn, key) do
|
||||
case Cachex.get(:idempotency_cache, key) do
|
||||
{:ok, nil} ->
|
||||
cache_resposnse(conn, key)
|
||||
|
||||
{:ok, record} ->
|
||||
send_cached(conn, key, record)
|
||||
|
||||
{atom, message} when atom in [:ignore, :error] ->
|
||||
render_error(conn, message)
|
||||
end
|
||||
end
|
||||
|
||||
defp cache_resposnse(conn, key) do
|
||||
register_before_send(conn, fn conn ->
|
||||
[request_id] = get_resp_header(conn, "x-request-id")
|
||||
content_type = get_content_type(conn)
|
||||
|
||||
record = {request_id, content_type, conn.status, conn.resp_body}
|
||||
{:ok, _} = Cachex.put(:idempotency_cache, key, record)
|
||||
|
||||
conn
|
||||
|> put_resp_header("idempotency-key", key)
|
||||
|> put_resp_header("x-original-request-id", request_id)
|
||||
end)
|
||||
end
|
||||
|
||||
defp send_cached(conn, key, record) do
|
||||
{request_id, content_type, status, body} = record
|
||||
|
||||
conn
|
||||
|> put_resp_header("idempotency-key", key)
|
||||
|> put_resp_header("idempotent-replayed", "true")
|
||||
|> put_resp_header("x-original-request-id", request_id)
|
||||
|> put_resp_content_type(content_type)
|
||||
|> send_resp(status, body)
|
||||
|> halt()
|
||||
end
|
||||
|
||||
defp render_error(conn, message) do
|
||||
conn
|
||||
|> put_status(:unprocessable_entity)
|
||||
|> json(%{error: message})
|
||||
|> halt()
|
||||
end
|
||||
|
||||
defp get_content_type(conn) do
|
||||
[content_type] = get_resp_header(conn, "content-type")
|
||||
|
||||
if String.contains?(content_type, ";") do
|
||||
content_type
|
||||
|> String.split(";")
|
||||
|> hd()
|
||||
else
|
||||
content_type
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -6,18 +6,18 @@ defmodule Pleroma.ReleaseTasks do
|
|||
@repo Pleroma.Repo
|
||||
|
||||
def run(args) do
|
||||
Mix.Tasks.Pleroma.Common.start_pleroma()
|
||||
[task | args] = String.split(args)
|
||||
|
||||
case task do
|
||||
"migrate" -> migrate()
|
||||
"migrate" -> migrate(args)
|
||||
"create" -> create()
|
||||
"rollback" -> rollback(String.to_integer(Enum.at(args, 0)))
|
||||
"rollback" -> rollback(args)
|
||||
task -> mix_task(task, args)
|
||||
end
|
||||
end
|
||||
|
||||
defp mix_task(task, args) do
|
||||
Application.load(:pleroma)
|
||||
{:ok, modules} = :application.get_key(:pleroma, :modules)
|
||||
|
||||
module =
|
||||
|
|
@ -35,15 +35,17 @@ defmodule Pleroma.ReleaseTasks do
|
|||
end
|
||||
end
|
||||
|
||||
def migrate do
|
||||
{:ok, _, _} = Ecto.Migrator.with_repo(@repo, &Ecto.Migrator.run(&1, :up, all: true))
|
||||
def migrate(args) do
|
||||
Mix.Tasks.Pleroma.Ecto.Migrate.run(args)
|
||||
end
|
||||
|
||||
def rollback(version) do
|
||||
{:ok, _, _} = Ecto.Migrator.with_repo(@repo, &Ecto.Migrator.run(&1, :down, to: version))
|
||||
def rollback(args) do
|
||||
Mix.Tasks.Pleroma.Ecto.Rollback.run(args)
|
||||
end
|
||||
|
||||
def create do
|
||||
Application.load(:pleroma)
|
||||
|
||||
case @repo.__adapter__.storage_up(@repo.config) do
|
||||
:ok ->
|
||||
IO.puts("The database for #{inspect(@repo)} has been created")
|
||||
|
|
|
|||
34
lib/pleroma/repo_streamer.ex
Normal file
34
lib/pleroma/repo_streamer.ex
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.RepoStreamer do
|
||||
alias Pleroma.Repo
|
||||
import Ecto.Query
|
||||
|
||||
def chunk_stream(query, chunk_size) do
|
||||
Stream.unfold(0, fn
|
||||
:halt ->
|
||||
{[], :halt}
|
||||
|
||||
last_id ->
|
||||
query
|
||||
|> order_by(asc: :id)
|
||||
|> where([r], r.id > ^last_id)
|
||||
|> limit(^chunk_size)
|
||||
|> Repo.all()
|
||||
|> case do
|
||||
[] ->
|
||||
{[], :halt}
|
||||
|
||||
records ->
|
||||
last_id = List.last(records).id
|
||||
{records, last_id}
|
||||
end
|
||||
end)
|
||||
|> Stream.take_while(fn
|
||||
[] -> false
|
||||
_ -> true
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
@ -10,10 +10,19 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilename do
|
|||
"""
|
||||
@behaviour Pleroma.Upload.Filter
|
||||
|
||||
def filter(upload) do
|
||||
extension = List.last(String.split(upload.name, "."))
|
||||
name = Pleroma.Config.get([__MODULE__, :text], random(extension))
|
||||
{:ok, %Pleroma.Upload{upload | name: name}}
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Upload
|
||||
|
||||
def filter(%Upload{name: name} = upload) do
|
||||
extension = List.last(String.split(name, "."))
|
||||
name = predefined_name(extension) || random(extension)
|
||||
{:ok, %Upload{upload | name: name}}
|
||||
end
|
||||
|
||||
@spec predefined_name(String.t()) :: String.t() | nil
|
||||
defp predefined_name(extension) do
|
||||
with name when not is_nil(name) <- Config.get([__MODULE__, :text]),
|
||||
do: String.replace(name, "{extension}", extension)
|
||||
end
|
||||
|
||||
defp random(extension) do
|
||||
|
|
|
|||
|
|
@ -9,12 +9,14 @@ defmodule Pleroma.User do
|
|||
import Ecto.Query
|
||||
|
||||
alias Comeonin.Pbkdf2
|
||||
alias Ecto.Multi
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Keys
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Registration
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.RepoStreamer
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
|
@ -193,27 +195,24 @@ defmodule Pleroma.User do
|
|||
end
|
||||
|
||||
def password_update_changeset(struct, params) do
|
||||
changeset =
|
||||
struct
|
||||
|> cast(params, [:password, :password_confirmation])
|
||||
|> validate_required([:password, :password_confirmation])
|
||||
|> validate_confirmation(:password)
|
||||
|
||||
OAuth.Token.delete_user_tokens(struct)
|
||||
OAuth.Authorization.delete_user_authorizations(struct)
|
||||
|
||||
if changeset.valid? do
|
||||
hashed = Pbkdf2.hashpwsalt(changeset.changes[:password])
|
||||
|
||||
changeset
|
||||
|> put_change(:password_hash, hashed)
|
||||
else
|
||||
changeset
|
||||
end
|
||||
|> put_password_hash
|
||||
end
|
||||
|
||||
def reset_password(user, data) do
|
||||
update_and_set_cache(password_update_changeset(user, data))
|
||||
def reset_password(%User{id: user_id} = user, data) do
|
||||
multi =
|
||||
Multi.new()
|
||||
|> Multi.update(:user, password_update_changeset(user, data))
|
||||
|> Multi.delete_all(:tokens, OAuth.Token.Query.get_by_user(user_id))
|
||||
|> Multi.delete_all(:auth, OAuth.Authorization.delete_by_user_query(user))
|
||||
|
||||
case Repo.transaction(multi) do
|
||||
{:ok, %{user: user} = _} -> set_cache(user)
|
||||
{:error, _, changeset, _} -> {:error, changeset}
|
||||
end
|
||||
end
|
||||
|
||||
def register_changeset(struct, params \\ %{}, opts \\ []) do
|
||||
|
|
@ -249,12 +248,11 @@ defmodule Pleroma.User do
|
|||
end
|
||||
|
||||
if changeset.valid? do
|
||||
hashed = Pbkdf2.hashpwsalt(changeset.changes[:password])
|
||||
ap_id = User.ap_id(%User{nickname: changeset.changes[:nickname]})
|
||||
followers = User.ap_followers(%User{nickname: changeset.changes[:nickname]})
|
||||
|
||||
changeset
|
||||
|> put_change(:password_hash, hashed)
|
||||
|> put_password_hash
|
||||
|> put_change(:ap_id, ap_id)
|
||||
|> unique_constraint(:ap_id)
|
||||
|> put_change(:following, [followers])
|
||||
|
|
@ -838,15 +836,12 @@ defmodule Pleroma.User do
|
|||
def mutes?(nil, _), do: false
|
||||
def mutes?(user, %{ap_id: ap_id}), do: Enum.member?(user.info.mutes, ap_id)
|
||||
|
||||
def blocks?(user, %{ap_id: ap_id}) do
|
||||
blocks = user.info.blocks
|
||||
domain_blocks = user.info.domain_blocks
|
||||
def blocks?(%User{info: info} = _user, %{ap_id: ap_id}) do
|
||||
blocks = info.blocks
|
||||
domain_blocks = info.domain_blocks
|
||||
%{host: host} = URI.parse(ap_id)
|
||||
|
||||
Enum.member?(blocks, ap_id) ||
|
||||
Enum.any?(domain_blocks, fn domain ->
|
||||
host == domain
|
||||
end)
|
||||
Enum.member?(blocks, ap_id) || Enum.any?(domain_blocks, &(&1 == host))
|
||||
end
|
||||
|
||||
def subscribed_to?(user, %{ap_id: ap_id}) do
|
||||
|
|
@ -932,18 +927,24 @@ defmodule Pleroma.User do
|
|||
|
||||
@spec perform(atom(), User.t()) :: {:ok, User.t()}
|
||||
def perform(:delete, %User{} = user) do
|
||||
{:ok, user} = User.deactivate(user)
|
||||
|
||||
# Remove all relationships
|
||||
{:ok, followers} = User.get_followers(user)
|
||||
|
||||
Enum.each(followers, fn follower -> User.unfollow(follower, user) end)
|
||||
Enum.each(followers, fn follower ->
|
||||
ActivityPub.unfollow(follower, user)
|
||||
User.unfollow(follower, user)
|
||||
end)
|
||||
|
||||
{:ok, friends} = User.get_friends(user)
|
||||
|
||||
Enum.each(friends, fn followed -> User.unfollow(user, followed) end)
|
||||
Enum.each(friends, fn followed ->
|
||||
ActivityPub.unfollow(user, followed)
|
||||
User.unfollow(user, followed)
|
||||
end)
|
||||
|
||||
delete_user_activities(user)
|
||||
|
||||
{:ok, _user} = Repo.delete(user)
|
||||
end
|
||||
|
||||
@spec perform(atom(), User.t()) :: {:ok, User.t()}
|
||||
|
|
@ -1016,18 +1017,35 @@ defmodule Pleroma.User do
|
|||
])
|
||||
|
||||
def delete_user_activities(%User{ap_id: ap_id} = user) do
|
||||
stream =
|
||||
ap_id
|
||||
|> Activity.query_by_actor()
|
||||
|> Repo.stream()
|
||||
|
||||
Repo.transaction(fn -> Enum.each(stream, &delete_activity(&1)) end, timeout: :infinity)
|
||||
|> RepoStreamer.chunk_stream(50)
|
||||
|> Stream.each(fn activities ->
|
||||
Enum.each(activities, &delete_activity(&1))
|
||||
end)
|
||||
|> Stream.run()
|
||||
|
||||
{:ok, user}
|
||||
end
|
||||
|
||||
defp delete_activity(%{data: %{"type" => "Create"}} = activity) do
|
||||
Object.normalize(activity) |> ActivityPub.delete()
|
||||
activity
|
||||
|> Object.normalize()
|
||||
|> ActivityPub.delete()
|
||||
end
|
||||
|
||||
defp delete_activity(%{data: %{"type" => "Like"}} = activity) do
|
||||
user = get_cached_by_ap_id(activity.actor)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
ActivityPub.unlike(user, object)
|
||||
end
|
||||
|
||||
defp delete_activity(%{data: %{"type" => "Announce"}} = activity) do
|
||||
user = get_cached_by_ap_id(activity.actor)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
ActivityPub.unannounce(user, object)
|
||||
end
|
||||
|
||||
defp delete_activity(_activity), do: "Doing nothing"
|
||||
|
|
@ -1325,4 +1343,12 @@ defmodule Pleroma.User do
|
|||
end
|
||||
|
||||
defdelegate search(query, opts \\ []), to: User.Search
|
||||
|
||||
defp put_password_hash(
|
||||
%Ecto.Changeset{valid?: true, changes: %{password: password}} = changeset
|
||||
) do
|
||||
change(changeset, password_hash: Pbkdf2.hashpwsalt(password))
|
||||
end
|
||||
|
||||
defp put_password_hash(changeset), do: changeset
|
||||
end
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ defmodule Pleroma.User.Search do
|
|||
defp search_query(query_string, for_user, following) do
|
||||
for_user
|
||||
|> base_query(following)
|
||||
|> filter_blocked_user(for_user)
|
||||
|> filter_blocked_domains(for_user)
|
||||
|> search_subqueries(query_string)
|
||||
|> union_subqueries
|
||||
|> distinct_query()
|
||||
|
|
@ -55,6 +57,25 @@ defmodule Pleroma.User.Search do
|
|||
defp base_query(_user, false), do: User
|
||||
defp base_query(user, true), do: User.get_followers_query(user)
|
||||
|
||||
defp filter_blocked_user(query, %User{info: %{blocks: blocks}})
|
||||
when length(blocks) > 0 do
|
||||
from(q in query, where: not (q.ap_id in ^blocks))
|
||||
end
|
||||
|
||||
defp filter_blocked_user(query, _), do: query
|
||||
|
||||
defp filter_blocked_domains(query, %User{info: %{domain_blocks: domain_blocks}})
|
||||
when length(domain_blocks) > 0 do
|
||||
domains = Enum.join(domain_blocks, ",")
|
||||
|
||||
from(
|
||||
q in query,
|
||||
where: fragment("substring(ap_id from '.*://([^/]*)') NOT IN (?)", ^domains)
|
||||
)
|
||||
end
|
||||
|
||||
defp filter_blocked_domains(query, _), do: query
|
||||
|
||||
defp paginate(query, limit, offset) do
|
||||
from(q in query, limit: ^limit, offset: ^offset)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -189,6 +189,22 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
end)
|
||||
end
|
||||
|
||||
def stream_out_participations(%Object{data: %{"context" => context}}, user) do
|
||||
with %Conversation{} = conversation <- Conversation.get_for_ap_id(context),
|
||||
conversation = Repo.preload(conversation, :participations),
|
||||
last_activity_id =
|
||||
fetch_latest_activity_id_for_context(conversation.ap_id, %{
|
||||
"user" => user,
|
||||
"blocking_user" => user
|
||||
}) do
|
||||
if last_activity_id do
|
||||
stream_out_participations(conversation.participations)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def stream_out_participations(_, _), do: :noop
|
||||
|
||||
def stream_out(activity) do
|
||||
public = "https://www.w3.org/ns/activitystreams#Public"
|
||||
|
||||
|
|
@ -401,7 +417,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
"to" => to,
|
||||
"deleted_activity_id" => activity && activity.id
|
||||
},
|
||||
{:ok, activity} <- insert(data, local),
|
||||
{:ok, activity} <- insert(data, local, false),
|
||||
stream_out_participations(object, user),
|
||||
_ <- decrease_replies_count_if_reply(object),
|
||||
# Changing note count prior to enqueuing federation task in order to avoid
|
||||
# race conditions on updating user.info
|
||||
|
|
|
|||
48
lib/pleroma/web/activity_pub/mrf/anti_link_spam_policy.ex
Normal file
48
lib/pleroma/web/activity_pub/mrf/anti_link_spam_policy.ex
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy do
|
||||
alias Pleroma.User
|
||||
|
||||
require Logger
|
||||
|
||||
# has the user successfully posted before?
|
||||
defp old_user?(%User{} = u) do
|
||||
u.info.note_count > 0 || u.info.follower_count > 0
|
||||
end
|
||||
|
||||
# does the post contain links?
|
||||
defp contains_links?(%{"content" => content} = _object) do
|
||||
content
|
||||
|> Floki.filter_out("a.mention,a.hashtag,a[rel~=\"tag\"],a.zrl")
|
||||
|> Floki.attribute("a", "href")
|
||||
|> length() > 0
|
||||
end
|
||||
|
||||
defp contains_links?(_), do: false
|
||||
|
||||
def filter(%{"type" => "Create", "actor" => actor, "object" => object} = message) do
|
||||
with {:ok, %User{} = u} <- User.get_or_fetch_by_ap_id(actor),
|
||||
{:contains_links, true} <- {:contains_links, contains_links?(object)},
|
||||
{:old_user, true} <- {:old_user, old_user?(u)} do
|
||||
{:ok, message}
|
||||
else
|
||||
{:contains_links, false} ->
|
||||
{:ok, message}
|
||||
|
||||
{:old_user, false} ->
|
||||
{:reject, nil}
|
||||
|
||||
{:error, _} ->
|
||||
{:reject, nil}
|
||||
|
||||
e ->
|
||||
Logger.warn("[MRF anti-link-spam] WTF: unhandled error #{inspect(e)}")
|
||||
{:reject, nil}
|
||||
end
|
||||
end
|
||||
|
||||
# in all other cases, pass through
|
||||
def filter(message), do: {:ok, message}
|
||||
end
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy do
|
||||
@moduledoc "Preloads any attachments in the MediaProxy cache by prefetching them"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||
|
||||
alias Pleroma.HTTP
|
||||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
require Logger
|
||||
|
||||
@hackney_options [
|
||||
pool: :media,
|
||||
recv_timeout: 10_000
|
||||
]
|
||||
|
||||
def perform(:prefetch, url) do
|
||||
Logger.info("Prefetching #{inspect(url)}")
|
||||
|
||||
url
|
||||
|> MediaProxy.url()
|
||||
|> HTTP.get([], adapter: @hackney_options)
|
||||
end
|
||||
|
||||
def perform(:preload, %{"object" => %{"attachment" => attachments}} = _message) do
|
||||
Enum.each(attachments, fn
|
||||
%{"url" => url} when is_list(url) ->
|
||||
url
|
||||
|> Enum.each(fn
|
||||
%{"href" => href} ->
|
||||
PleromaJobQueue.enqueue(:background, __MODULE__, [:prefetch, href])
|
||||
|
||||
x ->
|
||||
Logger.debug("Unhandled attachment URL object #{inspect(x)}")
|
||||
end)
|
||||
|
||||
x ->
|
||||
Logger.debug("Unhandled attachment #{inspect(x)}")
|
||||
end)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def filter(
|
||||
%{"type" => "Create", "object" => %{"attachment" => attachments} = _object} = message
|
||||
)
|
||||
when is_list(attachments) and length(attachments) > 0 do
|
||||
PleromaJobQueue.enqueue(:background, __MODULE__, [:preload, message])
|
||||
|
||||
{:ok, message}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def filter(message), do: {:ok, message}
|
||||
end
|
||||
|
|
@ -151,16 +151,18 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
|
||||
def create_context(context) do
|
||||
context = context || generate_id("contexts")
|
||||
changeset = Object.context_mapping(context)
|
||||
|
||||
case Repo.insert(changeset) do
|
||||
{:ok, object} ->
|
||||
# Ecto has problems accessing the constraint inside the jsonb,
|
||||
# so we explicitly check for the existed object before insert
|
||||
object = Object.get_cached_by_ap_id(context)
|
||||
|
||||
with true <- is_nil(object),
|
||||
changeset <- Object.context_mapping(context),
|
||||
{:ok, inserted_object} <- Repo.insert(changeset) do
|
||||
inserted_object
|
||||
else
|
||||
_ ->
|
||||
object
|
||||
|
||||
# This should be solved by an upsert, but it seems ecto
|
||||
# has problems accessing the constraint inside the jsonb.
|
||||
{:error, _} ->
|
||||
Object.get_cached_by_ap_id(context)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -377,18 +377,18 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||
if Pleroma.Config.get([:instance, :dynamic_configuration]) do
|
||||
updated =
|
||||
Enum.map(configs, fn
|
||||
%{"key" => key, "value" => value} ->
|
||||
{:ok, config} = Config.update_or_create(%{key: key, value: value})
|
||||
%{"group" => group, "key" => key, "value" => value} ->
|
||||
{:ok, config} = Config.update_or_create(%{group: group, key: key, value: value})
|
||||
config
|
||||
|
||||
%{"key" => key, "delete" => "true"} ->
|
||||
{:ok, _} = Config.delete(key)
|
||||
%{"group" => group, "key" => key, "delete" => "true"} ->
|
||||
{:ok, _} = Config.delete(%{group: group, key: key})
|
||||
nil
|
||||
end)
|
||||
|> Enum.reject(&is_nil(&1))
|
||||
|
||||
Pleroma.Config.TransferTask.load_and_update_env()
|
||||
Mix.Tasks.Pleroma.Config.run(["migrate_from_db", Pleroma.Config.get(:env)])
|
||||
Mix.Tasks.Pleroma.Config.run(["migrate_from_db", Pleroma.Config.get(:env), "false"])
|
||||
updated
|
||||
else
|
||||
[]
|
||||
|
|
|
|||
|
|
@ -12,26 +12,27 @@ defmodule Pleroma.Web.AdminAPI.Config do
|
|||
|
||||
schema "config" do
|
||||
field(:key, :string)
|
||||
field(:group, :string)
|
||||
field(:value, :binary)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@spec get_by_key(String.t()) :: Config.t() | nil
|
||||
def get_by_key(key), do: Repo.get_by(Config, key: key)
|
||||
@spec get_by_params(map()) :: Config.t() | nil
|
||||
def get_by_params(params), do: Repo.get_by(Config, params)
|
||||
|
||||
@spec changeset(Config.t(), map()) :: Changeset.t()
|
||||
def changeset(config, params \\ %{}) do
|
||||
config
|
||||
|> cast(params, [:key, :value])
|
||||
|> validate_required([:key, :value])
|
||||
|> unique_constraint(:key)
|
||||
|> cast(params, [:key, :group, :value])
|
||||
|> validate_required([:key, :group, :value])
|
||||
|> unique_constraint(:key, name: :config_group_key_index)
|
||||
end
|
||||
|
||||
@spec create(map()) :: {:ok, Config.t()} | {:error, Changeset.t()}
|
||||
def create(%{key: key, value: value}) do
|
||||
def create(params) do
|
||||
%Config{}
|
||||
|> changeset(%{key: key, value: transform(value)})
|
||||
|> changeset(Map.put(params, :value, transform(params[:value])))
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
|
|
@ -43,20 +44,20 @@ defmodule Pleroma.Web.AdminAPI.Config do
|
|||
end
|
||||
|
||||
@spec update_or_create(map()) :: {:ok, Config.t()} | {:error, Changeset.t()}
|
||||
def update_or_create(%{key: key} = params) do
|
||||
with %Config{} = config <- Config.get_by_key(key) do
|
||||
def update_or_create(params) do
|
||||
with %Config{} = config <- Config.get_by_params(Map.take(params, [:group, :key])) do
|
||||
Config.update(config, params)
|
||||
else
|
||||
nil -> Config.create(params)
|
||||
end
|
||||
end
|
||||
|
||||
@spec delete(String.t()) :: {:ok, Config.t()} | {:error, Changeset.t()}
|
||||
def delete(key) do
|
||||
with %Config{} = config <- Config.get_by_key(key) do
|
||||
@spec delete(map()) :: {:ok, Config.t()} | {:error, Changeset.t()}
|
||||
def delete(params) do
|
||||
with %Config{} = config <- Config.get_by_params(params) do
|
||||
Repo.delete(config)
|
||||
else
|
||||
nil -> {:error, "Config with key #{key} not found"}
|
||||
nil -> {:error, "Config with params #{inspect(params)} not found"}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -77,10 +78,21 @@ defmodule Pleroma.Web.AdminAPI.Config do
|
|||
defp do_convert({k, v} = value) when is_tuple(value),
|
||||
do: %{k => do_convert(v)}
|
||||
|
||||
defp do_convert(value) when is_binary(value) or is_atom(value) or is_map(value),
|
||||
do: value
|
||||
defp do_convert(value) when is_tuple(value), do: %{"tuple" => do_convert(Tuple.to_list(value))}
|
||||
|
||||
defp do_convert(value) when is_binary(value) or is_map(value) or is_number(value), do: value
|
||||
|
||||
defp do_convert(value) when is_atom(value) do
|
||||
string = to_string(value)
|
||||
|
||||
if String.starts_with?(string, "Elixir."),
|
||||
do: String.trim_leading(string, "Elixir."),
|
||||
else: value
|
||||
end
|
||||
|
||||
@spec transform(any()) :: binary()
|
||||
def transform(%{"tuple" => _} = entity), do: :erlang.term_to_binary(do_transform(entity))
|
||||
|
||||
def transform(entity) when is_map(entity) do
|
||||
tuples =
|
||||
for {k, v} <- entity,
|
||||
|
|
@ -101,11 +113,16 @@ defmodule Pleroma.Web.AdminAPI.Config do
|
|||
|
||||
defp do_transform(%Regex{} = value) when is_map(value), do: value
|
||||
|
||||
defp do_transform(%{"tuple" => [k, values] = entity}) when length(entity) == 2 do
|
||||
{do_transform(k), do_transform(values)}
|
||||
end
|
||||
|
||||
defp do_transform(%{"tuple" => values}) do
|
||||
Enum.reduce(values, {}, fn val, acc -> Tuple.append(acc, do_transform(val)) end)
|
||||
end
|
||||
|
||||
defp do_transform(value) when is_map(value) do
|
||||
values =
|
||||
for {key, val} <- value,
|
||||
into: [],
|
||||
do: {String.to_atom(key), do_transform(val)}
|
||||
values = for {key, val} <- value, into: [], do: {String.to_atom(key), do_transform(val)}
|
||||
|
||||
Enum.sort(values)
|
||||
end
|
||||
|
|
@ -117,15 +134,17 @@ defmodule Pleroma.Web.AdminAPI.Config do
|
|||
defp do_transform(entity) when is_list(entity) and length(entity) == 1, do: hd(entity)
|
||||
|
||||
defp do_transform(value) when is_binary(value) do
|
||||
value = String.trim(value)
|
||||
String.trim(value)
|
||||
|> do_transform_string()
|
||||
end
|
||||
|
||||
case String.length(value) do
|
||||
0 ->
|
||||
nil
|
||||
defp do_transform(value), do: value
|
||||
|
||||
_ ->
|
||||
defp do_transform_string(value) when byte_size(value) == 0, do: nil
|
||||
|
||||
defp do_transform_string(value) do
|
||||
cond do
|
||||
String.starts_with?(value, "Pleroma") ->
|
||||
String.starts_with?(value, "Pleroma") or String.starts_with?(value, "Phoenix") ->
|
||||
String.to_existing_atom("Elixir." <> value)
|
||||
|
||||
String.starts_with?(value, ":") ->
|
||||
|
|
@ -138,7 +157,4 @@ defmodule Pleroma.Web.AdminAPI.Config do
|
|||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp do_transform(value), do: value
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,8 +5,11 @@
|
|||
defmodule Pleroma.Web.AdminAPI.AccountView do
|
||||
use Pleroma.Web, :view
|
||||
|
||||
alias Pleroma.HTML
|
||||
alias Pleroma.User
|
||||
alias Pleroma.User.Info
|
||||
alias Pleroma.Web.AdminAPI.AccountView
|
||||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
def render("index.json", %{users: users, count: count, page_size: page_size}) do
|
||||
%{
|
||||
|
|
@ -17,9 +20,14 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
|
|||
end
|
||||
|
||||
def render("show.json", %{user: user}) do
|
||||
avatar = User.avatar_url(user) |> MediaProxy.url()
|
||||
display_name = HTML.strip_tags(user.name || user.nickname)
|
||||
|
||||
%{
|
||||
"id" => user.id,
|
||||
"avatar" => avatar,
|
||||
"nickname" => user.nickname,
|
||||
"display_name" => display_name,
|
||||
"deactivated" => user.info.deactivated,
|
||||
"local" => user.local,
|
||||
"roles" => Info.roles(user.info),
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigView do
|
|||
def render("show.json", %{config: config}) do
|
||||
%{
|
||||
key: config.key,
|
||||
group: config.group,
|
||||
value: Pleroma.Web.AdminAPI.Config.from_binary_to_map(config.value)
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
defmodule Pleroma.Web.AdminAPI.ReportView do
|
||||
use Pleroma.Web, :view
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.HTML
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
alias Pleroma.Web.MastodonAPI.StatusView
|
||||
|
||||
def render("index.json", %{reports: reports}) do
|
||||
|
|
@ -23,6 +23,13 @@ defmodule Pleroma.Web.AdminAPI.ReportView do
|
|||
[account_ap_id | status_ap_ids] = report.data["object"]
|
||||
account = User.get_cached_by_ap_id(account_ap_id)
|
||||
|
||||
content =
|
||||
unless is_nil(report.data["content"]) do
|
||||
HTML.filter_tags(report.data["content"])
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
statuses =
|
||||
Enum.map(status_ap_ids, fn ap_id ->
|
||||
Activity.get_by_ap_id_with_object(ap_id)
|
||||
|
|
@ -30,12 +37,19 @@ defmodule Pleroma.Web.AdminAPI.ReportView do
|
|||
|
||||
%{
|
||||
id: report.id,
|
||||
account: AccountView.render("account.json", %{user: account}),
|
||||
actor: AccountView.render("account.json", %{user: user}),
|
||||
content: report.data["content"],
|
||||
account: merge_account_views(account),
|
||||
actor: merge_account_views(user),
|
||||
content: content,
|
||||
created_at: created_at,
|
||||
statuses: StatusView.render("index.json", %{activities: statuses, as: :activity}),
|
||||
state: report.data["state"]
|
||||
}
|
||||
end
|
||||
|
||||
defp merge_account_views(%User{} = user) do
|
||||
Pleroma.Web.MastodonAPI.AccountView.render("account.json", %{user: user})
|
||||
|> Map.merge(Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user}))
|
||||
end
|
||||
|
||||
defp merge_account_views(_), do: %{}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.ActivityPub.Visibility
|
||||
|
||||
import Pleroma.Web.CommonAPI.Utils
|
||||
|
||||
|
|
@ -212,7 +213,7 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
cw <- data["spoiler_text"] || "",
|
||||
sensitive <- data["sensitive"] || Enum.member?(tags, {"#nsfw", "nsfw"}),
|
||||
full_payload <- String.trim(status <> cw),
|
||||
length when length in 1..limit <- String.length(full_payload),
|
||||
:ok <- validate_character_limit(full_payload, attachments, limit),
|
||||
object <-
|
||||
make_note_data(
|
||||
user.ap_id,
|
||||
|
|
@ -247,6 +248,8 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
|
||||
res
|
||||
else
|
||||
{:private_to_public, true} -> {:error, "The message visibility must be direct"}
|
||||
{:error, _} = e -> e
|
||||
e -> {:error, e}
|
||||
end
|
||||
end
|
||||
|
|
@ -282,12 +285,11 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
},
|
||||
object: %Object{
|
||||
data: %{
|
||||
"to" => object_to,
|
||||
"type" => "Note"
|
||||
}
|
||||
}
|
||||
} = activity <- get_by_id_or_ap_id(id_or_ap_id),
|
||||
true <- Enum.member?(object_to, "https://www.w3.org/ns/activitystreams#Public"),
|
||||
true <- Visibility.is_public?(activity),
|
||||
%{valid?: true} = info_changeset <-
|
||||
User.Info.add_pinnned_activity(user.info, activity),
|
||||
changeset <-
|
||||
|
|
|
|||
|
|
@ -504,4 +504,18 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
"inReplyTo" => object.data["id"]
|
||||
}
|
||||
end
|
||||
|
||||
def validate_character_limit(full_payload, attachments, limit) do
|
||||
length = String.length(full_payload)
|
||||
|
||||
if length < limit do
|
||||
if length > 0 or Enum.count(attachments) > 0 do
|
||||
:ok
|
||||
else
|
||||
{:error, "Cannot post an empty status without attachments"}
|
||||
end
|
||||
else
|
||||
{:error, "The status is over the character limit"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -356,6 +356,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||
|
||||
def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do
|
||||
with %User{} = user <- User.get_cached_by_id(params["id"]) do
|
||||
params =
|
||||
params
|
||||
|> Map.put("tag", params["tagged"])
|
||||
|
||||
activities = ActivityPub.fetch_user_activities(user, reading_user, params)
|
||||
|
||||
conn
|
||||
|
|
@ -544,15 +548,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||
end
|
||||
end
|
||||
|
||||
def post_status(conn, %{"status" => "", "media_ids" => media_ids} = params)
|
||||
when length(media_ids) > 0 do
|
||||
params =
|
||||
params
|
||||
|> Map.put("status", ".")
|
||||
|
||||
post_status(conn, params)
|
||||
end
|
||||
|
||||
def post_status(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do
|
||||
params =
|
||||
params
|
||||
|
|
@ -570,18 +565,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||
else
|
||||
params = Map.drop(params, ["scheduled_at"])
|
||||
|
||||
case get_cached_status_or_post(conn, params) do
|
||||
{:ignore, message} ->
|
||||
conn
|
||||
|> put_status(422)
|
||||
|> json(%{error: message})
|
||||
|
||||
case CommonAPI.post(user, params) do
|
||||
{:error, message} ->
|
||||
conn
|
||||
|> put_status(422)
|
||||
|> put_status(:unprocessable_entity)
|
||||
|> json(%{error: message})
|
||||
|
||||
{_, activity} ->
|
||||
{:ok, activity} ->
|
||||
conn
|
||||
|> put_view(StatusView)
|
||||
|> try_render("status.json", %{activity: activity, for: user, as: :activity})
|
||||
|
|
@ -589,21 +579,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||
end
|
||||
end
|
||||
|
||||
defp get_cached_status_or_post(%{assigns: %{user: user}} = conn, params) do
|
||||
idempotency_key =
|
||||
case get_req_header(conn, "idempotency-key") do
|
||||
[key] -> key
|
||||
_ -> Ecto.UUID.generate()
|
||||
end
|
||||
|
||||
Cachex.fetch(:idempotency_cache, idempotency_key, fn _ ->
|
||||
case CommonAPI.post(user, params) do
|
||||
{:ok, activity} -> activity
|
||||
{:error, message} -> {:ignore, message}
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
def delete_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||
with {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
|
||||
json(conn, %{})
|
||||
|
|
@ -853,7 +828,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||
|
||||
conn
|
||||
|> put_view(AccountView)
|
||||
|> render(AccountView, "accounts.json", %{for: user, users: users, as: :user})
|
||||
|> render("accounts.json", %{for: user, users: users, as: :user})
|
||||
else
|
||||
_ -> json(conn, [])
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
|
|||
plug(Pleroma.Plugs.RateLimiter, :search when action in [:search, :search2, :account_search])
|
||||
|
||||
def search2(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
|
||||
accounts = User.search(query, search_options(params, user))
|
||||
statuses = Activity.search(user, query)
|
||||
accounts = with_fallback(fn -> User.search(query, search_options(params, user)) end, [])
|
||||
statuses = with_fallback(fn -> Activity.search(user, query) end, [])
|
||||
tags_path = Web.base_url() <> "/tag/"
|
||||
|
||||
tags =
|
||||
|
|
@ -40,8 +40,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
|
|||
end
|
||||
|
||||
def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
|
||||
accounts = User.search(query, search_options(params, user))
|
||||
statuses = Activity.search(user, query)
|
||||
accounts = with_fallback(fn -> User.search(query, search_options(params, user)) end, [])
|
||||
statuses = with_fallback(fn -> Activity.search(user, query) end, [])
|
||||
|
||||
tags =
|
||||
query
|
||||
|
|
@ -76,4 +76,14 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
|
|||
for_user: user
|
||||
]
|
||||
end
|
||||
|
||||
defp with_fallback(f, fallback) do
|
||||
try do
|
||||
f.()
|
||||
rescue
|
||||
error ->
|
||||
Logger.error("#{__MODULE__} search error: #{inspect(error)}")
|
||||
fallback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
end
|
||||
|
||||
defp do_render("account.json", %{user: user} = opts) do
|
||||
display_name = HTML.strip_tags(user.name || user.nickname)
|
||||
|
||||
image = User.avatar_url(user) |> MediaProxy.url()
|
||||
header = User.banner_url(user) |> MediaProxy.url()
|
||||
user_info = User.get_cached_user_info(user)
|
||||
|
|
@ -96,7 +98,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
id: to_string(user.id),
|
||||
username: username_from_nickname(user.nickname),
|
||||
acct: user.nickname,
|
||||
display_name: user.name || user.nickname,
|
||||
display_name: display_name,
|
||||
locked: user_info.locked,
|
||||
created_at: Utils.to_masto_date(user.inserted_at),
|
||||
followers_count: user_info.follower_count,
|
||||
|
|
|
|||
|
|
@ -162,7 +162,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
|
|||
accountActivationRequired: Config.get([:instance, :account_activation_required], false),
|
||||
invitesEnabled: Config.get([:instance, :invites_enabled], false),
|
||||
features: features,
|
||||
restrictedNicknames: Config.get([Pleroma.User, :restricted_nicknames])
|
||||
restrictedNicknames: Config.get([Pleroma.User, :restricted_nicknames]),
|
||||
skipThreadContainment: Config.get([:instance, :skip_thread_containment], false)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -76,14 +76,16 @@ defmodule Pleroma.Web.OAuth.Authorization do
|
|||
def use_token(%Authorization{used: true}), do: {:error, "already used"}
|
||||
|
||||
@spec delete_user_authorizations(User.t()) :: {integer(), any()}
|
||||
def delete_user_authorizations(%User{id: user_id}) do
|
||||
from(
|
||||
a in Pleroma.Web.OAuth.Authorization,
|
||||
where: a.user_id == ^user_id
|
||||
)
|
||||
def delete_user_authorizations(%User{} = user) do
|
||||
user
|
||||
|> delete_by_user_query
|
||||
|> Repo.delete_all()
|
||||
end
|
||||
|
||||
def delete_by_user_query(%User{id: user_id}) do
|
||||
from(a in __MODULE__, where: a.user_id == ^user_id)
|
||||
end
|
||||
|
||||
@doc "gets auth for app by token"
|
||||
@spec get_by_token(App.t(), String.t()) :: {:ok, t()} | {:error, :not_found}
|
||||
def get_by_token(%App{id: app_id} = _app, token) do
|
||||
|
|
|
|||
|
|
@ -64,26 +64,34 @@ defmodule Pleroma.Web.OAuth.OAuthController do
|
|||
|
||||
defp handle_existing_authorization(
|
||||
%Plug.Conn{assigns: %{token: %Token{} = token}} = conn,
|
||||
params
|
||||
%{"redirect_uri" => @oob_token_redirect_uri}
|
||||
) do
|
||||
token = Repo.preload(token, :app)
|
||||
render(conn, "oob_token_exists.html", %{token: token})
|
||||
end
|
||||
|
||||
defp handle_existing_authorization(
|
||||
%Plug.Conn{assigns: %{token: %Token{} = token}} = conn,
|
||||
%{} = params
|
||||
) do
|
||||
app = Repo.preload(token, :app).app
|
||||
|
||||
redirect_uri =
|
||||
if is_binary(params["redirect_uri"]) do
|
||||
params["redirect_uri"]
|
||||
else
|
||||
default_redirect_uri(token.app)
|
||||
default_redirect_uri(app)
|
||||
end
|
||||
|
||||
if redirect_uri in String.split(app.redirect_uris) do
|
||||
redirect_uri = redirect_uri(conn, redirect_uri)
|
||||
|
||||
if redirect_uri == @oob_token_redirect_uri do
|
||||
render(conn, "oob_token_exists.html", %{token: token})
|
||||
else
|
||||
url_params = %{access_token: token.token}
|
||||
url_params = UriHelper.append_param_if_present(url_params, :state, params["state"])
|
||||
url = UriHelper.append_uri_params(redirect_uri, url_params)
|
||||
redirect(conn, external: url)
|
||||
else
|
||||
conn
|
||||
|> put_flash(:error, "Unlisted redirect_uri.")
|
||||
|> redirect(external: redirect_uri(conn, redirect_uri))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -100,18 +108,28 @@ defmodule Pleroma.Web.OAuth.OAuthController do
|
|||
end
|
||||
end
|
||||
|
||||
def after_create_authorization(%Plug.Conn{} = conn, %Authorization{} = auth, %{
|
||||
"authorization" => %{"redirect_uri" => @oob_token_redirect_uri}
|
||||
}) do
|
||||
render(conn, "oob_authorization_created.html", %{auth: auth})
|
||||
end
|
||||
|
||||
def after_create_authorization(%Plug.Conn{} = conn, %Authorization{} = auth, %{
|
||||
"authorization" => %{"redirect_uri" => redirect_uri} = auth_attrs
|
||||
}) do
|
||||
redirect_uri = redirect_uri(conn, redirect_uri)
|
||||
app = Repo.preload(auth, :app).app
|
||||
|
||||
if redirect_uri == @oob_token_redirect_uri do
|
||||
render(conn, "oob_authorization_created.html", %{auth: auth})
|
||||
else
|
||||
# An extra safety measure before we redirect (also done in `do_create_authorization/2`)
|
||||
if redirect_uri in String.split(app.redirect_uris) do
|
||||
redirect_uri = redirect_uri(conn, redirect_uri)
|
||||
url_params = %{code: auth.token}
|
||||
url_params = UriHelper.append_param_if_present(url_params, :state, auth_attrs["state"])
|
||||
url = UriHelper.append_uri_params(redirect_uri, url_params)
|
||||
redirect(conn, external: url)
|
||||
else
|
||||
conn
|
||||
|> put_flash(:error, "Unlisted redirect_uri.")
|
||||
|> redirect(external: redirect_uri(conn, redirect_uri))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -324,7 +342,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
|
|||
})
|
||||
|
||||
conn
|
||||
|> put_session(:registration_id, registration.id)
|
||||
|> put_session_registration_id(registration.id)
|
||||
|> registration_details(%{"authorization" => registration_params})
|
||||
end
|
||||
else
|
||||
|
|
@ -445,7 +463,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
|
|||
|> Scopes.validates(app.scopes)
|
||||
end
|
||||
|
||||
defp default_redirect_uri(%App{} = app) do
|
||||
def default_redirect_uri(%App{} = app) do
|
||||
app.redirect_uris
|
||||
|> String.split()
|
||||
|> Enum.at(0)
|
||||
|
|
|
|||
|
|
@ -4,25 +4,53 @@
|
|||
|
||||
defmodule Pleroma.Web.RichMedia.Helpers do
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.HTML
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.RichMedia.Parser
|
||||
|
||||
@spec validate_page_url(any()) :: :ok | :error
|
||||
defp validate_page_url(page_url) when is_binary(page_url) do
|
||||
if AutoLinker.Parser.url?(page_url, true) do
|
||||
URI.parse(page_url) |> validate_page_url
|
||||
else
|
||||
validate_tld = Application.get_env(:auto_linker, :opts)[:validate_tld]
|
||||
|
||||
page_url
|
||||
|> AutoLinker.Parser.url?(scheme: true, validate_tld: validate_tld)
|
||||
|> parse_uri(page_url)
|
||||
end
|
||||
|
||||
defp validate_page_url(%URI{host: host, scheme: scheme, authority: authority})
|
||||
when scheme == "https" and not is_nil(authority) do
|
||||
cond do
|
||||
host in Config.get([:rich_media, :ignore_hosts], []) ->
|
||||
:error
|
||||
|
||||
get_tld(host) in Config.get([:rich_media, :ignore_tld], []) ->
|
||||
:error
|
||||
|
||||
true ->
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
defp validate_page_url(%URI{authority: nil}), do: :error
|
||||
defp validate_page_url(%URI{scheme: nil}), do: :error
|
||||
defp validate_page_url(%URI{}), do: :ok
|
||||
defp validate_page_url(_), do: :error
|
||||
|
||||
defp parse_uri(true, url) do
|
||||
url
|
||||
|> URI.parse()
|
||||
|> validate_page_url
|
||||
end
|
||||
|
||||
defp parse_uri(_, _), do: :error
|
||||
|
||||
defp get_tld(host) do
|
||||
host
|
||||
|> String.split(".")
|
||||
|> Enum.reverse()
|
||||
|> hd
|
||||
end
|
||||
|
||||
def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) do
|
||||
with true <- Pleroma.Config.get([:rich_media, :enabled]),
|
||||
with true <- Config.get([:rich_media, :enabled]),
|
||||
%Object{} = object <- Object.normalize(activity),
|
||||
false <- object.data["sensitive"] || false,
|
||||
{:ok, page_url} <- HTML.extract_first_external_url(object, object.data["content"]),
|
||||
|
|
|
|||
|
|
@ -34,13 +34,15 @@ defmodule Pleroma.Web.RichMedia.Parsers.MetaTagsParser do
|
|||
|
||||
defp maybe_put_title(%{title: _} = meta, _), do: meta
|
||||
|
||||
defp maybe_put_title(meta, html) do
|
||||
defp maybe_put_title(meta, html) when meta != %{} do
|
||||
case get_page_title(html) do
|
||||
"" -> meta
|
||||
title -> Map.put_new(meta, :title, title)
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_put_title(meta, _), do: meta
|
||||
|
||||
defp get_page_title(html) do
|
||||
Floki.find(html, "title") |> Floki.text()
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ defmodule Pleroma.Web.Router do
|
|||
plug(Pleroma.Plugs.UserEnabledPlug)
|
||||
plug(Pleroma.Plugs.SetUserSessionIdPlug)
|
||||
plug(Pleroma.Plugs.EnsureUserKeyPlug)
|
||||
plug(Pleroma.Plugs.IdempotencyPlug)
|
||||
end
|
||||
|
||||
pipeline :authenticated_api do
|
||||
|
|
@ -41,6 +42,7 @@ defmodule Pleroma.Web.Router do
|
|||
plug(Pleroma.Plugs.UserEnabledPlug)
|
||||
plug(Pleroma.Plugs.SetUserSessionIdPlug)
|
||||
plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
|
||||
plug(Pleroma.Plugs.IdempotencyPlug)
|
||||
end
|
||||
|
||||
pipeline :admin_api do
|
||||
|
|
@ -57,6 +59,7 @@ defmodule Pleroma.Web.Router do
|
|||
plug(Pleroma.Plugs.SetUserSessionIdPlug)
|
||||
plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
|
||||
plug(Pleroma.Plugs.UserIsAdminPlug)
|
||||
plug(Pleroma.Plugs.IdempotencyPlug)
|
||||
end
|
||||
|
||||
pipeline :mastodon_html do
|
||||
|
|
@ -133,8 +136,8 @@ defmodule Pleroma.Web.Router do
|
|||
scope "/api/pleroma", Pleroma.Web.TwitterAPI do
|
||||
pipe_through(:pleroma_api)
|
||||
|
||||
get("/password_reset/:token", UtilController, :show_password_reset)
|
||||
post("/password_reset", UtilController, :password_reset)
|
||||
get("/password_reset/:token", PasswordController, :reset, as: :reset_password)
|
||||
post("/password_reset", PasswordController, :do_reset, as: :reset_password)
|
||||
get("/emoji", UtilController, :emoji)
|
||||
get("/captcha", UtilController, :captcha)
|
||||
get("/healthcheck", UtilController, :healthcheck)
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ defmodule Pleroma.Web.Salmon do
|
|||
do: Instances.set_reachable(url)
|
||||
|
||||
Logger.debug(fn -> "Pushed to #{url}, code #{code}" end)
|
||||
:ok
|
||||
{:ok, code}
|
||||
else
|
||||
e ->
|
||||
unless params[:unreachable_since], do: Instances.set_reachable(url)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<h2>Password Reset for <%= @user.nickname %></h2>
|
||||
<%= form_for @conn, util_path(@conn, :password_reset), [as: "data"], fn f -> %>
|
||||
<%= form_for @conn, reset_password_path(@conn, :do_reset), [as: "data"], fn f -> %>
|
||||
<div class="form-row">
|
||||
<%= label f, :password, "Password" %>
|
||||
<%= password_input f, :password %>
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.TwitterAPI.PasswordController do
|
||||
@moduledoc """
|
||||
The module containts functions for reset password.
|
||||
"""
|
||||
|
||||
use Pleroma.Web, :controller
|
||||
|
||||
require Logger
|
||||
|
||||
alias Pleroma.PasswordResetToken
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
|
||||
def reset(conn, %{"token" => token}) do
|
||||
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
|
||||
%User{} = user <- User.get_cached_by_id(token.user_id) do
|
||||
render(conn, "reset.html", %{
|
||||
token: token,
|
||||
user: user
|
||||
})
|
||||
else
|
||||
_e -> render(conn, "invalid_token.html")
|
||||
end
|
||||
end
|
||||
|
||||
def do_reset(conn, %{"data" => data}) do
|
||||
with {:ok, _} <- PasswordResetToken.reset_password(data["token"], data) do
|
||||
render(conn, "reset_success.html")
|
||||
else
|
||||
_e -> render(conn, "reset_failed.html")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -11,8 +11,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
|||
alias Pleroma.Activity
|
||||
alias Pleroma.Emoji
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.PasswordResetToken
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
|
@ -20,26 +18,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
|||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.WebFinger
|
||||
|
||||
def show_password_reset(conn, %{"token" => token}) do
|
||||
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
|
||||
%User{} = user <- User.get_cached_by_id(token.user_id) do
|
||||
render(conn, "password_reset.html", %{
|
||||
token: token,
|
||||
user: user
|
||||
})
|
||||
else
|
||||
_e -> render(conn, "invalid_token.html")
|
||||
end
|
||||
end
|
||||
|
||||
def password_reset(conn, %{"data" => data}) do
|
||||
with {:ok, _} <- PasswordResetToken.reset_password(data["token"], data) do
|
||||
render(conn, "password_reset_success.html")
|
||||
else
|
||||
_e -> render(conn, "password_reset_failed.html")
|
||||
end
|
||||
end
|
||||
|
||||
def help_test(conn, _params) do
|
||||
json(conn, "ok")
|
||||
end
|
||||
|
|
|
|||
8
lib/pleroma/web/twitter_api/views/password_view.ex
Normal file
8
lib/pleroma/web/twitter_api/views/password_view.ex
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.TwitterAPI.PasswordView do
|
||||
use Pleroma.Web, :view
|
||||
import Phoenix.HTML.Form
|
||||
end
|
||||
77
mix.exs
77
mix.exs
|
|
@ -4,7 +4,7 @@ defmodule Pleroma.Mixfile do
|
|||
def project do
|
||||
[
|
||||
app: :pleroma,
|
||||
version: version("0.9.0"),
|
||||
version: version("1.0.0"),
|
||||
elixir: "~> 1.7",
|
||||
elixirc_paths: elixirc_paths(Mix.env()),
|
||||
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
|
||||
|
|
@ -37,14 +37,23 @@ defmodule Pleroma.Mixfile do
|
|||
pleroma: [
|
||||
include_executables_for: [:unix],
|
||||
applications: [ex_syslogger: :load, syslog: :load],
|
||||
steps: [:assemble, ©_pleroma_ctl/1]
|
||||
steps: [:assemble, ©_files/1, ©_nginx_config/1]
|
||||
]
|
||||
]
|
||||
]
|
||||
end
|
||||
|
||||
def copy_pleroma_ctl(%{path: target_path} = release) do
|
||||
File.cp!("./rel/pleroma_ctl", Path.join([target_path, "bin", "pleroma_ctl"]))
|
||||
def copy_files(%{path: target_path} = release) do
|
||||
File.cp_r!("./rel/files", target_path)
|
||||
release
|
||||
end
|
||||
|
||||
def copy_nginx_config(%{path: target_path} = release) do
|
||||
File.cp!(
|
||||
"./installation/pleroma.nginx",
|
||||
Path.join([target_path, "installation", "pleroma.nginx"])
|
||||
)
|
||||
|
||||
release
|
||||
end
|
||||
|
||||
|
|
@ -108,7 +117,7 @@ defmodule Pleroma.Mixfile do
|
|||
{:ex_aws, "~> 2.0"},
|
||||
{:ex_aws_s3, "~> 2.0"},
|
||||
{:earmark, "~> 1.3"},
|
||||
{:bbcode, "~> 0.1"},
|
||||
{:bbcode, "~> 0.1.1"},
|
||||
{:ex_machina, "~> 2.3", only: :test},
|
||||
{:credo, "~> 0.9.3", only: [:dev, :test]},
|
||||
{:mock, "~> 0.3.3", only: :test},
|
||||
|
|
@ -126,7 +135,7 @@ defmodule Pleroma.Mixfile do
|
|||
{:ueberauth, "~> 0.4"},
|
||||
{:auto_linker,
|
||||
git: "https://git.pleroma.social/pleroma/auto_linker.git",
|
||||
ref: "e2385402bcd24fc659fee83b3eb8863b0528ad42"},
|
||||
ref: "95e8188490e97505c56636c1379ffdf036c1fdde"},
|
||||
{:http_signatures,
|
||||
git: "https://git.pleroma.social/pleroma/http_signatures.git",
|
||||
ref: "9789401987096ead65646b52b5a2ca6bf52fc531"},
|
||||
|
|
@ -154,6 +163,8 @@ defmodule Pleroma.Mixfile do
|
|||
# See the documentation for `Mix` for more info on aliases.
|
||||
defp aliases do
|
||||
[
|
||||
"ecto.migrate": ["pleroma.ecto.migrate"],
|
||||
"ecto.rollback": ["pleroma.ecto.rollback"],
|
||||
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
|
||||
"ecto.reset": ["ecto.drop", "ecto.setup"],
|
||||
test: ["ecto.create --quiet", "ecto.migrate", "test"]
|
||||
|
|
@ -163,10 +174,14 @@ defmodule Pleroma.Mixfile do
|
|||
# Builds a version string made of:
|
||||
# * the application version
|
||||
# * a pre-release if ahead of the tag: the describe string (-count-commithash)
|
||||
# * build info:
|
||||
# * branch name
|
||||
# * build metadata:
|
||||
# * a build name if `PLEROMA_BUILD_NAME` or `:pleroma, :build_name` is defined
|
||||
# * the mix environment if different than prod
|
||||
defp version(version) do
|
||||
identifier_filter = ~r/[^0-9a-z\-]+/i
|
||||
|
||||
# Pre-release version, denoted from patch version with a hyphen
|
||||
{git_tag, git_pre_release} =
|
||||
with {tag, 0} <-
|
||||
System.cmd("git", ["describe", "--tags", "--abbrev=0"], stderr_to_stdout: true),
|
||||
|
|
@ -187,6 +202,19 @@ defmodule Pleroma.Mixfile do
|
|||
)
|
||||
end
|
||||
|
||||
# Branch name as pre-release version component, denoted with a dot
|
||||
branch_name =
|
||||
with {branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]),
|
||||
branch_name <- System.get_env("PLEROMA_BUILD_BRANCH") || branch_name,
|
||||
true <- branch_name != "master" do
|
||||
branch_name =
|
||||
branch_name
|
||||
|> String.trim()
|
||||
|> String.replace(identifier_filter, "-")
|
||||
|
||||
"." <> branch_name
|
||||
end
|
||||
|
||||
build_name =
|
||||
cond do
|
||||
name = Application.get_env(:pleroma, :build_name) -> name
|
||||
|
|
@ -195,27 +223,26 @@ defmodule Pleroma.Mixfile do
|
|||
end
|
||||
|
||||
env_name = if Mix.env() != :prod, do: to_string(Mix.env())
|
||||
env_override = System.get_env("PLEROMA_BUILD_ENV")
|
||||
|
||||
build =
|
||||
[build_name, env_name]
|
||||
|> Enum.filter(fn string -> string && string != "" end)
|
||||
|> Enum.join("-")
|
||||
|> (fn
|
||||
"" -> nil
|
||||
string -> "+" <> string
|
||||
end).()
|
||||
|
||||
branch_name =
|
||||
with {branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]),
|
||||
true <- branch_name != "master" do
|
||||
branch_name =
|
||||
String.trim(branch_name)
|
||||
|> String.replace(~r/\W+/, "-")
|
||||
|
||||
"-" <> branch_name
|
||||
env_name =
|
||||
case env_override do
|
||||
nil -> env_name
|
||||
env_override when env_override in ["", "prod"] -> nil
|
||||
env_override -> env_override
|
||||
end
|
||||
|
||||
[version, git_pre_release, branch_name, build]
|
||||
# Build metadata, denoted with a plus sign
|
||||
build_metadata =
|
||||
[build_name, env_name]
|
||||
|> Enum.filter(fn string -> string && string != "" end)
|
||||
|> Enum.join(".")
|
||||
|> (fn
|
||||
"" -> nil
|
||||
string -> "+" <> String.replace(string, identifier_filter, "-")
|
||||
end).()
|
||||
|
||||
[version, git_pre_release, branch_name, build_metadata]
|
||||
|> Enum.filter(fn string -> string && string != "" end)
|
||||
|> Enum.join()
|
||||
end
|
||||
|
|
|
|||
4
mix.lock
4
mix.lock
|
|
@ -1,8 +1,8 @@
|
|||
%{
|
||||
"accept": {:hex, :accept, "0.3.5", "b33b127abca7cc948bbe6caa4c263369abf1347cfa9d8e699c6d214660f10cd1", [:rebar3], [], "hexpm"},
|
||||
"auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "e2385402bcd24fc659fee83b3eb8863b0528ad42", [ref: "e2385402bcd24fc659fee83b3eb8863b0528ad42"]},
|
||||
"auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "95e8188490e97505c56636c1379ffdf036c1fdde", [ref: "95e8188490e97505c56636c1379ffdf036c1fdde"]},
|
||||
"base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [:rebar], [], "hexpm"},
|
||||
"bbcode": {:hex, :bbcode, "0.1.0", "400e618b640b635261611d7fb7f79d104917fc5b084aae371ab6b08477cb035b", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"bbcode": {:hex, :bbcode, "0.1.1", "0023e2c7814119b2e620b7add67182e3f6019f92bfec9a22da7e99821aceba70", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"benchee": {:hex, :benchee, "1.0.1", "66b211f9bfd84bd97e6d1beaddf8fc2312aaabe192f776e8931cb0c16f53a521", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
|
||||
"cachex": {:hex, :cachex, "3.0.2", "1351caa4e26e29f7d7ec1d29b53d6013f0447630bbf382b4fb5d5bad0209f203", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.CreatePleroma.User do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:users) do
|
||||
create_if_not_exists table(:users) do
|
||||
add :email, :string
|
||||
add :password_hash, :string
|
||||
add :name, :string
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ defmodule Pleroma.Repo.Migrations.CreatePleroma.Activity do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:activities) do
|
||||
create_if_not_exists table(:activities) do
|
||||
add :data, :map
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index(:activities, [:data], using: :gin)
|
||||
create_if_not_exists index(:activities, [:data], using: :gin)
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.CreatePleroma.Object do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:objects) do
|
||||
create_if_not_exists table(:objects) do
|
||||
add :data, :map
|
||||
|
||||
timestamps()
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.AddIndexToObjects do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create index(:objects, [:data], using: :gin)
|
||||
create_if_not_exists index(:objects, [:data], using: :gin)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.AddUniqueIndexToEmailAndNickname do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create unique_index(:users, [:email])
|
||||
create unique_index(:users, [:nickname])
|
||||
create_if_not_exists unique_index(:users, [:email])
|
||||
create_if_not_exists unique_index(:users, [:nickname])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.CreateWebsubServerSubscription do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:websub_server_subscriptions) do
|
||||
create_if_not_exists table(:websub_server_subscriptions) do
|
||||
add :topic, :string
|
||||
add :callback, :string
|
||||
add :secret, :string
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.CreateWebsubClientSubscription do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:websub_client_subscriptions) do
|
||||
create_if_not_exists table(:websub_client_subscriptions) do
|
||||
add :topic, :string
|
||||
add :secret, :string
|
||||
add :valid_until, :naive_datetime_usec
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
defmodule Pleroma.Repo.Migrations.AddIdContraintsToActivitiesAndObjectsPartTwo do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
def up do
|
||||
drop_if_exists index(:objects, ["(data->>\"id\")"], name: :objects_unique_apid_index)
|
||||
drop_if_exists index(:activities, ["(data->>\"id\")"], name: :activities_unique_apid_index)
|
||||
create unique_index(:objects, ["(data->>'id')"], name: :objects_unique_apid_index)
|
||||
create unique_index(:activities, ["(data->>'id')"], name: :activities_unique_apid_index)
|
||||
create_if_not_exists unique_index(:objects, ["(data->>'id')"], name: :objects_unique_apid_index)
|
||||
create_if_not_exists unique_index(:activities, ["(data->>'id')"], name: :activities_unique_apid_index)
|
||||
end
|
||||
|
||||
def down, do: :ok
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ defmodule Pleroma.Repo.Migrations.AddLocalFieldToActivities do
|
|||
add :local, :boolean, default: true
|
||||
end
|
||||
|
||||
create index(:activities, [:local])
|
||||
create_if_not_exists index(:activities, [:local])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.AddUniqueIndexToAPID do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create unique_index(:users, [:ap_id])
|
||||
create_if_not_exists unique_index(:users, [:ap_id])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,19 +1,31 @@
|
|||
defmodule Pleroma.Repo.Migrations.CaseInsensivtivity do
|
||||
use Ecto.Migration
|
||||
|
||||
# Two-steps alters are intentional.
|
||||
# When alter of 2 columns is done in a single operation,
|
||||
# inconsistent failures happen because of index on `email` column.
|
||||
|
||||
def up do
|
||||
execute ("create extension if not exists citext")
|
||||
execute("create extension if not exists citext")
|
||||
|
||||
alter table(:users) do
|
||||
modify :email, :citext
|
||||
modify :nickname, :citext
|
||||
modify(:email, :citext)
|
||||
end
|
||||
|
||||
alter table(:users) do
|
||||
modify(:nickname, :citext)
|
||||
end
|
||||
end
|
||||
|
||||
def down do
|
||||
alter table(:users) do
|
||||
modify :email, :string
|
||||
modify :nickname, :string
|
||||
modify(:email, :string)
|
||||
end
|
||||
execute ("drop extension if exists citext")
|
||||
|
||||
alter table(:users) do
|
||||
modify(:nickname, :string)
|
||||
end
|
||||
|
||||
execute("drop extension if exists citext")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,16 @@
|
|||
defmodule Pleroma.Repo.Migrations.LongerBios do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
def up do
|
||||
alter table(:users) do
|
||||
modify :bio, :text
|
||||
end
|
||||
end
|
||||
|
||||
def down do
|
||||
alter table(:users) do
|
||||
modify :bio, :string
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.RemoveActivitiesIndex do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
drop index(:activities, [:data])
|
||||
drop_if_exists index(:activities, [:data])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ defmodule Pleroma.Repo.Migrations.AddObjectActivityIndex do
|
|||
|
||||
def change do
|
||||
# This was wrong, now a noop
|
||||
# create index(:objects, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index)
|
||||
# create_if_not_exists index(:objects, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ defmodule Pleroma.Repo.Migrations.AddObjectActivityIndexPartTwo do
|
|||
|
||||
def change do
|
||||
drop_if_exists index(:objects, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index)
|
||||
create index(:activities, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index)
|
||||
create_if_not_exists index(:activities, ["(data->'object'->>'id')", "(data->>'type')"], name: :activities_create_objects_index)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.AddActorIndexToActivity do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create index(:activities, ["(data->>'actor')", "inserted_at desc"], name: :activities_actor_index)
|
||||
create_if_not_exists index(:activities, ["(data->>'actor')", "inserted_at desc"], name: :activities_actor_index)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.AddMastodonApps do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:apps) do
|
||||
create_if_not_exists table(:apps) do
|
||||
add :client_name, :string
|
||||
add :redirect_uris, :string
|
||||
add :scopes, :string
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.CreateOAuthAuthorizations do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:oauth_authorizations) do
|
||||
create_if_not_exists table(:oauth_authorizations) do
|
||||
add :app_id, references(:apps)
|
||||
add :user_id, references(:users)
|
||||
add :token, :string
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.CreateOAuthToken do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:oauth_tokens) do
|
||||
create_if_not_exists table(:oauth_tokens) do
|
||||
add :app_id, references(:apps)
|
||||
add :user_id, references(:users)
|
||||
add :token, :string
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.CreateNotifications do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:notifications) do
|
||||
create_if_not_exists table(:notifications) do
|
||||
add :user_id, references(:users, on_delete: :delete_all)
|
||||
add :activity_id, references(:activities, on_delete: :delete_all)
|
||||
add :seen, :boolean, default: false
|
||||
|
|
@ -10,6 +10,6 @@ defmodule Pleroma.Repo.Migrations.CreateNotifications do
|
|||
timestamps()
|
||||
end
|
||||
|
||||
create index(:notifications, [:user_id])
|
||||
create_if_not_exists index(:notifications, [:user_id])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ defmodule Pleroma.Repo.Migrations.CreatePasswordResetTokens do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:password_reset_tokens) do
|
||||
create_if_not_exists table(:password_reset_tokens) do
|
||||
add :token, :string
|
||||
add :user_id, references(:users)
|
||||
add :used, :boolean, default: false
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ defmodule Pleroma.Repo.Migrations.AddActorToActivity do
|
|||
end
|
||||
|
||||
def down do
|
||||
drop index(:activities, [:actor, "id DESC NULLS LAST"])
|
||||
drop_if_exists index(:activities, [:actor, "id DESC NULLS LAST"])
|
||||
alter table(:activities) do
|
||||
remove :actor
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.AddLocalIndexToUser do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create index(:users, [:local])
|
||||
create_if_not_exists index(:users, [:local])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ defmodule Pleroma.Repo.Migrations.AddRecipientsToActivities do
|
|||
add :recipients, {:array, :string}
|
||||
end
|
||||
|
||||
create index(:activities, [:recipients], using: :gin)
|
||||
create_if_not_exists index(:activities, [:recipients], using: :gin)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,4 +18,6 @@ defmodule Pleroma.Repo.Migrations.FillRecipientsInActivities do
|
|||
end)
|
||||
end
|
||||
end
|
||||
|
||||
def down, do: :ok
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
defmodule Pleroma.Repo.Migrations.MakeFollowingPostgresArray do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
def up do
|
||||
alter table(:users) do
|
||||
add :following_temp, {:array, :string}
|
||||
end
|
||||
|
|
@ -15,4 +15,6 @@ defmodule Pleroma.Repo.Migrations.MakeFollowingPostgresArray do
|
|||
end
|
||||
rename table(:users), :following_temp, to: :following
|
||||
end
|
||||
|
||||
def down, do: :ok
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@ defmodule Pleroma.Repo.Migrations.DropLocalIndexOnActivities do
|
|||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
drop index(:users, [:local])
|
||||
drop_if_exists index(:users, [:local])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue