forked from AkkomaGang/akkoma
Merge remote-tracking branch 'pleroma/develop' into feature/addressable-lists
This commit is contained in:
commit
e82e73478e
228 changed files with 4758 additions and 1273 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -3,7 +3,6 @@
|
||||||
/db
|
/db
|
||||||
/deps
|
/deps
|
||||||
/*.ez
|
/*.ez
|
||||||
/uploads
|
|
||||||
/test/uploads
|
/test/uploads
|
||||||
/.elixir_ls
|
/.elixir_ls
|
||||||
/test/fixtures/test_tmp.txt
|
/test/fixtures/test_tmp.txt
|
||||||
|
@ -11,6 +10,7 @@
|
||||||
/test/tmp/
|
/test/tmp/
|
||||||
/doc
|
/doc
|
||||||
/instance
|
/instance
|
||||||
|
/priv/ssh_keys
|
||||||
|
|
||||||
# Prevent committing custom emojis
|
# Prevent committing custom emojis
|
||||||
/priv/static/emoji/custom/*
|
/priv/static/emoji/custom/*
|
||||||
|
@ -38,3 +38,7 @@ erl_crash.dump
|
||||||
|
|
||||||
# Prevent committing docs files
|
# Prevent committing docs files
|
||||||
/priv/static/doc/*
|
/priv/static/doc/*
|
||||||
|
|
||||||
|
# Code test coverage
|
||||||
|
/cover
|
||||||
|
/Elixir.*.coverdata
|
||||||
|
|
|
@ -48,6 +48,7 @@ unit-testing:
|
||||||
- name: postgres:9.6.2
|
- name: postgres:9.6.2
|
||||||
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
|
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
|
||||||
script:
|
script:
|
||||||
|
- mix deps.get
|
||||||
- mix ecto.create
|
- mix ecto.create
|
||||||
- mix ecto.migrate
|
- mix ecto.migrate
|
||||||
- mix test --trace --preload-modules
|
- mix test --trace --preload-modules
|
||||||
|
|
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -16,17 +16,22 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Configuration: `link_name` option
|
- Configuration: `link_name` option
|
||||||
- Configuration: `fetch_initial_posts` option
|
- Configuration: `fetch_initial_posts` option
|
||||||
- Configuration: `notify_email` option
|
- Configuration: `notify_email` option
|
||||||
|
- Configuration: Media proxy `whitelist` option
|
||||||
- Pleroma API: User subscriptions
|
- Pleroma API: User subscriptions
|
||||||
- Pleroma API: Healthcheck endpoint
|
- Pleroma API: Healthcheck endpoint
|
||||||
- Admin API: Endpoints for listing/revoking invite tokens
|
- Admin API: Endpoints for listing/revoking invite tokens
|
||||||
- Admin API: Endpoints for making users follow/unfollow each other
|
- Admin API: Endpoints for making users follow/unfollow each other
|
||||||
|
- Admin API: added filters (role, tags, email, name) for users endpoint
|
||||||
- Mastodon API: [Scheduled statuses](https://docs.joinmastodon.org/api/rest/scheduled-statuses/)
|
- Mastodon API: [Scheduled statuses](https://docs.joinmastodon.org/api/rest/scheduled-statuses/)
|
||||||
- Mastodon API: `/api/v1/notifications/destroy_multiple` (glitch-soc extension)
|
- Mastodon API: `/api/v1/notifications/destroy_multiple` (glitch-soc extension)
|
||||||
- Mastodon API: `/api/v1/pleroma/accounts/:id/favourites` (API extension)
|
- Mastodon API: `/api/v1/pleroma/accounts/:id/favourites` (API extension)
|
||||||
- Mastodon API: [Reports](https://docs.joinmastodon.org/api/rest/reports/)
|
- Mastodon API: [Reports](https://docs.joinmastodon.org/api/rest/reports/)
|
||||||
|
- Mastodon API: REST API for creating an account
|
||||||
- ActivityPub C2S: OAuth endpoints
|
- ActivityPub C2S: OAuth endpoints
|
||||||
- Metadata RelMe provider
|
- Metadata RelMe provider
|
||||||
|
- OAuth: added support for refresh tokens
|
||||||
- Emoji packs and emoji pack manager
|
- Emoji packs and emoji pack manager
|
||||||
|
- AdminFE: initial release with basic user management accessible at /pleroma/admin/
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- **Breaking:** Configuration: move from Pleroma.Mailer to Pleroma.Emails.Mailer
|
- **Breaking:** Configuration: move from Pleroma.Mailer to Pleroma.Emails.Mailer
|
||||||
|
@ -40,26 +45,33 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Configuration: Dedupe enabled by default
|
- Configuration: Dedupe enabled by default
|
||||||
- Configuration: Added `extra_cookie_attrs` for setting non-standard cookie attributes. Defaults to ["SameSite=Lax"] so that remote follows work.
|
- Configuration: Added `extra_cookie_attrs` for setting non-standard cookie attributes. Defaults to ["SameSite=Lax"] so that remote follows work.
|
||||||
- Pleroma API: Support for emoji tags in `/api/pleroma/emoji` resulting in a breaking API change
|
- Pleroma API: Support for emoji tags in `/api/pleroma/emoji` resulting in a breaking API change
|
||||||
|
- Timelines: Messages involving people you have blocked will be excluded from the timeline in all cases instead of just repeats.
|
||||||
- Mastodon API: Support for `exclude_types`, `limit` and `min_id` in `/api/v1/notifications`
|
- Mastodon API: Support for `exclude_types`, `limit` and `min_id` in `/api/v1/notifications`
|
||||||
- Mastodon API: Add `languages` and `registrations` to `/api/v1/instance`
|
- Mastodon API: Add `languages` and `registrations` to `/api/v1/instance`
|
||||||
- Mastodon API: Provide plaintext versions of cw/content in the Status entity
|
- Mastodon API: Provide plaintext versions of cw/content in the Status entity
|
||||||
- Mastodon API: Add `pleroma.conversation_id`, `pleroma.in_reply_to_account_acct` fields to the Status entity
|
- Mastodon API: Add `pleroma.conversation_id`, `pleroma.in_reply_to_account_acct` fields to the Status entity
|
||||||
- Mastodon API: Add `pleroma.tags`, `pleroma.relationship{}`, `pleroma.is_moderator`, `pleroma.is_admin`, `pleroma.confirmation_pending` fields to the User entity
|
- Mastodon API: Add `pleroma.tags`, `pleroma.relationship{}`, `pleroma.is_moderator`, `pleroma.is_admin`, `pleroma.confirmation_pending`, `pleroma.hide_followers`, `pleroma.hide_follows`, `pleroma.hide_favorites` fields to the User entity
|
||||||
|
- Mastodon API: Add `pleroma.show_role`, `pleroma.no_rich_text` fields to the Source subentity
|
||||||
|
- Mastodon API: Add support for updating `no_rich_text`, `hide_followers`, `hide_follows`, `hide_favorites`, `show_role` in `PATCH /api/v1/update_credentials`
|
||||||
- Mastodon API: Add `pleroma.is_seen` to the Notification entity
|
- Mastodon API: Add `pleroma.is_seen` to the Notification entity
|
||||||
- Mastodon API: Add `pleroma.local` to the Status entity
|
- Mastodon API: Add `pleroma.local` to the Status entity
|
||||||
- Mastodon API: Add `preview` parameter to `POST /api/v1/statuses`
|
- Mastodon API: Add `preview` parameter to `POST /api/v1/statuses`
|
||||||
- Mastodon API: Add `with_muted` parameter to timeline endpoints
|
- Mastodon API: Add `with_muted` parameter to timeline endpoints
|
||||||
- Mastodon API: Actual reblog hiding instead of a dummy
|
- Mastodon API: Actual reblog hiding instead of a dummy
|
||||||
- Mastodon API: Remove attachment limit in the Status entity
|
- Mastodon API: Remove attachment limit in the Status entity
|
||||||
|
- Mastodon API: Added support max_id & since_id for bookmark timeline endpoints.
|
||||||
- Deps: Updated Cowboy to 2.6
|
- Deps: Updated Cowboy to 2.6
|
||||||
- Deps: Updated Ecto to 3.0.7
|
- Deps: Updated Ecto to 3.0.7
|
||||||
- Don't ship finmoji by default, they can be installed as an emoji pack
|
- Don't ship finmoji by default, they can be installed as an emoji pack
|
||||||
|
- Admin API: Move the user related API to `api/pleroma/admin/users`
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
- Added an FTS index on objects. Running `vacuum analyze` and setting a larger `work_mem` is recommended.
|
||||||
- Followers counter not being updated when a follower is blocked
|
- Followers counter not being updated when a follower is blocked
|
||||||
- Deactivated users being able to request an access token
|
- Deactivated users being able to request an access token
|
||||||
- Limit on request body in rich media/relme parsers being ignored resulting in a possible memory leak
|
- Limit on request body in rich media/relme parsers being ignored resulting in a possible memory leak
|
||||||
- proper Twitter Card generation instead of a dummy
|
- proper Twitter Card generation instead of a dummy
|
||||||
|
- Deletions failing for users with a large number of posts
|
||||||
- NodeInfo: Include admins in `staffAccounts`
|
- NodeInfo: Include admins in `staffAccounts`
|
||||||
- ActivityPub: Crashing when requesting empty local user's outbox
|
- ActivityPub: Crashing when requesting empty local user's outbox
|
||||||
- Federation: Handling of objects without `summary` property
|
- Federation: Handling of objects without `summary` property
|
||||||
|
@ -68,16 +80,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Federation: Cope with missing or explicitly nulled address lists
|
- Federation: Cope with missing or explicitly nulled address lists
|
||||||
- Federation: Explicitly ensure activities addressed to `as:Public` become addressed to the followers collection
|
- Federation: Explicitly ensure activities addressed to `as:Public` become addressed to the followers collection
|
||||||
- Federation: Better cope with actors which do not declare a followers collection and use `as:Public` with these semantics
|
- Federation: Better cope with actors which do not declare a followers collection and use `as:Public` with these semantics
|
||||||
|
- Federation: Follow requests from remote users who have been blocked will be automatically rejected if appropriate
|
||||||
- MediaProxy: Parse name from content disposition headers even for non-whitelisted types
|
- MediaProxy: Parse name from content disposition headers even for non-whitelisted types
|
||||||
- MediaProxy: S3 link encoding
|
- MediaProxy: S3 link encoding
|
||||||
- Rich Media: Reject any data which cannot be explicitly encoded into JSON
|
- Rich Media: Reject any data which cannot be explicitly encoded into JSON
|
||||||
- Pleroma API: Importing follows from Mastodon 2.8+
|
- Pleroma API: Importing follows from Mastodon 2.8+
|
||||||
|
- Twitter API: Exposing default scope, `no_rich_text` of the user to anyone
|
||||||
|
- Twitter API: Returning the `role` object in user entity despite `show_role = false`
|
||||||
- Mastodon API: `/api/v1/favourites` serving only public activities
|
- Mastodon API: `/api/v1/favourites` serving only public activities
|
||||||
- Mastodon API: Reblogs having `in_reply_to_id` - `null` even when they are replies
|
- Mastodon API: Reblogs having `in_reply_to_id` - `null` even when they are replies
|
||||||
- Mastodon API: Streaming API broadcasting wrong activity id
|
- Mastodon API: Streaming API broadcasting wrong activity id
|
||||||
- Mastodon API: 500 errors when requesting a card for a private conversation
|
- Mastodon API: 500 errors when requesting a card for a private conversation
|
||||||
- Mastodon API: Handling of `reblogs` in `/api/v1/accounts/:id/follow`
|
- Mastodon API: Handling of `reblogs` in `/api/v1/accounts/:id/follow`
|
||||||
- Mastodon API: Correct `reblogged`, `favourited`, and `bookmarked` values in the reblog status JSON
|
- Mastodon API: Correct `reblogged`, `favourited`, and `bookmarked` values in the reblog status JSON
|
||||||
|
- Mastodon API: Exposing default scope of the user to anyone
|
||||||
|
- Mastodon API: Make `irreversible` field default to `false` [`POST /api/v1/filters`]
|
||||||
|
|
||||||
## [0.9.9999] - 2019-04-05
|
## [0.9.9999] - 2019-04-05
|
||||||
### Security
|
### Security
|
||||||
|
|
8
COPYING
8
COPYING
|
@ -15,6 +15,14 @@ priv/static/images/pleroma-tan.png
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
The following files are copyright © 2019 shitposter.club, and are distributed
|
||||||
|
under the Creative Commons Attribution 4.0 International license, you should
|
||||||
|
have received a copy of the license file as CC-BY-4.0.
|
||||||
|
|
||||||
|
priv/static/images/pleroma-fox-tan-shy.png
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
The following files are copyright © 2017-2019 Pleroma Authors
|
The following files are copyright © 2017-2019 Pleroma Authors
|
||||||
<https://pleroma.social/>, and are distributed under the Creative Commons
|
<https://pleroma.social/>, and are distributed under the Creative Commons
|
||||||
Attribution-ShareAlike 4.0 International license, you should have received
|
Attribution-ShareAlike 4.0 International license, you should have received
|
||||||
|
|
|
@ -12,7 +12,7 @@ For clients it supports both the [GNU Social API with Qvitter extensions](https:
|
||||||
|
|
||||||
- [Client Applications for Pleroma](https://docs-develop.pleroma.social/clients.html)
|
- [Client Applications for Pleroma](https://docs-develop.pleroma.social/clients.html)
|
||||||
|
|
||||||
No release has been made yet, but several servers have been online for months already. 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>.
|
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
|
## Installation
|
||||||
|
|
||||||
|
|
|
@ -212,6 +212,11 @@
|
||||||
registrations_open: true,
|
registrations_open: true,
|
||||||
federating: true,
|
federating: true,
|
||||||
federation_reachability_timeout_days: 7,
|
federation_reachability_timeout_days: 7,
|
||||||
|
federation_publisher_modules: [
|
||||||
|
Pleroma.Web.ActivityPub.Publisher,
|
||||||
|
Pleroma.Web.Websub,
|
||||||
|
Pleroma.Web.Salmon
|
||||||
|
],
|
||||||
allow_relay: true,
|
allow_relay: true,
|
||||||
rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,
|
rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,
|
||||||
public: true,
|
public: true,
|
||||||
|
@ -221,7 +226,8 @@
|
||||||
allowed_post_formats: [
|
allowed_post_formats: [
|
||||||
"text/plain",
|
"text/plain",
|
||||||
"text/html",
|
"text/html",
|
||||||
"text/markdown"
|
"text/markdown",
|
||||||
|
"text/bbcode"
|
||||||
],
|
],
|
||||||
mrf_transparency: true,
|
mrf_transparency: true,
|
||||||
autofollowed_nicknames: [],
|
autofollowed_nicknames: [],
|
||||||
|
@ -233,6 +239,8 @@
|
||||||
safe_dm_mentions: false,
|
safe_dm_mentions: false,
|
||||||
healthcheck: false
|
healthcheck: false
|
||||||
|
|
||||||
|
config :pleroma, :app_account_creation, enabled: false, max_requests: 5, interval: 1800
|
||||||
|
|
||||||
config :pleroma, :markup,
|
config :pleroma, :markup,
|
||||||
# XXX - unfortunately, inline images must be enabled by default right now, because
|
# XXX - unfortunately, inline images must be enabled by default right now, because
|
||||||
# of custom emoji. Issue #275 discusses defanging that somehow.
|
# of custom emoji. Issue #275 discusses defanging that somehow.
|
||||||
|
@ -326,7 +334,8 @@
|
||||||
follow_redirect: true,
|
follow_redirect: true,
|
||||||
pool: :media
|
pool: :media
|
||||||
]
|
]
|
||||||
]
|
],
|
||||||
|
whitelist: []
|
||||||
|
|
||||||
config :pleroma, :chat, enabled: true
|
config :pleroma, :chat, enabled: true
|
||||||
|
|
||||||
|
@ -414,7 +423,8 @@
|
||||||
web_push: 50,
|
web_push: 50,
|
||||||
mailer: 10,
|
mailer: 10,
|
||||||
transmogrifier: 20,
|
transmogrifier: 20,
|
||||||
scheduled_activities: 10
|
scheduled_activities: 10,
|
||||||
|
background: 5
|
||||||
|
|
||||||
config :pleroma, :fetch_initial_posts,
|
config :pleroma, :fetch_initial_posts,
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -441,6 +451,9 @@
|
||||||
base: System.get_env("LDAP_BASE") || "dc=example,dc=com",
|
base: System.get_env("LDAP_BASE") || "dc=example,dc=com",
|
||||||
uid: System.get_env("LDAP_UID") || "cn"
|
uid: System.get_env("LDAP_UID") || "cn"
|
||||||
|
|
||||||
|
config :esshd,
|
||||||
|
enabled: false
|
||||||
|
|
||||||
oauth_consumer_strategies = String.split(System.get_env("OAUTH_CONSUMER_STRATEGIES") || "")
|
oauth_consumer_strategies = String.split(System.get_env("OAUTH_CONSUMER_STRATEGIES") || "")
|
||||||
|
|
||||||
ueberauth_providers =
|
ueberauth_providers =
|
||||||
|
@ -466,6 +479,10 @@
|
||||||
total_user_limit: 300,
|
total_user_limit: 300,
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
|
config :pleroma, :oauth2,
|
||||||
|
token_expires_in: 600,
|
||||||
|
issue_new_refresh_token: true
|
||||||
|
|
||||||
# Import environment specific config. This must remain at the bottom
|
# Import environment specific config. This must remain at the bottom
|
||||||
# of this file so it overrides the configuration defined above.
|
# of this file so it overrides the configuration defined above.
|
||||||
import_config "#{Mix.env()}.exs"
|
import_config "#{Mix.env()}.exs"
|
||||||
|
|
|
@ -8,15 +8,20 @@ Authentication is required and the user must be an admin.
|
||||||
|
|
||||||
- Method `GET`
|
- Method `GET`
|
||||||
- Query Params:
|
- Query Params:
|
||||||
- *optional* `query`: **string** search term
|
- *optional* `query`: **string** search term (e.g. nickname, domain, nickname@domain)
|
||||||
- *optional* `filters`: **string** comma-separated string of filters:
|
- *optional* `filters`: **string** comma-separated string of filters:
|
||||||
- `local`: only local users
|
- `local`: only local users
|
||||||
- `external`: only external users
|
- `external`: only external users
|
||||||
- `active`: only active users
|
- `active`: only active users
|
||||||
- `deactivated`: only deactivated users
|
- `deactivated`: only deactivated users
|
||||||
|
- `is_admin`: users with admin role
|
||||||
|
- `is_moderator`: users with moderator role
|
||||||
- *optional* `page`: **integer** page number
|
- *optional* `page`: **integer** page number
|
||||||
- *optional* `page_size`: **integer** number of users per page (default is `50`)
|
- *optional* `page_size`: **integer** number of users per page (default is `50`)
|
||||||
- Example: `https://mypleroma.org/api/pleroma/admin/users?query=john&filters=local,active&page=1&page_size=10`
|
- *optional* `tags`: **[string]** tags list
|
||||||
|
- *optional* `name`: **string** user display name
|
||||||
|
- *optional* `email`: **string** user email
|
||||||
|
- Example: `https://mypleroma.org/api/pleroma/admin/users?query=john&filters=local,active&page=1&page_size=10&tags[]=some_tag&tags[]=another_tag&name=display_name&email=email@example.com`
|
||||||
- Response:
|
- Response:
|
||||||
|
|
||||||
```JSON
|
```JSON
|
||||||
|
@ -40,7 +45,7 @@ Authentication is required and the user must be an admin.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## `/api/pleroma/admin/user`
|
## `/api/pleroma/admin/users`
|
||||||
|
|
||||||
### Remove a user
|
### Remove a user
|
||||||
|
|
||||||
|
@ -58,7 +63,7 @@ Authentication is required and the user must be an admin.
|
||||||
- `password`
|
- `password`
|
||||||
- Response: User’s nickname
|
- Response: User’s nickname
|
||||||
|
|
||||||
## `/api/pleroma/admin/user/follow`
|
## `/api/pleroma/admin/users/follow`
|
||||||
### Make a user follow another user
|
### Make a user follow another user
|
||||||
|
|
||||||
- Methods: `POST`
|
- Methods: `POST`
|
||||||
|
@ -68,7 +73,7 @@ Authentication is required and the user must be an admin.
|
||||||
- Response:
|
- Response:
|
||||||
- "ok"
|
- "ok"
|
||||||
|
|
||||||
## `/api/pleroma/admin/user/unfollow`
|
## `/api/pleroma/admin/users/unfollow`
|
||||||
### Make a user unfollow another user
|
### Make a user unfollow another user
|
||||||
|
|
||||||
- Methods: `POST`
|
- Methods: `POST`
|
||||||
|
@ -111,7 +116,7 @@ Authentication is required and the user must be an admin.
|
||||||
- `nickname`
|
- `nickname`
|
||||||
- `tags`
|
- `tags`
|
||||||
|
|
||||||
## `/api/pleroma/admin/permission_group/:nickname`
|
## `/api/pleroma/admin/users/:nickname/permission_group`
|
||||||
|
|
||||||
### Get user user permission groups membership
|
### Get user user permission groups membership
|
||||||
|
|
||||||
|
@ -126,7 +131,7 @@ Authentication is required and the user must be an admin.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## `/api/pleroma/admin/permission_group/:nickname/:permission_group`
|
## `/api/pleroma/admin/users/:nickname/permission_group/:permission_group`
|
||||||
|
|
||||||
Note: Available `:permission_group` is currently moderator and admin. 404 is returned when the permission group doesn’t exist.
|
Note: Available `:permission_group` is currently moderator and admin. 404 is returned when the permission group doesn’t exist.
|
||||||
|
|
||||||
|
@ -160,7 +165,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
- On success: JSON of the `user.info`
|
- On success: JSON of the `user.info`
|
||||||
- Note: An admin cannot revoke their own admin status.
|
- Note: An admin cannot revoke their own admin status.
|
||||||
|
|
||||||
## `/api/pleroma/admin/activation_status/:nickname`
|
## `/api/pleroma/admin/users/:nickname/activation_status`
|
||||||
|
|
||||||
### Active or deactivate a user
|
### Active or deactivate a user
|
||||||
|
|
||||||
|
@ -198,7 +203,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
- Response:
|
- Response:
|
||||||
- On success: URL of the unfollowed relay
|
- On success: URL of the unfollowed relay
|
||||||
|
|
||||||
## `/api/pleroma/admin/invite_token`
|
## `/api/pleroma/admin/users/invite_token`
|
||||||
|
|
||||||
### Get an account registration invite token
|
### Get an account registration invite token
|
||||||
|
|
||||||
|
@ -210,7 +215,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
]
|
]
|
||||||
- Response: invite token (base64 string)
|
- Response: invite token (base64 string)
|
||||||
|
|
||||||
## `/api/pleroma/admin/invites`
|
## `/api/pleroma/admin/users/invites`
|
||||||
|
|
||||||
### Get a list of generated invites
|
### Get a list of generated invites
|
||||||
|
|
||||||
|
@ -236,7 +241,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## `/api/pleroma/admin/revoke_invite`
|
## `/api/pleroma/admin/users/revoke_invite`
|
||||||
|
|
||||||
### Revoke invite by token
|
### Revoke invite by token
|
||||||
|
|
||||||
|
@ -259,7 +264,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## `/api/pleroma/admin/email_invite`
|
## `/api/pleroma/admin/users/email_invite`
|
||||||
|
|
||||||
### Sends registration invite via email
|
### Sends registration invite via email
|
||||||
|
|
||||||
|
@ -268,7 +273,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
- `email`
|
- `email`
|
||||||
- `name`, optional
|
- `name`, optional
|
||||||
|
|
||||||
## `/api/pleroma/admin/password_reset`
|
## `/api/pleroma/admin/users/:nickname/password_reset`
|
||||||
|
|
||||||
### Get a password reset token for a given nickname
|
### Get a password reset token for a given nickname
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,18 @@ Has these additional fields under the `pleroma` object:
|
||||||
|
|
||||||
- `tags`: Lists an array of tags for the user
|
- `tags`: Lists an array of tags for the user
|
||||||
- `relationship{}`: Includes fields as documented for Mastodon API https://docs.joinmastodon.org/api/entities/#relationship
|
- `relationship{}`: Includes fields as documented for Mastodon API https://docs.joinmastodon.org/api/entities/#relationship
|
||||||
- `is_moderator`: boolean, true if user is a moderator
|
- `is_moderator`: boolean, nullable, true if user is a moderator
|
||||||
- `is_admin`: boolean, true if user is an admin
|
- `is_admin`: boolean, nullable, true if user is an admin
|
||||||
- `confirmation_pending`: boolean, true if a new user account is waiting on email confirmation to be activated
|
- `confirmation_pending`: boolean, true if a new user account is waiting on email confirmation to be activated
|
||||||
|
- `hide_followers`: boolean, true when the user has follower hiding enabled
|
||||||
|
- `hide_follows`: boolean, true when the user has follow hiding enabled
|
||||||
|
|
||||||
|
### Source
|
||||||
|
|
||||||
|
Has these additional fields under the `pleroma` object:
|
||||||
|
|
||||||
|
- `show_role`: boolean, nullable, true when the user wants his role (e.g admin, moderator) to be shown
|
||||||
|
- `no_rich_text` - boolean, nullable, true when html tags are stripped from all statuses requested from the API
|
||||||
|
|
||||||
## Account Search
|
## Account Search
|
||||||
|
|
||||||
|
@ -60,3 +69,31 @@ Additional parameters can be added to the JSON body/Form data:
|
||||||
|
|
||||||
- `preview`: boolean, if set to `true` the post won't be actually posted, but the status entitiy would still be rendered back. This could be useful for previewing rich text/custom emoji, for example.
|
- `preview`: boolean, if set to `true` the post won't be actually posted, but the status entitiy would still be rendered back. This could be useful for previewing rich text/custom emoji, for example.
|
||||||
- `content_type`: string, contain the MIME type of the status, it is transformed into HTML by the backend. You can get the list of the supported MIME types with the nodeinfo endpoint.
|
- `content_type`: string, contain the MIME type of the status, it is transformed into HTML by the backend. You can get the list of the supported MIME types with the nodeinfo endpoint.
|
||||||
|
|
||||||
|
## PATCH `/api/v1/update_credentials`
|
||||||
|
|
||||||
|
Additional parameters can be added to the JSON body/Form data:
|
||||||
|
|
||||||
|
- `no_rich_text` - if true, html tags are stripped from all statuses requested from the API
|
||||||
|
- `hide_followers` - if true, user's followers will be hidden
|
||||||
|
- `hide_follows` - if true, user's follows will be hidden
|
||||||
|
- `hide_favorites` - if true, user's favorites timeline will be hidden
|
||||||
|
- `show_role` - if true, user's role (e.g admin, moderator) will be exposed to anyone in the API
|
||||||
|
- `default_scope` - the scope returned under `privacy` key in Source subentity
|
||||||
|
|
||||||
|
## Authentication
|
||||||
|
|
||||||
|
*Pleroma supports refreshing tokens.
|
||||||
|
|
||||||
|
`POST /oauth/token`
|
||||||
|
Post here request with grant_type=refresh_token to obtain new access token. Returns an access token.
|
||||||
|
|
||||||
|
## Account Registration
|
||||||
|
`POST /api/v1/accounts`
|
||||||
|
|
||||||
|
Has theses additionnal parameters (which are the same as in Pleroma-API):
|
||||||
|
* `fullname`: optional
|
||||||
|
* `bio`: optional
|
||||||
|
* `captcha_solution`: optional, contains provider-specific captcha solution,
|
||||||
|
* `captcha_token`: optional, contains provider-specific captcha token
|
||||||
|
* `token`: invite token required when the registerations aren't public.
|
||||||
|
|
|
@ -37,7 +37,7 @@ This filter replaces the filename (not the path) of an upload. For complete obfu
|
||||||
|
|
||||||
An example for Sendgrid adapter:
|
An example for Sendgrid adapter:
|
||||||
|
|
||||||
```exs
|
```elixir
|
||||||
config :pleroma, Pleroma.Emails.Mailer,
|
config :pleroma, Pleroma.Emails.Mailer,
|
||||||
adapter: Swoosh.Adapters.Sendgrid,
|
adapter: Swoosh.Adapters.Sendgrid,
|
||||||
api_key: "YOUR_API_KEY"
|
api_key: "YOUR_API_KEY"
|
||||||
|
@ -45,7 +45,7 @@ config :pleroma, Pleroma.Emails.Mailer,
|
||||||
|
|
||||||
An example for SMTP adapter:
|
An example for SMTP adapter:
|
||||||
|
|
||||||
```exs
|
```elixir
|
||||||
config :pleroma, Pleroma.Emails.Mailer,
|
config :pleroma, Pleroma.Emails.Mailer,
|
||||||
adapter: Swoosh.Adapters.SMTP,
|
adapter: Swoosh.Adapters.SMTP,
|
||||||
relay: "smtp.gmail.com",
|
relay: "smtp.gmail.com",
|
||||||
|
@ -105,11 +105,17 @@ config :pleroma, Pleroma.Emails.Mailer,
|
||||||
* `safe_dm_mentions`: If set to true, only mentions at the beginning of a post will be used to address people in direct messages. This is to prevent accidental mentioning of people when talking about them (e.g. "@friend hey i really don't like @enemy"). (Default: `false`)
|
* `safe_dm_mentions`: If set to true, only mentions at the beginning of a post will be used to address people in direct messages. This is to prevent accidental mentioning of people when talking about them (e.g. "@friend hey i really don't like @enemy"). (Default: `false`)
|
||||||
* `healthcheck`: if set to true, system data will be shown on ``/api/pleroma/healthcheck``.
|
* `healthcheck`: if set to true, system data will be shown on ``/api/pleroma/healthcheck``.
|
||||||
|
|
||||||
|
## :app_account_creation
|
||||||
|
REST API for creating an account settings
|
||||||
|
* `enabled`: Enable/disable registration
|
||||||
|
* `max_requests`: Number of requests allowed for creating accounts
|
||||||
|
* `interval`: Interval for restricting requests for one ip (seconds)
|
||||||
|
|
||||||
## :logger
|
## :logger
|
||||||
* `backends`: `:console` is used to send logs to stdout, `{ExSyslogger, :ex_syslogger}` to log to syslog, and `Quack.Logger` to log to Slack
|
* `backends`: `:console` is used to send logs to stdout, `{ExSyslogger, :ex_syslogger}` to log to syslog, and `Quack.Logger` to log to Slack
|
||||||
|
|
||||||
An example to enable ONLY ExSyslogger (f/ex in ``prod.secret.exs``) with info and debug suppressed:
|
An example to enable ONLY ExSyslogger (f/ex in ``prod.secret.exs``) with info and debug suppressed:
|
||||||
```
|
```elixir
|
||||||
config :logger,
|
config :logger,
|
||||||
backends: [{ExSyslogger, :ex_syslogger}]
|
backends: [{ExSyslogger, :ex_syslogger}]
|
||||||
|
|
||||||
|
@ -118,7 +124,7 @@ config :logger, :ex_syslogger,
|
||||||
```
|
```
|
||||||
|
|
||||||
Another example, keeping console output and adding the pid to syslog output:
|
Another example, keeping console output and adding the pid to syslog output:
|
||||||
```
|
```elixir
|
||||||
config :logger,
|
config :logger,
|
||||||
backends: [:console, {ExSyslogger, :ex_syslogger}]
|
backends: [:console, {ExSyslogger, :ex_syslogger}]
|
||||||
|
|
||||||
|
@ -130,7 +136,7 @@ config :logger, :ex_syslogger,
|
||||||
See: [logger’s documentation](https://hexdocs.pm/logger/Logger.html) and [ex_syslogger’s documentation](https://hexdocs.pm/ex_syslogger/)
|
See: [logger’s documentation](https://hexdocs.pm/logger/Logger.html) and [ex_syslogger’s documentation](https://hexdocs.pm/ex_syslogger/)
|
||||||
|
|
||||||
An example of logging info to local syslog, but warn to a Slack channel:
|
An example of logging info to local syslog, but warn to a Slack channel:
|
||||||
```
|
```elixir
|
||||||
config :logger,
|
config :logger,
|
||||||
backends: [ {ExSyslogger, :ex_syslogger}, Quack.Logger ],
|
backends: [ {ExSyslogger, :ex_syslogger}, Quack.Logger ],
|
||||||
level: :info
|
level: :info
|
||||||
|
@ -156,14 +162,30 @@ Frontends can access these settings at `/api/pleroma/frontend_configurations`
|
||||||
|
|
||||||
To add your own configuration for PleromaFE, use it like this:
|
To add your own configuration for PleromaFE, use it like this:
|
||||||
|
|
||||||
`config :pleroma, :frontend_configurations, pleroma_fe: %{redirectRootNoLogin: "/main/all", ...}`
|
```elixir
|
||||||
|
config :pleroma, :frontend_configurations,
|
||||||
|
pleroma_fe: %{
|
||||||
|
theme: "pleroma-dark",
|
||||||
|
# ... see /priv/static/static/config.json for the available keys.
|
||||||
|
},
|
||||||
|
masto_fe: %{
|
||||||
|
showInstanceSpecificPanel: true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
These settings need to be complete, they will override the defaults. See `priv/static/static/config.json` for the available keys.
|
These settings **need to be complete**, they will override the defaults.
|
||||||
|
|
||||||
|
NOTE: for versions < 1.0, you need to set [`:fe`](#fe) to false, as shown a few lines below.
|
||||||
|
|
||||||
## :fe
|
## :fe
|
||||||
__THIS IS DEPRECATED__
|
__THIS IS DEPRECATED__
|
||||||
|
|
||||||
If you are using this method, please change it to the `frontend_configurations` method. Please set this option to false in your config like this: `config :pleroma, :fe, false`.
|
If you are using this method, please change it to the [`frontend_configurations`](#frontend_configurations) method.
|
||||||
|
Please **set this option to false** in your config like this:
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
config :pleroma, :fe, false
|
||||||
|
```
|
||||||
|
|
||||||
This section is used to configure Pleroma-FE, unless ``:managed_config`` in ``:instance`` is set to false.
|
This section is used to configure Pleroma-FE, unless ``:managed_config`` in ``:instance`` is set to false.
|
||||||
|
|
||||||
|
@ -205,6 +227,7 @@ This section is used to configure Pleroma-FE, unless ``:managed_config`` in ``:i
|
||||||
* `enabled`: Enables proxying of remote media to the instance’s proxy
|
* `enabled`: Enables proxying of remote media to the instance’s proxy
|
||||||
* `base_url`: The base URL to access a user-uploaded file. Useful when you want to proxy the media files via another host/CDN fronts.
|
* `base_url`: The base URL to access a user-uploaded file. Useful when you want to proxy the media files via another host/CDN fronts.
|
||||||
* `proxy_opts`: All options defined in `Pleroma.ReverseProxy` documentation, defaults to `[max_body_length: (25*1_048_576)]`.
|
* `proxy_opts`: All options defined in `Pleroma.ReverseProxy` documentation, defaults to `[max_body_length: (25*1_048_576)]`.
|
||||||
|
* `whitelist`: List of domains to bypass the mediaproxy
|
||||||
|
|
||||||
## :gopher
|
## :gopher
|
||||||
* `enabled`: Enables the gopher interface
|
* `enabled`: Enables the gopher interface
|
||||||
|
@ -273,7 +296,7 @@ their ActivityPub ID.
|
||||||
|
|
||||||
An example:
|
An example:
|
||||||
|
|
||||||
```exs
|
```elixir
|
||||||
config :pleroma, :mrf_user_allowlist,
|
config :pleroma, :mrf_user_allowlist,
|
||||||
"example.org": ["https://example.org/users/admin"]
|
"example.org": ["https://example.org/users/admin"]
|
||||||
```
|
```
|
||||||
|
@ -302,7 +325,7 @@ the source code is here: https://github.com/koto-bank/kocaptcha. The default end
|
||||||
|
|
||||||
Allows to set a token that can be used to authenticate with the admin api without using an actual user by giving it as the 'admin_token' parameter. Example:
|
Allows to set a token that can be used to authenticate with the admin api without using an actual user by giving it as the 'admin_token' parameter. Example:
|
||||||
|
|
||||||
```exs
|
```elixir
|
||||||
config :pleroma, :admin_token, "somerandomtoken"
|
config :pleroma, :admin_token, "somerandomtoken"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -386,7 +409,7 @@ Configuration for the `auto_linker` library:
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```exs
|
```elixir
|
||||||
config :auto_linker,
|
config :auto_linker,
|
||||||
opts: [
|
opts: [
|
||||||
scheme: true,
|
scheme: true,
|
||||||
|
@ -427,15 +450,36 @@ Pleroma account will be created with the same name as the LDAP user name.
|
||||||
* `base`: LDAP base, e.g. "dc=example,dc=com"
|
* `base`: LDAP base, e.g. "dc=example,dc=com"
|
||||||
* `uid`: LDAP attribute name to authenticate the user, e.g. when "cn", the filter will be "cn=username,base"
|
* `uid`: LDAP attribute name to authenticate the user, e.g. when "cn", the filter will be "cn=username,base"
|
||||||
|
|
||||||
|
## BBS / SSH access
|
||||||
|
|
||||||
|
To enable simple command line interface accessible over ssh, add a setting like this to your configuration file:
|
||||||
|
|
||||||
|
```exs
|
||||||
|
app_dir = File.cwd!
|
||||||
|
priv_dir = Path.join([app_dir, "priv/ssh_keys"])
|
||||||
|
|
||||||
|
config :esshd,
|
||||||
|
enabled: true,
|
||||||
|
priv_dir: priv_dir,
|
||||||
|
handler: "Pleroma.BBS.Handler",
|
||||||
|
port: 10_022,
|
||||||
|
password_authenticator: "Pleroma.BBS.Authenticator"
|
||||||
|
```
|
||||||
|
|
||||||
|
Feel free to adjust the priv_dir and port number. Then you will have to create the key for the keys (in the example `priv/ssh_keys`) and create the host keys with `ssh-keygen -N "" -b 2048 -t rsa -f ssh_host_rsa_key`. After restarting, you should be able to connect to your Pleroma instance with `ssh username@server -p $PORT`
|
||||||
|
|
||||||
## :auth
|
## :auth
|
||||||
|
|
||||||
|
* `Pleroma.Web.Auth.PleromaAuthenticator`: default database authenticator
|
||||||
|
* `Pleroma.Web.Auth.LDAPAuthenticator`: LDAP authentication
|
||||||
|
|
||||||
Authentication / authorization settings.
|
Authentication / authorization settings.
|
||||||
|
|
||||||
* `auth_template`: authentication form template. By default it's `show.html` which corresponds to `lib/pleroma/web/templates/o_auth/o_auth/show.html.eex`.
|
* `auth_template`: authentication form template. By default it's `show.html` which corresponds to `lib/pleroma/web/templates/o_auth/o_auth/show.html.eex`.
|
||||||
* `oauth_consumer_template`: OAuth consumer mode authentication form template. By default it's `consumer.html` which corresponds to `lib/pleroma/web/templates/o_auth/o_auth/consumer.html.eex`.
|
* `oauth_consumer_template`: OAuth consumer mode authentication form template. By default it's `consumer.html` which corresponds to `lib/pleroma/web/templates/o_auth/o_auth/consumer.html.eex`.
|
||||||
* `oauth_consumer_strategies`: the list of enabled OAuth consumer strategies; by default it's set by OAUTH_CONSUMER_STRATEGIES environment variable.
|
* `oauth_consumer_strategies`: the list of enabled OAuth consumer strategies; by default it's set by OAUTH_CONSUMER_STRATEGIES environment variable.
|
||||||
|
|
||||||
# OAuth consumer mode
|
## OAuth consumer mode
|
||||||
|
|
||||||
OAuth consumer mode allows sign in / sign up via external OAuth providers (e.g. Twitter, Facebook, Google, Microsoft, etc.).
|
OAuth consumer mode allows sign in / sign up via external OAuth providers (e.g. Twitter, Facebook, Google, Microsoft, etc.).
|
||||||
Implementation is based on Ueberauth; see the list of [available strategies](https://github.com/ueberauth/ueberauth/wiki/List-of-Strategies).
|
Implementation is based on Ueberauth; see the list of [available strategies](https://github.com/ueberauth/ueberauth/wiki/List-of-Strategies).
|
||||||
|
@ -459,7 +503,7 @@ Note: make sure that `"SameSite=Lax"` is set in `extra_cookie_attrs` when you ha
|
||||||
Once the app is configured on external OAuth provider side, add app's credentials and strategy-specific settings (if any — e.g. see Microsoft below) to `config/prod.secret.exs`,
|
Once the app is configured on external OAuth provider side, add app's credentials and strategy-specific settings (if any — e.g. see Microsoft below) to `config/prod.secret.exs`,
|
||||||
per strategy's documentation (e.g. [ueberauth_twitter](https://github.com/ueberauth/ueberauth_twitter)). Example config basing on environment variables:
|
per strategy's documentation (e.g. [ueberauth_twitter](https://github.com/ueberauth/ueberauth_twitter)). Example config basing on environment variables:
|
||||||
|
|
||||||
```
|
```elixir
|
||||||
# Twitter
|
# Twitter
|
||||||
config :ueberauth, Ueberauth.Strategy.Twitter.OAuth,
|
config :ueberauth, Ueberauth.Strategy.Twitter.OAuth,
|
||||||
consumer_key: System.get_env("TWITTER_CONSUMER_KEY"),
|
consumer_key: System.get_env("TWITTER_CONSUMER_KEY"),
|
||||||
|
@ -488,6 +532,13 @@ config :ueberauth, Ueberauth,
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## OAuth 2.0 provider - :oauth2
|
||||||
|
|
||||||
|
Configure OAuth 2 provider capabilities:
|
||||||
|
|
||||||
|
* `token_expires_in` - The lifetime in seconds of the access token.
|
||||||
|
* `issue_new_refresh_token` - Keeps old refresh token or generate new refresh token when to obtain an access token.
|
||||||
|
|
||||||
## :emoji
|
## :emoji
|
||||||
* `shortcode_globs`: Location of custom emoji files. `*` can be used as a wildcard. Example `["/emoji/custom/**/*.png"]`
|
* `shortcode_globs`: Location of custom emoji files. `*` can be used as a wildcard. Example `["/emoji/custom/**/*.png"]`
|
||||||
* `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"]]`
|
* `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"]]`
|
||||||
|
|
45
installation/download-mastofe-build.sh
Executable file
45
installation/download-mastofe-build.sh
Executable file
|
@ -0,0 +1,45 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
project_id="74"
|
||||||
|
project_branch="rebase/glitch-soc"
|
||||||
|
static_dir="instance/static"
|
||||||
|
# For bundling:
|
||||||
|
# project_branch="pleroma"
|
||||||
|
# static_dir="priv/static"
|
||||||
|
|
||||||
|
if [[ ! -d "${static_dir}" ]]
|
||||||
|
then
|
||||||
|
echo "Error: ${static_dir} directory is missing, are you sure you are running this script at the root of pleroma’s repository?"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
last_modified="$(curl -s -I 'https://git.pleroma.social/api/v4/projects/'${project_id}'/jobs/artifacts/'${project_branch}'/download?job=build' | grep '^Last-Modified:' | cut -d: -f2-)"
|
||||||
|
|
||||||
|
echo "branch:${project_branch}"
|
||||||
|
echo "Last-Modified:${last_modified}"
|
||||||
|
|
||||||
|
artifact="mastofe.zip"
|
||||||
|
|
||||||
|
if [[ -e mastofe.timestamp ]] && [[ "${last_modified}" != "" ]]
|
||||||
|
then
|
||||||
|
if [[ "$(cat mastofe.timestamp)" == "${last_modified}" ]]
|
||||||
|
then
|
||||||
|
echo "MastoFE is up-to-date, exiting…"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
curl -c - "https://git.pleroma.social/api/v4/projects/${project_id}/jobs/artifacts/${project_branch}/download?job=build" -o "${artifact}" || exit
|
||||||
|
|
||||||
|
# TODO: Update the emoji as well
|
||||||
|
rm -fr "${static_dir}/sw.js" "${static_dir}/packs" || exit
|
||||||
|
unzip -q "${artifact}" || exit
|
||||||
|
|
||||||
|
cp public/assets/sw.js "${static_dir}/sw.js" || exit
|
||||||
|
cp -r public/packs "${static_dir}/packs" || exit
|
||||||
|
|
||||||
|
echo "${last_modified}" > mastofe.timestamp
|
||||||
|
rm -fr public
|
||||||
|
rm -i "${artifact}"
|
25
lib/mix/tasks/benchmark.ex
Normal file
25
lib/mix/tasks/benchmark.ex
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
defmodule Mix.Tasks.Pleroma.Benchmark do
|
||||||
|
use Mix.Task
|
||||||
|
alias Mix.Tasks.Pleroma.Common
|
||||||
|
|
||||||
|
def run(["search"]) do
|
||||||
|
Common.start_pleroma()
|
||||||
|
|
||||||
|
Benchee.run(%{
|
||||||
|
"search" => fn ->
|
||||||
|
Pleroma.Web.MastodonAPI.MastodonAPIController.status_search(nil, "cofe")
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(["tag"]) do
|
||||||
|
Common.start_pleroma()
|
||||||
|
|
||||||
|
Benchee.run(%{
|
||||||
|
"tag" => fn ->
|
||||||
|
%{"type" => "Create", "tag" => "cofe"}
|
||||||
|
|> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
|
@ -109,7 +109,7 @@ def run(["get-packs" | args]) do
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
binary_archive = Tesla.get!(src_url).body
|
binary_archive = Tesla.get!(client(), src_url).body
|
||||||
archive_sha = :crypto.hash(:sha256, binary_archive) |> Base.encode16()
|
archive_sha = :crypto.hash(:sha256, binary_archive) |> Base.encode16()
|
||||||
|
|
||||||
sha_status_text = ["SHA256 of ", :bright, pack_name, :normal, " source file is ", :bright]
|
sha_status_text = ["SHA256 of ", :bright, pack_name, :normal, " source file is ", :bright]
|
||||||
|
@ -137,7 +137,7 @@ def run(["get-packs" | args]) do
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
files = Tesla.get!(files_url).body |> Poison.decode!()
|
files = Tesla.get!(client(), files_url).body |> Jason.decode!()
|
||||||
|
|
||||||
IO.puts(IO.ANSI.format(["Unpacking ", :bright, pack_name]))
|
IO.puts(IO.ANSI.format(["Unpacking ", :bright, pack_name]))
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ def run(["gen-pack", src]) do
|
||||||
|
|
||||||
IO.puts("Downloading the pack and generating SHA256")
|
IO.puts("Downloading the pack and generating SHA256")
|
||||||
|
|
||||||
binary_archive = Tesla.get!(src).body
|
binary_archive = Tesla.get!(client(), src).body
|
||||||
archive_sha = :crypto.hash(:sha256, binary_archive) |> Base.encode16()
|
archive_sha = :crypto.hash(:sha256, binary_archive) |> Base.encode16()
|
||||||
|
|
||||||
IO.puts("SHA256 is #{archive_sha}")
|
IO.puts("SHA256 is #{archive_sha}")
|
||||||
|
@ -239,7 +239,7 @@ def run(["gen-pack", src]) do
|
||||||
|
|
||||||
emoji_map = Pleroma.Emoji.make_shortcode_to_file_map(tmp_pack_dir, exts)
|
emoji_map = Pleroma.Emoji.make_shortcode_to_file_map(tmp_pack_dir, exts)
|
||||||
|
|
||||||
File.write!(files_name, Poison.encode!(emoji_map, pretty: true))
|
File.write!(files_name, Jason.encode!(emoji_map, pretty: true))
|
||||||
|
|
||||||
IO.puts("""
|
IO.puts("""
|
||||||
|
|
||||||
|
@ -248,11 +248,11 @@ def run(["gen-pack", src]) do
|
||||||
""")
|
""")
|
||||||
|
|
||||||
if File.exists?("index.json") do
|
if File.exists?("index.json") do
|
||||||
existing_data = File.read!("index.json") |> Poison.decode!()
|
existing_data = File.read!("index.json") |> Jason.decode!()
|
||||||
|
|
||||||
File.write!(
|
File.write!(
|
||||||
"index.json",
|
"index.json",
|
||||||
Poison.encode!(
|
Jason.encode!(
|
||||||
Map.merge(
|
Map.merge(
|
||||||
existing_data,
|
existing_data,
|
||||||
pack_json
|
pack_json
|
||||||
|
@ -263,16 +263,16 @@ def run(["gen-pack", src]) do
|
||||||
|
|
||||||
IO.puts("index.json file has been update with the #{name} pack")
|
IO.puts("index.json file has been update with the #{name} pack")
|
||||||
else
|
else
|
||||||
File.write!("index.json", Poison.encode!(pack_json, pretty: true))
|
File.write!("index.json", Jason.encode!(pack_json, pretty: true))
|
||||||
|
|
||||||
IO.puts("index.json has been created with the #{name} pack")
|
IO.puts("index.json has been created with the #{name} pack")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp fetch_manifest(from) do
|
defp fetch_manifest(from) do
|
||||||
Poison.decode!(
|
Jason.decode!(
|
||||||
if String.starts_with?(from, "http") do
|
if String.starts_with?(from, "http") do
|
||||||
Tesla.get!(from).body
|
Tesla.get!(client(), from).body
|
||||||
else
|
else
|
||||||
File.read!(from)
|
File.read!(from)
|
||||||
end
|
end
|
||||||
|
@ -290,4 +290,12 @@ defp parse_global_opts(args) do
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp client do
|
||||||
|
middleware = [
|
||||||
|
{Tesla.Middleware.FollowRedirects, [max_redirects: 3]}
|
||||||
|
]
|
||||||
|
|
||||||
|
Tesla.client(middleware)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -126,7 +126,7 @@ def run(["new", nickname, email | rest]) do
|
||||||
|
|
||||||
proceed? = assume_yes? or Mix.shell().yes?("Continue?")
|
proceed? = assume_yes? or Mix.shell().yes?("Continue?")
|
||||||
|
|
||||||
unless not proceed? do
|
if proceed? do
|
||||||
Common.start_pleroma()
|
Common.start_pleroma()
|
||||||
|
|
||||||
params = %{
|
params = %{
|
||||||
|
@ -138,7 +138,7 @@ def run(["new", nickname, email | rest]) do
|
||||||
bio: bio
|
bio: bio
|
||||||
}
|
}
|
||||||
|
|
||||||
changeset = User.register_changeset(%User{}, params, confirmed: true)
|
changeset = User.register_changeset(%User{}, params, need_confirmation: false)
|
||||||
{:ok, _user} = User.register(changeset)
|
{:ok, _user} = User.register(changeset)
|
||||||
|
|
||||||
Mix.shell().info("User #{nickname} created")
|
Mix.shell().info("User #{nickname} created")
|
||||||
|
@ -163,7 +163,7 @@ def run(["rm", nickname]) do
|
||||||
Common.start_pleroma()
|
Common.start_pleroma()
|
||||||
|
|
||||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||||
User.delete(user)
|
User.perform(:delete, user)
|
||||||
Mix.shell().info("User #{nickname} deleted.")
|
Mix.shell().info("User #{nickname} deleted.")
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -380,7 +380,7 @@ def run(["delete_activities", nickname]) do
|
||||||
Common.start_pleroma()
|
Common.start_pleroma()
|
||||||
|
|
||||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||||
User.delete_user_activities(user)
|
{:ok, _} = User.delete_user_activities(user)
|
||||||
Mix.shell().info("User #{nickname} statuses deleted.")
|
Mix.shell().info("User #{nickname} statuses deleted.")
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
|
|
|
@ -6,14 +6,18 @@ defmodule Pleroma.Activity do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Bookmark
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
@type t :: %__MODULE__{}
|
@type t :: %__MODULE__{}
|
||||||
|
@type actor :: String.t()
|
||||||
|
|
||||||
@primary_key {:id, Pleroma.FlakeId, autogenerate: true}
|
@primary_key {:id, Pleroma.FlakeId, autogenerate: true}
|
||||||
|
|
||||||
# https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19
|
# https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19
|
||||||
|
@ -33,6 +37,8 @@ defmodule Pleroma.Activity do
|
||||||
field(:local, :boolean, default: true)
|
field(:local, :boolean, default: true)
|
||||||
field(:actor, :string)
|
field(:actor, :string)
|
||||||
field(:recipients, {:array, :string}, default: [])
|
field(:recipients, {:array, :string}, default: [])
|
||||||
|
# This is a fake relation, do not use outside of with_preloaded_bookmark/get_bookmark
|
||||||
|
has_one(:bookmark, Bookmark)
|
||||||
has_many(:notifications, Notification, on_delete: :delete_all)
|
has_many(:notifications, Notification, on_delete: :delete_all)
|
||||||
|
|
||||||
# Attention: this is a fake relation, don't try to preload it blindly and expect it to work!
|
# Attention: this is a fake relation, don't try to preload it blindly and expect it to work!
|
||||||
|
@ -71,6 +77,16 @@ def with_preloaded_object(query) do
|
||||||
|> preload([activity, object], object: object)
|
|> preload([activity, object], object: object)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_preloaded_bookmark(query, %User{} = user) do
|
||||||
|
from([a] in query,
|
||||||
|
left_join: b in Bookmark,
|
||||||
|
on: b.user_id == ^user.id and b.activity_id == a.id,
|
||||||
|
preload: [bookmark: b]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def with_preloaded_bookmark(query, _), do: query
|
||||||
|
|
||||||
def get_by_ap_id(ap_id) do
|
def get_by_ap_id(ap_id) do
|
||||||
Repo.one(
|
Repo.one(
|
||||||
from(
|
from(
|
||||||
|
@ -80,6 +96,16 @@ def get_by_ap_id(ap_id) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_bookmark(%Activity{} = activity, %User{} = user) do
|
||||||
|
if Ecto.assoc_loaded?(activity.bookmark) do
|
||||||
|
activity.bookmark
|
||||||
|
else
|
||||||
|
Bookmark.get(user.id, activity.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_bookmark(_, _), do: nil
|
||||||
|
|
||||||
def change(struct, params \\ %{}) do
|
def change(struct, params \\ %{}) do
|
||||||
struct
|
struct
|
||||||
|> cast(params, [:data])
|
|> cast(params, [:data])
|
||||||
|
@ -260,4 +286,32 @@ def all_by_actor_and_id(actor, status_ids) do
|
||||||
|> where([s], s.actor == ^actor)
|
|> where([s], s.actor == ^actor)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def follow_requests_for_actor(%Pleroma.User{ap_id: ap_id}) do
|
||||||
|
from(
|
||||||
|
a in Activity,
|
||||||
|
where:
|
||||||
|
fragment(
|
||||||
|
"? ->> 'type' = 'Follow'",
|
||||||
|
a.data
|
||||||
|
),
|
||||||
|
where:
|
||||||
|
fragment(
|
||||||
|
"? ->> 'state' = 'pending'",
|
||||||
|
a.data
|
||||||
|
),
|
||||||
|
where:
|
||||||
|
fragment(
|
||||||
|
"coalesce((?)->'object'->>'id', (?)->>'object') = ?",
|
||||||
|
a.data,
|
||||||
|
a.data,
|
||||||
|
^ap_id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec query_by_actor(actor()) :: Ecto.Query.t()
|
||||||
|
def query_by_actor(actor) do
|
||||||
|
from(a in Activity, where: a.actor == ^actor)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
16
lib/pleroma/bbs/authenticator.ex
Normal file
16
lib/pleroma/bbs/authenticator.ex
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
defmodule Pleroma.BBS.Authenticator do
|
||||||
|
use Sshd.PasswordAuthenticator
|
||||||
|
alias Comeonin.Pbkdf2
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
|
def authenticate(username, password) do
|
||||||
|
username = to_string(username)
|
||||||
|
password = to_string(password)
|
||||||
|
|
||||||
|
with %User{} = user <- User.get_by_nickname(username) do
|
||||||
|
Pbkdf2.checkpw(password, user.password_hash)
|
||||||
|
else
|
||||||
|
_e -> false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
147
lib/pleroma/bbs/handler.ex
Normal file
147
lib/pleroma/bbs/handler.ex
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
defmodule Pleroma.BBS.Handler do
|
||||||
|
use Sshd.ShellHandler
|
||||||
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
|
def on_shell(username, _pubkey, _ip, _port) do
|
||||||
|
:ok = IO.puts("Welcome to #{Pleroma.Config.get([:instance, :name])}!")
|
||||||
|
user = Pleroma.User.get_cached_by_nickname(to_string(username))
|
||||||
|
Logger.debug("#{inspect(user)}")
|
||||||
|
loop(run_state(user: user))
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_connect(username, ip, port, method) do
|
||||||
|
Logger.debug(fn ->
|
||||||
|
"""
|
||||||
|
Incoming SSH shell #{inspect(self())} requested for #{username} from #{inspect(ip)}:#{
|
||||||
|
inspect(port)
|
||||||
|
} using #{inspect(method)}
|
||||||
|
"""
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_disconnect(username, ip, port) do
|
||||||
|
Logger.debug(fn ->
|
||||||
|
"Disconnecting SSH shell for #{username} from #{inspect(ip)}:#{inspect(port)}"
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp loop(state) do
|
||||||
|
self_pid = self()
|
||||||
|
counter = state.counter
|
||||||
|
prefix = state.prefix
|
||||||
|
user = state.user
|
||||||
|
|
||||||
|
input = spawn(fn -> io_get(self_pid, prefix, counter, user.nickname) end)
|
||||||
|
wait_input(state, input)
|
||||||
|
end
|
||||||
|
|
||||||
|
def puts_activity(activity) do
|
||||||
|
status = Pleroma.Web.MastodonAPI.StatusView.render("status.json", %{activity: activity})
|
||||||
|
IO.puts("-- #{status.id} by #{status.account.display_name} (#{status.account.acct})")
|
||||||
|
IO.puts(HtmlSanitizeEx.strip_tags(status.content))
|
||||||
|
IO.puts("")
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_command(state, "help") do
|
||||||
|
IO.puts("Available commands:")
|
||||||
|
IO.puts("help - This help")
|
||||||
|
IO.puts("home - Show the home timeline")
|
||||||
|
IO.puts("p <text> - Post the given text")
|
||||||
|
IO.puts("r <id> <text> - Reply to the post with the given id")
|
||||||
|
IO.puts("quit - Quit")
|
||||||
|
|
||||||
|
state
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_command(%{user: user} = state, "r " <> text) do
|
||||||
|
text = String.trim(text)
|
||||||
|
[activity_id, rest] = String.split(text, " ", parts: 2)
|
||||||
|
|
||||||
|
with %Activity{} <- Activity.get_by_id(activity_id),
|
||||||
|
{:ok, _activity} <-
|
||||||
|
CommonAPI.post(user, %{"status" => rest, "in_reply_to_status_id" => activity_id}) do
|
||||||
|
IO.puts("Replied!")
|
||||||
|
else
|
||||||
|
_e -> IO.puts("Could not reply...")
|
||||||
|
end
|
||||||
|
|
||||||
|
state
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_command(%{user: user} = state, "p " <> text) do
|
||||||
|
text = String.trim(text)
|
||||||
|
|
||||||
|
with {:ok, _activity} <- CommonAPI.post(user, %{"status" => text}) do
|
||||||
|
IO.puts("Posted!")
|
||||||
|
else
|
||||||
|
_e -> IO.puts("Could not post...")
|
||||||
|
end
|
||||||
|
|
||||||
|
state
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_command(state, "home") do
|
||||||
|
user = state.user
|
||||||
|
|
||||||
|
params =
|
||||||
|
%{}
|
||||||
|
|> Map.put("type", ["Create"])
|
||||||
|
|> Map.put("blocking_user", user)
|
||||||
|
|> Map.put("muting_user", user)
|
||||||
|
|> Map.put("user", user)
|
||||||
|
|
||||||
|
activities =
|
||||||
|
[user.ap_id | user.following]
|
||||||
|
|> ActivityPub.fetch_activities(params)
|
||||||
|
|> ActivityPub.contain_timeline(user)
|
||||||
|
|
||||||
|
Enum.each(activities, fn activity ->
|
||||||
|
puts_activity(activity)
|
||||||
|
end)
|
||||||
|
|
||||||
|
state
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_command(state, command) do
|
||||||
|
IO.puts("Unknown command '#{command}'")
|
||||||
|
state
|
||||||
|
end
|
||||||
|
|
||||||
|
defp wait_input(state, input) do
|
||||||
|
receive do
|
||||||
|
{:input, ^input, "quit\n"} ->
|
||||||
|
IO.puts("Exiting...")
|
||||||
|
|
||||||
|
{:input, ^input, code} when is_binary(code) ->
|
||||||
|
code = String.trim(code)
|
||||||
|
|
||||||
|
state = handle_command(state, code)
|
||||||
|
|
||||||
|
loop(%{state | counter: state.counter + 1})
|
||||||
|
|
||||||
|
{:error, :interrupted} ->
|
||||||
|
IO.puts("Caught Ctrl+C...")
|
||||||
|
loop(%{state | counter: state.counter + 1})
|
||||||
|
|
||||||
|
{:input, ^input, msg} ->
|
||||||
|
:ok = Logger.warn("received unknown message: #{inspect(msg)}")
|
||||||
|
loop(%{state | counter: state.counter + 1})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp run_state(opts) do
|
||||||
|
%{prefix: "pleroma", counter: 1, user: opts[:user]}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp io_get(pid, prefix, counter, username) do
|
||||||
|
prompt = prompt(prefix, counter, username)
|
||||||
|
send(pid, {:input, self(), IO.gets(:stdio, prompt)})
|
||||||
|
end
|
||||||
|
|
||||||
|
defp prompt(prefix, counter, username) do
|
||||||
|
prompt = "#{username}@#{prefix}:#{counter}>"
|
||||||
|
prompt <> " "
|
||||||
|
end
|
||||||
|
end
|
60
lib/pleroma/bookmark.ex
Normal file
60
lib/pleroma/bookmark.ex
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
defmodule Pleroma.Bookmark do
|
||||||
|
use Ecto.Schema
|
||||||
|
|
||||||
|
import Ecto.Changeset
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Bookmark
|
||||||
|
alias Pleroma.FlakeId
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
|
schema "bookmarks" do
|
||||||
|
belongs_to(:user, User, type: FlakeId)
|
||||||
|
belongs_to(:activity, Activity, type: FlakeId)
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec create(FlakeId.t(), FlakeId.t()) :: {:ok, Bookmark.t()} | {:error, Changeset.t()}
|
||||||
|
def create(user_id, activity_id) do
|
||||||
|
attrs = %{
|
||||||
|
user_id: user_id,
|
||||||
|
activity_id: activity_id
|
||||||
|
}
|
||||||
|
|
||||||
|
%Bookmark{}
|
||||||
|
|> cast(attrs, [:user_id, :activity_id])
|
||||||
|
|> validate_required([:user_id, :activity_id])
|
||||||
|
|> unique_constraint(:activity_id, name: :bookmarks_user_id_activity_id_index)
|
||||||
|
|> Repo.insert()
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec for_user_query(FlakeId.t()) :: Ecto.Query.t()
|
||||||
|
def for_user_query(user_id) do
|
||||||
|
Bookmark
|
||||||
|
|> where(user_id: ^user_id)
|
||||||
|
|> join(:inner, [b], activity in assoc(b, :activity))
|
||||||
|
|> preload([b, a], activity: a)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(user_id, activity_id) do
|
||||||
|
Bookmark
|
||||||
|
|> where(user_id: ^user_id)
|
||||||
|
|> where(activity_id: ^activity_id)
|
||||||
|
|> Repo.one()
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec destroy(FlakeId.t(), FlakeId.t()) :: {:ok, Bookmark.t()} | {:error, Changeset.t()}
|
||||||
|
def destroy(user_id, activity_id) do
|
||||||
|
from(b in Bookmark,
|
||||||
|
where: b.user_id == ^user_id,
|
||||||
|
where: b.activity_id == ^activity_id
|
||||||
|
)
|
||||||
|
|> Repo.one()
|
||||||
|
|> Repo.delete()
|
||||||
|
end
|
||||||
|
end
|
|
@ -15,7 +15,7 @@ def new do
|
||||||
%{error: "Kocaptcha service unavailable"}
|
%{error: "Kocaptcha service unavailable"}
|
||||||
|
|
||||||
{:ok, res} ->
|
{:ok, res} ->
|
||||||
json_resp = Poison.decode!(res.body)
|
json_resp = Jason.decode!(res.body)
|
||||||
|
|
||||||
%{
|
%{
|
||||||
type: :kocaptcha,
|
type: :kocaptcha,
|
||||||
|
|
75
lib/pleroma/conversation.ex
Normal file
75
lib/pleroma/conversation.ex
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Conversation do
|
||||||
|
alias Pleroma.Conversation.Participation
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
|
use Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
schema "conversations" do
|
||||||
|
# This is the context ap id.
|
||||||
|
field(:ap_id, :string)
|
||||||
|
has_many(:participations, Participation)
|
||||||
|
has_many(:users, through: [:participations, :user])
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
def creation_cng(struct, params) do
|
||||||
|
struct
|
||||||
|
|> cast(params, [:ap_id])
|
||||||
|
|> validate_required([:ap_id])
|
||||||
|
|> unique_constraint(:ap_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_for_ap_id(ap_id) do
|
||||||
|
%__MODULE__{}
|
||||||
|
|> creation_cng(%{ap_id: ap_id})
|
||||||
|
|> Repo.insert(
|
||||||
|
on_conflict: [set: [updated_at: NaiveDateTime.utc_now()]],
|
||||||
|
returning: true,
|
||||||
|
conflict_target: :ap_id
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_for_ap_id(ap_id) do
|
||||||
|
Repo.get_by(__MODULE__, ap_id: ap_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
This will
|
||||||
|
1. Create a conversation if there isn't one already
|
||||||
|
2. Create a participation for all the people involved who don't have one already
|
||||||
|
3. Bump all relevant participations to 'unread'
|
||||||
|
"""
|
||||||
|
def create_or_bump_for(activity) do
|
||||||
|
with true <- Pleroma.Web.ActivityPub.Visibility.is_direct?(activity),
|
||||||
|
"Create" <- activity.data["type"],
|
||||||
|
object <- Pleroma.Object.normalize(activity),
|
||||||
|
"Note" <- object.data["type"],
|
||||||
|
ap_id when is_binary(ap_id) and byte_size(ap_id) > 0 <- object.data["context"] do
|
||||||
|
{:ok, conversation} = create_for_ap_id(ap_id)
|
||||||
|
|
||||||
|
users = User.get_users_from_set(activity.recipients, false)
|
||||||
|
|
||||||
|
participations =
|
||||||
|
Enum.map(users, fn user ->
|
||||||
|
{:ok, participation} =
|
||||||
|
Participation.create_for_user_and_conversation(user, conversation)
|
||||||
|
|
||||||
|
participation
|
||||||
|
end)
|
||||||
|
|
||||||
|
{:ok,
|
||||||
|
%{
|
||||||
|
conversation
|
||||||
|
| participations: participations
|
||||||
|
}}
|
||||||
|
else
|
||||||
|
e -> {:error, e}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
81
lib/pleroma/conversation/participation.ex
Normal file
81
lib/pleroma/conversation/participation.ex
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Conversation.Participation do
|
||||||
|
use Ecto.Schema
|
||||||
|
alias Pleroma.Conversation
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
import Ecto.Changeset
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
schema "conversation_participations" do
|
||||||
|
belongs_to(:user, User, type: Pleroma.FlakeId)
|
||||||
|
belongs_to(:conversation, Conversation)
|
||||||
|
field(:read, :boolean, default: false)
|
||||||
|
field(:last_activity_id, Pleroma.FlakeId, virtual: true)
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
def creation_cng(struct, params) do
|
||||||
|
struct
|
||||||
|
|> cast(params, [:user_id, :conversation_id])
|
||||||
|
|> validate_required([:user_id, :conversation_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_for_user_and_conversation(user, conversation) do
|
||||||
|
%__MODULE__{}
|
||||||
|
|> creation_cng(%{user_id: user.id, conversation_id: conversation.id})
|
||||||
|
|> Repo.insert(
|
||||||
|
on_conflict: [set: [read: false, updated_at: NaiveDateTime.utc_now()]],
|
||||||
|
returning: true,
|
||||||
|
conflict_target: [:user_id, :conversation_id]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_cng(struct, params) do
|
||||||
|
struct
|
||||||
|
|> cast(params, [:read])
|
||||||
|
|> validate_required([:read])
|
||||||
|
end
|
||||||
|
|
||||||
|
def mark_as_read(participation) do
|
||||||
|
participation
|
||||||
|
|> read_cng(%{read: true})
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
|
||||||
|
def mark_as_unread(participation) do
|
||||||
|
participation
|
||||||
|
|> read_cng(%{read: false})
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
|
||||||
|
def for_user(user, params \\ %{}) do
|
||||||
|
from(p in __MODULE__,
|
||||||
|
where: p.user_id == ^user.id,
|
||||||
|
order_by: [desc: p.updated_at]
|
||||||
|
)
|
||||||
|
|> Pleroma.Pagination.fetch_paginated(params)
|
||||||
|
|> Repo.preload(conversation: [:users])
|
||||||
|
end
|
||||||
|
|
||||||
|
def for_user_with_last_activity_id(user, params \\ %{}) do
|
||||||
|
for_user(user, params)
|
||||||
|
|> Enum.map(fn participation ->
|
||||||
|
activity_id =
|
||||||
|
ActivityPub.fetch_latest_activity_id_for_context(participation.conversation.ap_id, %{
|
||||||
|
"user" => user,
|
||||||
|
"blocking_user" => user
|
||||||
|
})
|
||||||
|
|
||||||
|
%{
|
||||||
|
participation
|
||||||
|
| last_activity_id: activity_id
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
|
@ -113,9 +113,7 @@ def emojify(text, emoji, strip \\ false) do
|
||||||
|
|
||||||
html =
|
html =
|
||||||
if not strip do
|
if not strip do
|
||||||
"<img height='32px' width='32px' alt='#{emoji}' title='#{emoji}' src='#{
|
"<img class='emoji' alt='#{emoji}' title='#{emoji}' src='#{MediaProxy.url(file)}' />"
|
||||||
MediaProxy.url(file)
|
|
||||||
}' />"
|
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
@ -130,12 +128,23 @@ def demojify(text) do
|
||||||
|
|
||||||
def demojify(text, nil), do: text
|
def demojify(text, nil), do: text
|
||||||
|
|
||||||
|
@doc "Outputs a list of the emoji-shortcodes in a text"
|
||||||
def get_emoji(text) when is_binary(text) do
|
def get_emoji(text) when is_binary(text) do
|
||||||
Enum.filter(Emoji.get_all(), fn {emoji, _, _} -> String.contains?(text, ":#{emoji}:") end)
|
Enum.filter(Emoji.get_all(), fn {emoji, _, _} -> String.contains?(text, ":#{emoji}:") end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_emoji(_), do: []
|
def get_emoji(_), do: []
|
||||||
|
|
||||||
|
@doc "Outputs a list of the emoji-Maps in a text"
|
||||||
|
def get_emoji_map(text) when is_binary(text) do
|
||||||
|
get_emoji(text)
|
||||||
|
|> Enum.reduce(%{}, fn {name, file, _group}, acc ->
|
||||||
|
Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}")
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_emoji_map(_), do: []
|
||||||
|
|
||||||
def html_escape({text, mentions, hashtags}, type) do
|
def html_escape({text, mentions, hashtags}, type) do
|
||||||
{html_escape(text, type), mentions, hashtags}
|
{html_escape(text, type), mentions, hashtags}
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,12 +28,18 @@ def filter_tags(html, scrubber), do: Scrubber.scrub(html, scrubber)
|
||||||
def filter_tags(html), do: filter_tags(html, nil)
|
def filter_tags(html), do: filter_tags(html, nil)
|
||||||
def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags)
|
def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags)
|
||||||
|
|
||||||
def get_cached_scrubbed_html_for_activity(content, scrubbers, activity, key \\ "") do
|
def get_cached_scrubbed_html_for_activity(
|
||||||
|
content,
|
||||||
|
scrubbers,
|
||||||
|
activity,
|
||||||
|
key \\ "",
|
||||||
|
callback \\ fn x -> x end
|
||||||
|
) do
|
||||||
key = "#{key}#{generate_scrubber_signature(scrubbers)}|#{activity.id}"
|
key = "#{key}#{generate_scrubber_signature(scrubbers)}|#{activity.id}"
|
||||||
|
|
||||||
Cachex.fetch!(:scrubber_cache, key, fn _key ->
|
Cachex.fetch!(:scrubber_cache, key, fn _key ->
|
||||||
object = Pleroma.Object.normalize(activity)
|
object = Pleroma.Object.normalize(activity)
|
||||||
ensure_scrubbed_html(content, scrubbers, object.data["fake"] || false)
|
ensure_scrubbed_html(content, scrubbers, object.data["fake"] || false, callback)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -42,24 +48,27 @@ def get_cached_stripped_html_for_activity(content, activity, key) do
|
||||||
content,
|
content,
|
||||||
HtmlSanitizeEx.Scrubber.StripTags,
|
HtmlSanitizeEx.Scrubber.StripTags,
|
||||||
activity,
|
activity,
|
||||||
key
|
key,
|
||||||
|
&HtmlEntities.decode/1
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_scrubbed_html(
|
def ensure_scrubbed_html(
|
||||||
content,
|
content,
|
||||||
scrubbers,
|
scrubbers,
|
||||||
false = _fake
|
fake,
|
||||||
|
callback
|
||||||
) do
|
) do
|
||||||
{:commit, filter_tags(content, scrubbers)}
|
content =
|
||||||
end
|
content
|
||||||
|
|> filter_tags(scrubbers)
|
||||||
|
|> callback.()
|
||||||
|
|
||||||
def ensure_scrubbed_html(
|
if fake do
|
||||||
content,
|
{:ignore, content}
|
||||||
scrubbers,
|
else
|
||||||
true = _fake
|
{:commit, content}
|
||||||
) do
|
end
|
||||||
{:ignore, filter_tags(content, scrubbers)}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp generate_scrubber_signature(scrubber) when is_atom(scrubber) do
|
defp generate_scrubber_signature(scrubber) when is_atom(scrubber) do
|
||||||
|
@ -142,6 +151,7 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do
|
||||||
Meta.allow_tag_with_these_attributes("img", [
|
Meta.allow_tag_with_these_attributes("img", [
|
||||||
"width",
|
"width",
|
||||||
"height",
|
"height",
|
||||||
|
"class",
|
||||||
"title",
|
"title",
|
||||||
"alt"
|
"alt"
|
||||||
])
|
])
|
||||||
|
@ -212,6 +222,7 @@ defmodule Pleroma.HTML.Scrubber.Default do
|
||||||
Meta.allow_tag_with_these_attributes("img", [
|
Meta.allow_tag_with_these_attributes("img", [
|
||||||
"width",
|
"width",
|
||||||
"height",
|
"height",
|
||||||
|
"class",
|
||||||
"title",
|
"title",
|
||||||
"alt"
|
"alt"
|
||||||
])
|
])
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
defmodule Pleroma.Object.Containment do
|
defmodule Pleroma.Object.Containment do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
# Object Containment
|
|
||||||
|
|
||||||
This module contains some useful functions for containing objects to specific
|
This module contains some useful functions for containing objects to specific
|
||||||
origins and determining those origins. They previously lived in the
|
origins and determining those origins. They previously lived in the
|
||||||
ActivityPub `Transmogrifier` module.
|
ActivityPub `Transmogrifier` module.
|
||||||
|
|
|
@ -35,7 +35,7 @@ defp headers do
|
||||||
defp csp_string do
|
defp csp_string do
|
||||||
scheme = Config.get([Pleroma.Web.Endpoint, :url])[:scheme]
|
scheme = Config.get([Pleroma.Web.Endpoint, :url])[:scheme]
|
||||||
static_url = Pleroma.Web.Endpoint.static_url()
|
static_url = Pleroma.Web.Endpoint.static_url()
|
||||||
websocket_url = String.replace(static_url, "http", "ws")
|
websocket_url = Pleroma.Web.Endpoint.websocket_url()
|
||||||
|
|
||||||
connect_src = "connect-src 'self' #{static_url} #{websocket_url}"
|
connect_src = "connect-src 'self' #{static_url} #{websocket_url}"
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Plugs.OAuthPlug do
|
||||||
|
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.OAuth.App
|
||||||
alias Pleroma.Web.OAuth.Token
|
alias Pleroma.Web.OAuth.Token
|
||||||
|
|
||||||
@realm_reg Regex.compile!("Bearer\:?\s+(.*)$", "i")
|
@realm_reg Regex.compile!("Bearer\:?\s+(.*)$", "i")
|
||||||
|
@ -16,16 +17,47 @@ def init(options), do: options
|
||||||
|
|
||||||
def call(%{assigns: %{user: %User{}}} = conn, _), do: conn
|
def call(%{assigns: %{user: %User{}}} = conn, _), do: conn
|
||||||
|
|
||||||
def call(conn, _) do
|
def call(%{params: %{"access_token" => access_token}} = conn, _) do
|
||||||
with {:ok, token_str} <- fetch_token_str(conn),
|
with {:ok, user, token_record} <- fetch_user_and_token(access_token) do
|
||||||
{:ok, user, token_record} <- fetch_user_and_token(token_str) do
|
|
||||||
conn
|
conn
|
||||||
|> assign(:token, token_record)
|
|> assign(:token, token_record)
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
# token found, but maybe only with app
|
||||||
|
with {:ok, app, token_record} <- fetch_app_and_token(access_token) do
|
||||||
|
conn
|
||||||
|
|> assign(:token, token_record)
|
||||||
|
|> assign(:app, app)
|
||||||
else
|
else
|
||||||
_ -> conn
|
_ -> conn
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(conn, _) do
|
||||||
|
case fetch_token_str(conn) do
|
||||||
|
{:ok, token} ->
|
||||||
|
with {:ok, user, token_record} <- fetch_user_and_token(token) do
|
||||||
|
conn
|
||||||
|
|> assign(:token, token_record)
|
||||||
|
|> assign(:user, user)
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
# token found, but maybe only with app
|
||||||
|
with {:ok, app, token_record} <- fetch_app_and_token(token) do
|
||||||
|
conn
|
||||||
|
|> assign(:token, token_record)
|
||||||
|
|> assign(:app, app)
|
||||||
|
else
|
||||||
|
_ -> conn
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
conn
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Gets user by token
|
# Gets user by token
|
||||||
#
|
#
|
||||||
|
@ -44,6 +76,16 @@ defp fetch_user_and_token(token) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec fetch_app_and_token(String.t()) :: {:ok, App.t(), Token.t()} | nil
|
||||||
|
defp fetch_app_and_token(token) do
|
||||||
|
query =
|
||||||
|
from(t in Token, where: t.token == ^token, join: app in assoc(t, :app), preload: [app: app])
|
||||||
|
|
||||||
|
with %Token{app: app} = token_record <- Repo.one(query) do
|
||||||
|
{:ok, app, token_record}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Gets token from session by :oauth_token key
|
# Gets token from session by :oauth_token key
|
||||||
#
|
#
|
||||||
@spec fetch_token_from_session(Plug.Conn.t()) :: :no_token_found | {:ok, String.t()}
|
@spec fetch_token_from_session(Plug.Conn.t()) :: :no_token_found | {:ok, String.t()}
|
||||||
|
|
36
lib/pleroma/plugs/rate_limit_plug.ex
Normal file
36
lib/pleroma/plugs/rate_limit_plug.ex
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Plugs.RateLimitPlug do
|
||||||
|
import Phoenix.Controller, only: [json: 2]
|
||||||
|
import Plug.Conn
|
||||||
|
|
||||||
|
def init(opts), do: opts
|
||||||
|
|
||||||
|
def call(conn, opts) do
|
||||||
|
enabled? = Pleroma.Config.get([:app_account_creation, :enabled])
|
||||||
|
|
||||||
|
case check_rate(conn, Map.put(opts, :enabled, enabled?)) do
|
||||||
|
{:ok, _count} -> conn
|
||||||
|
{:error, _count} -> render_error(conn)
|
||||||
|
%Plug.Conn{} = conn -> conn
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp check_rate(conn, %{enabled: true} = opts) do
|
||||||
|
max_requests = opts[:max_requests]
|
||||||
|
bucket_name = conn.remote_ip |> Tuple.to_list() |> Enum.join(".")
|
||||||
|
|
||||||
|
ExRated.check_rate(bucket_name, opts[:interval] * 1000, max_requests)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp check_rate(conn, _), do: conn
|
||||||
|
|
||||||
|
defp render_error(conn) do
|
||||||
|
conn
|
||||||
|
|> put_status(:forbidden)
|
||||||
|
|> json(%{error: "Rate limit exceeded."})
|
||||||
|
|> halt()
|
||||||
|
end
|
||||||
|
end
|
|
@ -19,4 +19,32 @@ defmodule Instrumenter do
|
||||||
def init(_, opts) do
|
def init(_, opts) do
|
||||||
{:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))}
|
{:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc "find resource based on prepared query"
|
||||||
|
@spec find_resource(Ecto.Query.t()) :: {:ok, struct()} | {:error, :not_found}
|
||||||
|
def find_resource(%Ecto.Query{} = query) do
|
||||||
|
case __MODULE__.one(query) do
|
||||||
|
nil -> {:error, :not_found}
|
||||||
|
resource -> {:ok, resource}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_resource(_query), do: {:error, :not_found}
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Gets association from cache or loads if need
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> Repo.get_assoc(token, :user)
|
||||||
|
%User{}
|
||||||
|
|
||||||
|
"""
|
||||||
|
@spec get_assoc(struct(), atom()) :: {:ok, struct()} | {:error, :not_found}
|
||||||
|
def get_assoc(resource, association) do
|
||||||
|
case __MODULE__.preload(resource, association) do
|
||||||
|
%{^association => assoc} when not is_nil(assoc) -> {:ok, assoc}
|
||||||
|
_ -> {:error, :not_found}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,7 +34,7 @@ def schedule_update do
|
||||||
def update_stats do
|
def update_stats do
|
||||||
peers =
|
peers =
|
||||||
from(
|
from(
|
||||||
u in Pleroma.User,
|
u in User,
|
||||||
select: fragment("distinct split_part(?, '@', 2)", u.nickname),
|
select: fragment("distinct split_part(?, '@', 2)", u.nickname),
|
||||||
where: u.local != ^true
|
where: u.local != ^true
|
||||||
)
|
)
|
||||||
|
@ -44,10 +44,13 @@ def update_stats do
|
||||||
domain_count = Enum.count(peers)
|
domain_count = Enum.count(peers)
|
||||||
|
|
||||||
status_query =
|
status_query =
|
||||||
from(u in User.local_user_query(), select: fragment("sum((?->>'note_count')::int)", u.info))
|
from(u in User.Query.build(%{local: true}),
|
||||||
|
select: fragment("sum((?->>'note_count')::int)", u.info)
|
||||||
|
)
|
||||||
|
|
||||||
status_count = Repo.one(status_query)
|
status_count = Repo.one(status_query)
|
||||||
user_count = Repo.aggregate(User.active_local_user_query(), :count, :id)
|
|
||||||
|
user_count = Repo.aggregate(User.Query.build(%{local: true, active: true}), :count, :id)
|
||||||
|
|
||||||
Agent.update(__MODULE__, fn _ ->
|
Agent.update(__MODULE__, fn _ ->
|
||||||
{peers, %{domain_count: domain_count, status_count: status_count, user_count: user_count}}
|
{peers, %{domain_count: domain_count, status_count: status_count, user_count: user_count}}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
defmodule Pleroma.Upload do
|
defmodule Pleroma.Upload do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
# Upload
|
Manage user uploads
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
* `:type`: presets for activity type (defaults to Document) and size limits from app configuration
|
* `:type`: presets for activity type (defaults to Document) and size limits from app configuration
|
||||||
|
|
|
@ -14,7 +14,7 @@ def process_url(url) do
|
||||||
|
|
||||||
def process_response_body(body) do
|
def process_response_body(body) do
|
||||||
body
|
body
|
||||||
|> Poison.decode!()
|
|> Jason.decode!()
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_token do
|
def get_token do
|
||||||
|
@ -38,7 +38,7 @@ def get_token do
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_auth_body(username, password, tenant) do
|
def make_auth_body(username, password, tenant) do
|
||||||
Poison.encode!(%{
|
Jason.encode!(%{
|
||||||
:auth => %{
|
:auth => %{
|
||||||
:passwordCredentials => %{
|
:passwordCredentials => %{
|
||||||
:username => username,
|
:username => username,
|
||||||
|
|
|
@ -10,7 +10,6 @@ defmodule Pleroma.User do
|
||||||
|
|
||||||
alias Comeonin.Pbkdf2
|
alias Comeonin.Pbkdf2
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Formatter
|
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Registration
|
alias Pleroma.Registration
|
||||||
|
@ -53,7 +52,6 @@ defmodule Pleroma.User do
|
||||||
field(:search_rank, :float, virtual: true)
|
field(:search_rank, :float, virtual: true)
|
||||||
field(:search_type, :integer, virtual: true)
|
field(:search_type, :integer, virtual: true)
|
||||||
field(:tags, {:array, :string}, default: [])
|
field(:tags, {:array, :string}, default: [])
|
||||||
field(:bookmarks, {:array, :string}, default: [])
|
|
||||||
field(:last_refreshed_at, :naive_datetime_usec)
|
field(:last_refreshed_at, :naive_datetime_usec)
|
||||||
has_many(:notifications, Notification)
|
has_many(:notifications, Notification)
|
||||||
has_many(:registrations, Registration)
|
has_many(:registrations, Registration)
|
||||||
|
@ -206,14 +204,15 @@ def reset_password(user, data) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_changeset(struct, params \\ %{}, opts \\ []) do
|
def register_changeset(struct, params \\ %{}, opts \\ []) do
|
||||||
confirmation_status =
|
need_confirmation? =
|
||||||
if opts[:confirmed] || !Pleroma.Config.get([:instance, :account_activation_required]) do
|
if is_nil(opts[:need_confirmation]) do
|
||||||
:confirmed
|
Pleroma.Config.get([:instance, :account_activation_required])
|
||||||
else
|
else
|
||||||
:unconfirmed
|
opts[:need_confirmation]
|
||||||
end
|
end
|
||||||
|
|
||||||
info_change = User.Info.confirmation_changeset(%User.Info{}, confirmation_status)
|
info_change =
|
||||||
|
User.Info.confirmation_changeset(%User.Info{}, need_confirmation: need_confirmation?)
|
||||||
|
|
||||||
changeset =
|
changeset =
|
||||||
struct
|
struct
|
||||||
|
@ -256,10 +255,7 @@ defp autofollow_users(user) do
|
||||||
candidates = Pleroma.Config.get([:instance, :autofollowed_nicknames])
|
candidates = Pleroma.Config.get([:instance, :autofollowed_nicknames])
|
||||||
|
|
||||||
autofollowed_users =
|
autofollowed_users =
|
||||||
from(u in User,
|
User.Query.build(%{nickname: candidates, local: true})
|
||||||
where: u.local == true,
|
|
||||||
where: u.nickname in ^candidates
|
|
||||||
)
|
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|
|
||||||
follow_all(user, autofollowed_users)
|
follow_all(user, autofollowed_users)
|
||||||
|
@ -422,7 +418,7 @@ def follow_import(%User{} = follower, followed_identifiers)
|
||||||
Enum.map(
|
Enum.map(
|
||||||
followed_identifiers,
|
followed_identifiers,
|
||||||
fn followed_identifier ->
|
fn followed_identifier ->
|
||||||
with %User{} = followed <- get_or_fetch(followed_identifier),
|
with {:ok, %User{} = followed} <- get_or_fetch(followed_identifier),
|
||||||
{:ok, follower} <- maybe_direct_follow(follower, followed),
|
{:ok, follower} <- maybe_direct_follow(follower, followed),
|
||||||
{:ok, _} <- ActivityPub.follow(follower, followed) do
|
{:ok, _} <- ActivityPub.follow(follower, followed) do
|
||||||
followed
|
followed
|
||||||
|
@ -506,7 +502,15 @@ def get_cached_by_id(id) do
|
||||||
|
|
||||||
def get_cached_by_nickname(nickname) do
|
def get_cached_by_nickname(nickname) do
|
||||||
key = "nickname:#{nickname}"
|
key = "nickname:#{nickname}"
|
||||||
Cachex.fetch!(:user_cache, key, fn _ -> get_or_fetch_by_nickname(nickname) end)
|
|
||||||
|
Cachex.fetch!(:user_cache, key, fn ->
|
||||||
|
user_result = get_or_fetch_by_nickname(nickname)
|
||||||
|
|
||||||
|
case user_result do
|
||||||
|
{:ok, user} -> {:commit, user}
|
||||||
|
{:error, _error} -> {:ignore, nil}
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_cached_by_nickname_or_id(nickname_or_id) do
|
def get_cached_by_nickname_or_id(nickname_or_id) do
|
||||||
|
@ -542,7 +546,7 @@ def fetch_by_nickname(nickname) do
|
||||||
|
|
||||||
def get_or_fetch_by_nickname(nickname) do
|
def get_or_fetch_by_nickname(nickname) do
|
||||||
with %User{} = user <- get_by_nickname(nickname) do
|
with %User{} = user <- get_by_nickname(nickname) do
|
||||||
user
|
{:ok, user}
|
||||||
else
|
else
|
||||||
_e ->
|
_e ->
|
||||||
with [_nick, _domain] <- String.split(nickname, "@"),
|
with [_nick, _domain] <- String.split(nickname, "@"),
|
||||||
|
@ -552,9 +556,9 @@ def get_or_fetch_by_nickname(nickname) do
|
||||||
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
|
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
|
||||||
end
|
end
|
||||||
|
|
||||||
user
|
{:ok, user}
|
||||||
else
|
else
|
||||||
_e -> nil
|
_e -> {:error, "not found " <> nickname}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -570,19 +574,17 @@ def fetch_initial_posts(user) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_followers_query(%User{id: id, follower_address: follower_address}, nil) do
|
@spec get_followers_query(User.t(), pos_integer() | nil) :: Ecto.Query.t()
|
||||||
from(
|
def get_followers_query(%User{} = user, nil) do
|
||||||
u in User,
|
User.Query.build(%{followers: user})
|
||||||
where: fragment("? <@ ?", ^[follower_address], u.following),
|
|
||||||
where: u.id != ^id
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_followers_query(user, page) do
|
def get_followers_query(user, page) do
|
||||||
from(u in get_followers_query(user, nil))
|
from(u in get_followers_query(user, nil))
|
||||||
|> paginate(page, 20)
|
|> User.Query.paginate(page, 20)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec get_followers_query(User.t()) :: Ecto.Query.t()
|
||||||
def get_followers_query(user), do: get_followers_query(user, nil)
|
def get_followers_query(user), do: get_followers_query(user, nil)
|
||||||
|
|
||||||
def get_followers(user, page \\ nil) do
|
def get_followers(user, page \\ nil) do
|
||||||
|
@ -597,19 +599,17 @@ def get_followers_ids(user, page \\ nil) do
|
||||||
Repo.all(from(u in q, select: u.id))
|
Repo.all(from(u in q, select: u.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_friends_query(%User{id: id, following: following}, nil) do
|
@spec get_friends_query(User.t(), pos_integer() | nil) :: Ecto.Query.t()
|
||||||
from(
|
def get_friends_query(%User{} = user, nil) do
|
||||||
u in User,
|
User.Query.build(%{friends: user})
|
||||||
where: u.follower_address in ^following,
|
|
||||||
where: u.id != ^id
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_friends_query(user, page) do
|
def get_friends_query(user, page) do
|
||||||
from(u in get_friends_query(user, nil))
|
from(u in get_friends_query(user, nil))
|
||||||
|> paginate(page, 20)
|
|> User.Query.paginate(page, 20)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec get_friends_query(User.t()) :: Ecto.Query.t()
|
||||||
def get_friends_query(user), do: get_friends_query(user, nil)
|
def get_friends_query(user), do: get_friends_query(user, nil)
|
||||||
|
|
||||||
def get_friends(user, page \\ nil) do
|
def get_friends(user, page \\ nil) do
|
||||||
|
@ -624,33 +624,10 @@ def get_friends_ids(user, page \\ nil) do
|
||||||
Repo.all(from(u in q, select: u.id))
|
Repo.all(from(u in q, select: u.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_follow_requests_query(%User{} = user) do
|
@spec get_follow_requests(User.t()) :: {:ok, [User.t()]}
|
||||||
from(
|
|
||||||
a in Activity,
|
|
||||||
where:
|
|
||||||
fragment(
|
|
||||||
"? ->> 'type' = 'Follow'",
|
|
||||||
a.data
|
|
||||||
),
|
|
||||||
where:
|
|
||||||
fragment(
|
|
||||||
"? ->> 'state' = 'pending'",
|
|
||||||
a.data
|
|
||||||
),
|
|
||||||
where:
|
|
||||||
fragment(
|
|
||||||
"coalesce((?)->'object'->>'id', (?)->>'object') = ?",
|
|
||||||
a.data,
|
|
||||||
a.data,
|
|
||||||
^user.ap_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_follow_requests(%User{} = user) do
|
def get_follow_requests(%User{} = user) do
|
||||||
users =
|
users =
|
||||||
user
|
Activity.follow_requests_for_actor(user)
|
||||||
|> User.get_follow_requests_query()
|
|
||||||
|> join(:inner, [a], u in User, on: a.actor == u.ap_id)
|
|> join(:inner, [a], u in User, on: a.actor == u.ap_id)
|
||||||
|> where([a, u], not fragment("? @> ?", u.following, ^[user.follower_address]))
|
|> where([a, u], not fragment("? @> ?", u.following, ^[user.follower_address]))
|
||||||
|> group_by([a, u], u.id)
|
|> group_by([a, u], u.id)
|
||||||
|
@ -723,10 +700,7 @@ def update_note_count(%User{} = user) do
|
||||||
|
|
||||||
def update_follower_count(%User{} = user) do
|
def update_follower_count(%User{} = user) do
|
||||||
follower_count_query =
|
follower_count_query =
|
||||||
User
|
User.Query.build(%{followers: user}) |> select([u], %{count: count(u.id)})
|
||||||
|> where([u], ^user.follower_address in u.following)
|
|
||||||
|> where([u], u.id != ^user.id)
|
|
||||||
|> select([u], %{count: count(u.id)})
|
|
||||||
|
|
||||||
User
|
User
|
||||||
|> where(id: ^user.id)
|
|> where(id: ^user.id)
|
||||||
|
@ -749,38 +723,19 @@ def update_follower_count(%User{} = user) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_users_from_set_query(ap_ids, false) do
|
@spec get_users_from_set([String.t()], boolean()) :: [User.t()]
|
||||||
from(
|
|
||||||
u in User,
|
|
||||||
where: u.ap_id in ^ap_ids
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_users_from_set_query(ap_ids, true) do
|
|
||||||
query = get_users_from_set_query(ap_ids, false)
|
|
||||||
|
|
||||||
from(
|
|
||||||
u in query,
|
|
||||||
where: u.local == true
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_users_from_set(ap_ids, local_only \\ true) do
|
def get_users_from_set(ap_ids, local_only \\ true) do
|
||||||
get_users_from_set_query(ap_ids, local_only)
|
criteria = %{ap_id: ap_ids}
|
||||||
|
criteria = if local_only, do: Map.put(criteria, :local, true), else: criteria
|
||||||
|
|
||||||
|
User.Query.build(criteria)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec get_recipients_from_activity(Activity.t()) :: [User.t()]
|
||||||
def get_recipients_from_activity(%Activity{recipients: to}) do
|
def get_recipients_from_activity(%Activity{recipients: to}) do
|
||||||
query =
|
User.Query.build(%{recipients_from_activity: to, local: true})
|
||||||
from(
|
|> Repo.all()
|
||||||
u in User,
|
|
||||||
where: u.ap_id in ^to,
|
|
||||||
or_where: fragment("? && ?", u.following, ^to)
|
|
||||||
)
|
|
||||||
|
|
||||||
query = from(u in query, where: u.local == true)
|
|
||||||
|
|
||||||
Repo.all(query)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def search(query, resolve \\ false, for_user \\ nil) do
|
def search(query, resolve \\ false, for_user \\ nil) do
|
||||||
|
@ -901,7 +856,7 @@ def blocks_import(%User{} = blocker, blocked_identifiers) when is_list(blocked_i
|
||||||
Enum.map(
|
Enum.map(
|
||||||
blocked_identifiers,
|
blocked_identifiers,
|
||||||
fn blocked_identifier ->
|
fn blocked_identifier ->
|
||||||
with %User{} = blocked <- get_or_fetch(blocked_identifier),
|
with {:ok, %User{} = blocked} <- get_or_fetch(blocked_identifier),
|
||||||
{:ok, blocker} <- block(blocker, blocked),
|
{:ok, blocker} <- block(blocker, blocked),
|
||||||
{:ok, _} <- ActivityPub.block(blocker, blocked) do
|
{:ok, _} <- ActivityPub.block(blocker, blocked) do
|
||||||
blocked
|
blocked
|
||||||
|
@ -1042,14 +997,23 @@ def subscribed_to?(user, %{ap_id: ap_id}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def muted_users(user),
|
@spec muted_users(User.t()) :: [User.t()]
|
||||||
do: Repo.all(from(u in User, where: u.ap_id in ^user.info.mutes))
|
def muted_users(user) do
|
||||||
|
User.Query.build(%{ap_id: user.info.mutes})
|
||||||
|
|> Repo.all()
|
||||||
|
end
|
||||||
|
|
||||||
def blocked_users(user),
|
@spec blocked_users(User.t()) :: [User.t()]
|
||||||
do: Repo.all(from(u in User, where: u.ap_id in ^user.info.blocks))
|
def blocked_users(user) do
|
||||||
|
User.Query.build(%{ap_id: user.info.blocks})
|
||||||
|
|> Repo.all()
|
||||||
|
end
|
||||||
|
|
||||||
def subscribers(user),
|
@spec subscribers(User.t()) :: [User.t()]
|
||||||
do: Repo.all(from(u in User, where: u.ap_id in ^user.info.subscribers))
|
def subscribers(user) do
|
||||||
|
User.Query.build(%{ap_id: user.info.subscribers})
|
||||||
|
|> Repo.all()
|
||||||
|
end
|
||||||
|
|
||||||
def block_domain(user, domain) do
|
def block_domain(user, domain) do
|
||||||
info_cng =
|
info_cng =
|
||||||
|
@ -1075,69 +1039,6 @@ def unblock_domain(user, domain) do
|
||||||
update_and_set_cache(cng)
|
update_and_set_cache(cng)
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_local_user_query(query, local) do
|
|
||||||
if local, do: local_user_query(query), else: query
|
|
||||||
end
|
|
||||||
|
|
||||||
def local_user_query(query \\ User) do
|
|
||||||
from(
|
|
||||||
u in query,
|
|
||||||
where: u.local == true,
|
|
||||||
where: not is_nil(u.nickname)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def maybe_external_user_query(query, external) do
|
|
||||||
if external, do: external_user_query(query), else: query
|
|
||||||
end
|
|
||||||
|
|
||||||
def external_user_query(query \\ User) do
|
|
||||||
from(
|
|
||||||
u in query,
|
|
||||||
where: u.local == false,
|
|
||||||
where: not is_nil(u.nickname)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def maybe_active_user_query(query, active) do
|
|
||||||
if active, do: active_user_query(query), else: query
|
|
||||||
end
|
|
||||||
|
|
||||||
def active_user_query(query \\ User) do
|
|
||||||
from(
|
|
||||||
u in query,
|
|
||||||
where: fragment("not (?->'deactivated' @> 'true')", u.info),
|
|
||||||
where: not is_nil(u.nickname)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def maybe_deactivated_user_query(query, deactivated) do
|
|
||||||
if deactivated, do: deactivated_user_query(query), else: query
|
|
||||||
end
|
|
||||||
|
|
||||||
def deactivated_user_query(query \\ User) do
|
|
||||||
from(
|
|
||||||
u in query,
|
|
||||||
where: fragment("(?->'deactivated' @> 'true')", u.info),
|
|
||||||
where: not is_nil(u.nickname)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def active_local_user_query do
|
|
||||||
from(
|
|
||||||
u in local_user_query(),
|
|
||||||
where: fragment("not (?->'deactivated' @> 'true')", u.info)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def moderator_user_query do
|
|
||||||
from(
|
|
||||||
u in User,
|
|
||||||
where: u.local == true,
|
|
||||||
where: fragment("?->'is_moderator' @> 'true'", u.info)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def deactivate(%User{} = user, status \\ true) do
|
def deactivate(%User{} = user, status \\ true) do
|
||||||
info_cng = User.Info.set_activation_status(user.info, status)
|
info_cng = User.Info.set_activation_status(user.info, status)
|
||||||
|
|
||||||
|
@ -1156,7 +1057,12 @@ def update_notification_settings(%User{} = user, settings \\ %{}) do
|
||||||
|> update_and_set_cache()
|
|> update_and_set_cache()
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(%User{} = user) do
|
@spec delete(User.t()) :: :ok
|
||||||
|
def delete(%User{} = user),
|
||||||
|
do: PleromaJobQueue.enqueue(:background, __MODULE__, [:delete, user])
|
||||||
|
|
||||||
|
@spec perform(atom(), User.t()) :: {:ok, User.t()}
|
||||||
|
def perform(:delete, %User{} = user) do
|
||||||
{:ok, user} = User.deactivate(user)
|
{:ok, user} = User.deactivate(user)
|
||||||
|
|
||||||
# Remove all relationships
|
# Remove all relationships
|
||||||
|
@ -1172,22 +1078,23 @@ def delete(%User{} = user) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_user_activities(%User{ap_id: ap_id} = user) do
|
def delete_user_activities(%User{ap_id: ap_id} = user) do
|
||||||
Activity
|
stream =
|
||||||
|> where(actor: ^ap_id)
|
ap_id
|
||||||
|
|> Activity.query_by_actor()
|
||||||
|> Activity.with_preloaded_object()
|
|> Activity.with_preloaded_object()
|
||||||
|> Repo.all()
|
|> Repo.stream()
|
||||||
|> Enum.each(fn
|
|
||||||
%{data: %{"type" => "Create"}} = activity ->
|
|
||||||
activity |> Object.normalize() |> ActivityPub.delete()
|
|
||||||
|
|
||||||
# TODO: Do something with likes, follows, repeats.
|
Repo.transaction(fn -> Enum.each(stream, &delete_activity(&1)) end, timeout: :infinity)
|
||||||
_ ->
|
|
||||||
"Doing nothing"
|
|
||||||
end)
|
|
||||||
|
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp delete_activity(%{data: %{"type" => "Create"}} = activity) do
|
||||||
|
Object.normalize(activity) |> ActivityPub.delete()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp delete_activity(_activity), do: "Doing nothing"
|
||||||
|
|
||||||
def html_filter_policy(%User{info: %{no_rich_text: true}}) do
|
def html_filter_policy(%User{info: %{no_rich_text: true}}) do
|
||||||
Pleroma.HTML.Scrubber.TwitterText
|
Pleroma.HTML.Scrubber.TwitterText
|
||||||
end
|
end
|
||||||
|
@ -1201,11 +1108,11 @@ def fetch_by_ap_id(ap_id) do
|
||||||
|
|
||||||
case ap_try do
|
case ap_try do
|
||||||
{:ok, user} ->
|
{:ok, user} ->
|
||||||
user
|
{:ok, user}
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
case OStatus.make_user(ap_id) do
|
case OStatus.make_user(ap_id) do
|
||||||
{:ok, user} -> user
|
{:ok, user} -> {:ok, user}
|
||||||
_ -> {:error, "Could not fetch by AP id"}
|
_ -> {:error, "Could not fetch by AP id"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1215,20 +1122,20 @@ def get_or_fetch_by_ap_id(ap_id) do
|
||||||
user = get_cached_by_ap_id(ap_id)
|
user = get_cached_by_ap_id(ap_id)
|
||||||
|
|
||||||
if !is_nil(user) and !User.needs_update?(user) do
|
if !is_nil(user) and !User.needs_update?(user) do
|
||||||
user
|
{:ok, user}
|
||||||
else
|
else
|
||||||
# Whether to fetch initial posts for the user (if it's a new user & the fetching is enabled)
|
# Whether to fetch initial posts for the user (if it's a new user & the fetching is enabled)
|
||||||
should_fetch_initial = is_nil(user) and Pleroma.Config.get([:fetch_initial_posts, :enabled])
|
should_fetch_initial = is_nil(user) and Pleroma.Config.get([:fetch_initial_posts, :enabled])
|
||||||
|
|
||||||
user = fetch_by_ap_id(ap_id)
|
resp = fetch_by_ap_id(ap_id)
|
||||||
|
|
||||||
if should_fetch_initial do
|
if should_fetch_initial do
|
||||||
with %User{} = user do
|
with {:ok, %User{} = user} = resp do
|
||||||
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
|
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
user
|
resp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1270,7 +1177,7 @@ def public_key_from_info(%{magic_key: magic_key}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_public_key_for_ap_id(ap_id) do
|
def get_public_key_for_ap_id(ap_id) do
|
||||||
with %User{} = user <- get_or_fetch_by_ap_id(ap_id),
|
with {:ok, %User{} = user} <- get_or_fetch_by_ap_id(ap_id),
|
||||||
{:ok, public_key} <- public_key_from_info(user.info) do
|
{:ok, public_key} <- public_key_from_info(user.info) do
|
||||||
{:ok, public_key}
|
{:ok, public_key}
|
||||||
else
|
else
|
||||||
|
@ -1294,7 +1201,7 @@ def ap_enabled?(%User{info: info}), do: info.ap_enabled
|
||||||
def ap_enabled?(_), do: false
|
def ap_enabled?(_), do: false
|
||||||
|
|
||||||
@doc "Gets or fetch a user by uri or nickname."
|
@doc "Gets or fetch a user by uri or nickname."
|
||||||
@spec get_or_fetch(String.t()) :: User.t()
|
@spec get_or_fetch(String.t()) :: {:ok, User.t()} | {:error, String.t()}
|
||||||
def get_or_fetch("http" <> _host = uri), do: get_or_fetch_by_ap_id(uri)
|
def get_or_fetch("http" <> _host = uri), do: get_or_fetch_by_ap_id(uri)
|
||||||
def get_or_fetch(nickname), do: get_or_fetch_by_nickname(nickname)
|
def get_or_fetch(nickname), do: get_or_fetch_by_nickname(nickname)
|
||||||
|
|
||||||
|
@ -1322,18 +1229,15 @@ def wait_and_refresh(timeout, %User{} = a, %User{} = b) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_bio(bio, user \\ %User{info: %{source_data: %{}}})
|
def parse_bio(bio) when is_binary(bio) and bio != "" do
|
||||||
def parse_bio(nil, _user), do: ""
|
bio
|
||||||
def parse_bio(bio, _user) when bio == "", do: bio
|
|> CommonUtils.format_input("text/plain", mentions_format: :full)
|
||||||
|
|> elem(0)
|
||||||
|
end
|
||||||
|
|
||||||
def parse_bio(bio, user) do
|
def parse_bio(_), do: ""
|
||||||
emoji =
|
|
||||||
(user.info.source_data["tag"] || [])
|
|
||||||
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
|
|
||||||
|> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
|
|
||||||
{String.trim(name, ":"), url}
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
def parse_bio(bio, user) when is_binary(bio) and bio != "" do
|
||||||
# TODO: get profile URLs other than user.ap_id
|
# TODO: get profile URLs other than user.ap_id
|
||||||
profile_urls = [user.ap_id]
|
profile_urls = [user.ap_id]
|
||||||
|
|
||||||
|
@ -1343,9 +1247,10 @@ def parse_bio(bio, user) do
|
||||||
rel: &RelMe.maybe_put_rel_me(&1, profile_urls)
|
rel: &RelMe.maybe_put_rel_me(&1, profile_urls)
|
||||||
)
|
)
|
||||||
|> elem(0)
|
|> elem(0)
|
||||||
|> Formatter.emojify(emoji)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parse_bio(_, _), do: ""
|
||||||
|
|
||||||
def tag(user_identifiers, tags) when is_list(user_identifiers) do
|
def tag(user_identifiers, tags) when is_list(user_identifiers) do
|
||||||
Repo.transaction(fn ->
|
Repo.transaction(fn ->
|
||||||
for user_identifier <- user_identifiers, do: tag(user_identifier, tags)
|
for user_identifier <- user_identifiers, do: tag(user_identifier, tags)
|
||||||
|
@ -1379,22 +1284,6 @@ defp update_tags(%User{} = user, new_tags) do
|
||||||
updated_user
|
updated_user
|
||||||
end
|
end
|
||||||
|
|
||||||
def bookmark(%User{} = user, status_id) do
|
|
||||||
bookmarks = Enum.uniq(user.bookmarks ++ [status_id])
|
|
||||||
update_bookmarks(user, bookmarks)
|
|
||||||
end
|
|
||||||
|
|
||||||
def unbookmark(%User{} = user, status_id) do
|
|
||||||
bookmarks = Enum.uniq(user.bookmarks -- [status_id])
|
|
||||||
update_bookmarks(user, bookmarks)
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_bookmarks(%User{} = user, bookmarks) do
|
|
||||||
user
|
|
||||||
|> change(%{bookmarks: bookmarks})
|
|
||||||
|> update_and_set_cache
|
|
||||||
end
|
|
||||||
|
|
||||||
defp normalize_tags(tags) do
|
defp normalize_tags(tags) do
|
||||||
[tags]
|
[tags]
|
||||||
|> List.flatten()
|
|> List.flatten()
|
||||||
|
@ -1429,22 +1318,12 @@ def error_user(ap_id) do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec all_superusers() :: [User.t()]
|
||||||
def all_superusers do
|
def all_superusers do
|
||||||
from(
|
User.Query.build(%{super_users: true, local: true})
|
||||||
u in User,
|
|
||||||
where: u.local == true,
|
|
||||||
where: fragment("?->'is_admin' @> 'true' OR ?->'is_moderator' @> 'true'", u.info, u.info)
|
|
||||||
)
|
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp paginate(query, page, page_size) do
|
|
||||||
from(u in query,
|
|
||||||
limit: ^page_size,
|
|
||||||
offset: ^((page - 1) * page_size)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def showing_reblogs?(%User{} = user, %User{} = target) do
|
def showing_reblogs?(%User{} = user, %User{} = target) do
|
||||||
target.ap_id not in user.info.muted_reblogs
|
target.ap_id not in user.info.muted_reblogs
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,8 @@ defmodule Pleroma.User.Info do
|
||||||
|
|
||||||
alias Pleroma.User.Info
|
alias Pleroma.User.Info
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
embedded_schema do
|
embedded_schema do
|
||||||
field(:banner, :map, default: %{})
|
field(:banner, :map, default: %{})
|
||||||
field(:background, :map, default: %{})
|
field(:background, :map, default: %{})
|
||||||
|
@ -41,6 +43,7 @@ defmodule Pleroma.User.Info do
|
||||||
field(:hide_favorites, :boolean, default: true)
|
field(:hide_favorites, :boolean, default: true)
|
||||||
field(:pinned_activities, {:array, :string}, default: [])
|
field(:pinned_activities, {:array, :string}, default: [])
|
||||||
field(:flavour, :string, default: nil)
|
field(:flavour, :string, default: nil)
|
||||||
|
field(:emoji, {:array, :map}, default: [])
|
||||||
|
|
||||||
field(:notification_settings, :map,
|
field(:notification_settings, :map,
|
||||||
default: %{"remote" => true, "local" => true, "followers" => true, "follows" => true}
|
default: %{"remote" => true, "local" => true, "followers" => true, "follows" => true}
|
||||||
|
@ -209,32 +212,26 @@ def profile_update(info, params) do
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
def confirmation_changeset(info, :confirmed) do
|
@spec confirmation_changeset(Info.t(), keyword()) :: Ecto.Changerset.t()
|
||||||
confirmation_changeset(info, %{
|
def confirmation_changeset(info, opts) do
|
||||||
confirmation_pending: false,
|
need_confirmation? = Keyword.get(opts, :need_confirmation)
|
||||||
confirmation_token: nil
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
def confirmation_changeset(info, :unconfirmed) do
|
params =
|
||||||
confirmation_changeset(info, %{
|
if need_confirmation? do
|
||||||
|
%{
|
||||||
confirmation_pending: true,
|
confirmation_pending: true,
|
||||||
confirmation_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64()
|
confirmation_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64()
|
||||||
})
|
}
|
||||||
|
else
|
||||||
|
%{
|
||||||
|
confirmation_pending: false,
|
||||||
|
confirmation_token: nil
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def confirmation_changeset(info, params) do
|
|
||||||
cast(info, params, [:confirmation_pending, :confirmation_token])
|
cast(info, params, [:confirmation_pending, :confirmation_token])
|
||||||
end
|
end
|
||||||
|
|
||||||
def mastodon_profile_update(info, params) do
|
|
||||||
info
|
|
||||||
|> cast(params, [
|
|
||||||
:locked,
|
|
||||||
:banner
|
|
||||||
])
|
|
||||||
end
|
|
||||||
|
|
||||||
def mastodon_settings_update(info, settings) do
|
def mastodon_settings_update(info, settings) do
|
||||||
params = %{settings: settings}
|
params = %{settings: settings}
|
||||||
|
|
||||||
|
|
150
lib/pleroma/user/query.ex
Normal file
150
lib/pleroma/user/query.ex
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.User.Query do
|
||||||
|
@moduledoc """
|
||||||
|
User query builder module. Builds query from new query or another user query.
|
||||||
|
|
||||||
|
## Example:
|
||||||
|
query = Pleroma.User.Query(%{nickname: "nickname"})
|
||||||
|
another_query = Pleroma.User.Query.build(query, %{email: "email@example.com"})
|
||||||
|
Pleroma.Repo.all(query)
|
||||||
|
Pleroma.Repo.all(another_query)
|
||||||
|
|
||||||
|
Adding new rules:
|
||||||
|
- *ilike criteria*
|
||||||
|
- add field to @ilike_criteria list
|
||||||
|
- pass non empty string
|
||||||
|
- e.g. Pleroma.User.Query.build(%{nickname: "nickname"})
|
||||||
|
- *equal criteria*
|
||||||
|
- add field to @equal_criteria list
|
||||||
|
- pass non empty string
|
||||||
|
- e.g. Pleroma.User.Query.build(%{email: "email@example.com"})
|
||||||
|
- *contains criteria*
|
||||||
|
- add field to @containns_criteria list
|
||||||
|
- pass values list
|
||||||
|
- e.g. Pleroma.User.Query.build(%{ap_id: ["http://ap_id1", "http://ap_id2"]})
|
||||||
|
"""
|
||||||
|
import Ecto.Query
|
||||||
|
import Pleroma.Web.AdminAPI.Search, only: [not_empty_string: 1]
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
|
@type criteria ::
|
||||||
|
%{
|
||||||
|
query: String.t(),
|
||||||
|
tags: [String.t()],
|
||||||
|
name: String.t(),
|
||||||
|
email: String.t(),
|
||||||
|
local: boolean(),
|
||||||
|
external: boolean(),
|
||||||
|
active: boolean(),
|
||||||
|
deactivated: boolean(),
|
||||||
|
is_admin: boolean(),
|
||||||
|
is_moderator: boolean(),
|
||||||
|
super_users: boolean(),
|
||||||
|
followers: User.t(),
|
||||||
|
friends: User.t(),
|
||||||
|
recipients_from_activity: [String.t()],
|
||||||
|
nickname: [String.t()],
|
||||||
|
ap_id: [String.t()]
|
||||||
|
}
|
||||||
|
| %{}
|
||||||
|
|
||||||
|
@ilike_criteria [:nickname, :name, :query]
|
||||||
|
@equal_criteria [:email]
|
||||||
|
@role_criteria [:is_admin, :is_moderator]
|
||||||
|
@contains_criteria [:ap_id, :nickname]
|
||||||
|
|
||||||
|
@spec build(criteria()) :: Query.t()
|
||||||
|
def build(query \\ base_query(), criteria) do
|
||||||
|
prepare_query(query, criteria)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec paginate(Ecto.Query.t(), pos_integer(), pos_integer()) :: Ecto.Query.t()
|
||||||
|
def paginate(query, page, page_size) do
|
||||||
|
from(u in query,
|
||||||
|
limit: ^page_size,
|
||||||
|
offset: ^((page - 1) * page_size)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp base_query do
|
||||||
|
from(u in User)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp prepare_query(query, criteria) do
|
||||||
|
Enum.reduce(criteria, query, &compose_query/2)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp compose_query({key, value}, query)
|
||||||
|
when key in @ilike_criteria and not_empty_string(value) do
|
||||||
|
# hack for :query key
|
||||||
|
key = if key == :query, do: :nickname, else: key
|
||||||
|
where(query, [u], ilike(field(u, ^key), ^"%#{value}%"))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp compose_query({key, value}, query)
|
||||||
|
when key in @equal_criteria and not_empty_string(value) do
|
||||||
|
where(query, [u], ^[{key, value}])
|
||||||
|
end
|
||||||
|
|
||||||
|
defp compose_query({key, values}, query) when key in @contains_criteria and is_list(values) do
|
||||||
|
where(query, [u], field(u, ^key) in ^values)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp compose_query({:tags, tags}, query) when is_list(tags) and length(tags) > 0 do
|
||||||
|
Enum.reduce(tags, query, &prepare_tag_criteria/2)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp compose_query({key, _}, query) when key in @role_criteria do
|
||||||
|
where(query, [u], fragment("(?->? @> 'true')", u.info, ^to_string(key)))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp compose_query({:super_users, _}, query) do
|
||||||
|
where(
|
||||||
|
query,
|
||||||
|
[u],
|
||||||
|
fragment("?->'is_admin' @> 'true' OR ?->'is_moderator' @> 'true'", u.info, u.info)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp compose_query({:local, _}, query), do: location_query(query, true)
|
||||||
|
|
||||||
|
defp compose_query({:external, _}, query), do: location_query(query, false)
|
||||||
|
|
||||||
|
defp compose_query({:active, _}, query) do
|
||||||
|
where(query, [u], fragment("not (?->'deactivated' @> 'true')", u.info))
|
||||||
|
|> where([u], not is_nil(u.nickname))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp compose_query({:deactivated, _}, query) do
|
||||||
|
where(query, [u], fragment("?->'deactivated' @> 'true'", u.info))
|
||||||
|
|> where([u], not is_nil(u.nickname))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp compose_query({:followers, %User{id: id, follower_address: follower_address}}, query) do
|
||||||
|
where(query, [u], fragment("? <@ ?", ^[follower_address], u.following))
|
||||||
|
|> where([u], u.id != ^id)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp compose_query({:friends, %User{id: id, following: following}}, query) do
|
||||||
|
where(query, [u], u.follower_address in ^following)
|
||||||
|
|> where([u], u.id != ^id)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp compose_query({:recipients_from_activity, to}, query) do
|
||||||
|
where(query, [u], u.ap_id in ^to or fragment("? && ?", u.following, ^to))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp compose_query(_unsupported_param, query), do: query
|
||||||
|
|
||||||
|
defp prepare_tag_criteria(tag, query) do
|
||||||
|
or_where(query, [u], fragment("? = any(?)", ^tag, u.tags))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp location_query(query, local) do
|
||||||
|
where(query, [u], u.local == ^local)
|
||||||
|
|> where([u], not is_nil(u.nickname))
|
||||||
|
end
|
||||||
|
end
|
|
@ -24,7 +24,7 @@ defmodule Pleroma.UserInviteToken do
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec create_invite(map()) :: UserInviteToken.t()
|
@spec create_invite(map()) :: {:ok, UserInviteToken.t()}
|
||||||
def create_invite(params \\ %{}) do
|
def create_invite(params \\ %{}) do
|
||||||
%UserInviteToken{}
|
%UserInviteToken{}
|
||||||
|> cast(params, [:max_use, :expires_at])
|
|> cast(params, [:max_use, :expires_at])
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Instances
|
alias Pleroma.Conversation
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Object.Fetcher
|
alias Pleroma.Object.Fetcher
|
||||||
|
@ -14,7 +14,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.MRF
|
alias Pleroma.Web.ActivityPub.MRF
|
||||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
alias Pleroma.Web.Federator
|
|
||||||
alias Pleroma.Web.WebFinger
|
alias Pleroma.Web.WebFinger
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
@ -23,8 +22,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@httpoison Application.get_env(:pleroma, :httpoison)
|
|
||||||
|
|
||||||
# For Announce activities, we filter the recipients based on following status for any actors
|
# For Announce activities, we filter the recipients based on following status for any actors
|
||||||
# that match actual users. See issue #164 for more information about why this is necessary.
|
# that match actual users. See issue #164 for more information about why this is necessary.
|
||||||
defp get_recipients(%{"type" => "Announce"} = data) do
|
defp get_recipients(%{"type" => "Announce"} = data) do
|
||||||
|
@ -140,7 +137,14 @@ def insert(map, local \\ true, fake \\ false) when is_map(map) do
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Notification.create_notifications(activity)
|
Notification.create_notifications(activity)
|
||||||
|
|
||||||
|
participations =
|
||||||
|
activity
|
||||||
|
|> Conversation.create_or_bump_for()
|
||||||
|
|> get_participations()
|
||||||
|
|
||||||
stream_out(activity)
|
stream_out(activity)
|
||||||
|
stream_out_participations(participations)
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
%Activity{} = activity ->
|
%Activity{} = activity ->
|
||||||
|
@ -163,11 +167,23 @@ def insert(map, local \\ true, fake \\ false) when is_map(map) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp get_participations({:ok, %{participations: participations}}), do: participations
|
||||||
|
defp get_participations(_), do: []
|
||||||
|
|
||||||
|
def stream_out_participations(participations) do
|
||||||
|
participations =
|
||||||
|
participations
|
||||||
|
|> Repo.preload(:user)
|
||||||
|
|
||||||
|
Enum.each(participations, fn participation ->
|
||||||
|
Pleroma.Web.Streamer.stream("participation", participation)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
def stream_out(activity) do
|
def stream_out(activity) do
|
||||||
public = "https://www.w3.org/ns/activitystreams#Public"
|
public = "https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
|
||||||
if activity.data["type"] in ["Create", "Announce", "Delete"] do
|
if activity.data["type"] in ["Create", "Announce", "Delete"] do
|
||||||
object = Object.normalize(activity)
|
|
||||||
Pleroma.Web.Streamer.stream("user", activity)
|
Pleroma.Web.Streamer.stream("user", activity)
|
||||||
Pleroma.Web.Streamer.stream("list", activity)
|
Pleroma.Web.Streamer.stream("list", activity)
|
||||||
|
|
||||||
|
@ -179,6 +195,8 @@ def stream_out(activity) do
|
||||||
end
|
end
|
||||||
|
|
||||||
if activity.data["type"] in ["Create"] do
|
if activity.data["type"] in ["Create"] do
|
||||||
|
object = Object.normalize(activity)
|
||||||
|
|
||||||
object.data
|
object.data
|
||||||
|> Map.get("tag", [])
|
|> Map.get("tag", [])
|
||||||
|> Enum.filter(fn tag -> is_bitstring(tag) end)
|
|> Enum.filter(fn tag -> is_bitstring(tag) end)
|
||||||
|
@ -193,6 +211,7 @@ def stream_out(activity) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
# TODO: Write test, replace with visibility test
|
||||||
if !Enum.member?(activity.data["cc"] || [], public) &&
|
if !Enum.member?(activity.data["cc"] || [], public) &&
|
||||||
!Enum.member?(
|
!Enum.member?(
|
||||||
activity.data["to"],
|
activity.data["to"],
|
||||||
|
@ -455,35 +474,44 @@ def flag(
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_activities_for_context(context, opts \\ %{}) do
|
defp fetch_activities_for_context_query(context, opts) do
|
||||||
public = ["https://www.w3.org/ns/activitystreams#Public"]
|
public = ["https://www.w3.org/ns/activitystreams#Public"]
|
||||||
|
|
||||||
recipients =
|
recipients =
|
||||||
if opts["user"], do: [opts["user"].ap_id | opts["user"].following] ++ public, else: public
|
if opts["user"], do: [opts["user"].ap_id | opts["user"].following] ++ public, else: public
|
||||||
|
|
||||||
query = from(activity in Activity)
|
from(activity in Activity)
|
||||||
|
|
||||||
query =
|
|
||||||
query
|
|
||||||
|> restrict_blocked(opts)
|
|> restrict_blocked(opts)
|
||||||
|> restrict_recipients(recipients, opts["user"])
|
|> restrict_recipients(recipients, opts["user"])
|
||||||
|
|> where(
|
||||||
query =
|
[activity],
|
||||||
from(
|
|
||||||
activity in query,
|
|
||||||
where:
|
|
||||||
fragment(
|
fragment(
|
||||||
"?->>'type' = ? and ?->>'context' = ?",
|
"?->>'type' = ? and ?->>'context' = ?",
|
||||||
activity.data,
|
activity.data,
|
||||||
"Create",
|
"Create",
|
||||||
activity.data,
|
activity.data,
|
||||||
^context
|
^context
|
||||||
),
|
|
||||||
order_by: [desc: :id]
|
|
||||||
)
|
)
|
||||||
|> Activity.with_preloaded_object()
|
)
|
||||||
|
|> order_by([activity], desc: activity.id)
|
||||||
|
end
|
||||||
|
|
||||||
Repo.all(query)
|
@spec fetch_activities_for_context(String.t(), keyword() | map()) :: [Activity.t()]
|
||||||
|
def fetch_activities_for_context(context, opts \\ %{}) do
|
||||||
|
context
|
||||||
|
|> fetch_activities_for_context_query(opts)
|
||||||
|
|> Activity.with_preloaded_object()
|
||||||
|
|> Repo.all()
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec fetch_latest_activity_id_for_context(String.t(), keyword() | map()) ::
|
||||||
|
Pleroma.FlakeId.t() | nil
|
||||||
|
def fetch_latest_activity_id_for_context(context, opts \\ %{}) do
|
||||||
|
context
|
||||||
|
|> fetch_activities_for_context_query(opts)
|
||||||
|
|> limit(1)
|
||||||
|
|> select([a], a.id)
|
||||||
|
|> Repo.one()
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_public_activities(opts \\ %{}) do
|
def fetch_public_activities(opts \\ %{}) do
|
||||||
|
@ -782,9 +810,30 @@ defp maybe_preload_objects(query, _) do
|
||||||
|> Activity.with_preloaded_object()
|
|> Activity.with_preloaded_object()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp maybe_preload_bookmarks(query, %{"skip_preload" => true}), do: query
|
||||||
|
|
||||||
|
defp maybe_preload_bookmarks(query, opts) do
|
||||||
|
query
|
||||||
|
|> Activity.with_preloaded_bookmark(opts["user"])
|
||||||
|
end
|
||||||
|
|
||||||
|
defp maybe_order(query, %{order: :desc}) do
|
||||||
|
query
|
||||||
|
|> order_by(desc: :id)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp maybe_order(query, %{order: :asc}) do
|
||||||
|
query
|
||||||
|
|> order_by(asc: :id)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp maybe_order(query, _), do: query
|
||||||
|
|
||||||
def fetch_activities_query(recipients, opts \\ %{}) do
|
def fetch_activities_query(recipients, opts \\ %{}) do
|
||||||
Activity
|
Activity
|
||||||
|> maybe_preload_objects(opts)
|
|> maybe_preload_objects(opts)
|
||||||
|
|> maybe_preload_bookmarks(opts)
|
||||||
|
|> maybe_order(opts)
|
||||||
|> restrict_recipients(recipients, opts["user"])
|
|> restrict_recipients(recipients, opts["user"])
|
||||||
|> restrict_tag(opts)
|
|> restrict_tag(opts)
|
||||||
|> restrict_tag_reject(opts)
|
|> restrict_tag_reject(opts)
|
||||||
|
@ -925,134 +974,6 @@ def make_user_from_nickname(nickname) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_federate?(inbox, public) do
|
|
||||||
if public do
|
|
||||||
true
|
|
||||||
else
|
|
||||||
inbox_info = URI.parse(inbox)
|
|
||||||
!Enum.member?(Pleroma.Config.get([:instance, :quarantined_instances], []), inbox_info.host)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp recipients(actor, activity) do
|
|
||||||
followers =
|
|
||||||
if actor.follower_address in activity.recipients do
|
|
||||||
{:ok, followers} = User.get_followers(actor)
|
|
||||||
Enum.filter(followers, &(!&1.local))
|
|
||||||
else
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
|
|
||||||
Pleroma.Web.Salmon.remote_users(actor, activity) ++ followers
|
|
||||||
end
|
|
||||||
|
|
||||||
defp get_cc_ap_ids(ap_id, recipients) do
|
|
||||||
host = Map.get(URI.parse(ap_id), :host)
|
|
||||||
|
|
||||||
recipients
|
|
||||||
|> Enum.filter(fn %User{ap_id: ap_id} -> Map.get(URI.parse(ap_id), :host) == host end)
|
|
||||||
|> Enum.map(& &1.ap_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def publish(actor, %{data: %{"bcc" => bcc}} = activity) when is_list(bcc) and bcc != [] do
|
|
||||||
public = is_public?(activity)
|
|
||||||
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
|
||||||
|
|
||||||
recipients = recipients(actor, activity)
|
|
||||||
|
|
||||||
recipients
|
|
||||||
|> Enum.filter(&User.ap_enabled?/1)
|
|
||||||
|> Enum.map(fn %{info: %{source_data: data}} -> data["inbox"] end)
|
|
||||||
|> Enum.filter(fn inbox -> should_federate?(inbox, public) end)
|
|
||||||
|> Instances.filter_reachable()
|
|
||||||
|> Enum.each(fn {inbox, unreachable_since} ->
|
|
||||||
%User{ap_id: ap_id} =
|
|
||||||
Enum.find(recipients, fn %{info: %{source_data: data}} -> data["inbox"] == inbox end)
|
|
||||||
|
|
||||||
cc = get_cc_ap_ids(ap_id, recipients)
|
|
||||||
|
|
||||||
json =
|
|
||||||
data
|
|
||||||
|> Map.put("cc", cc)
|
|
||||||
|> Map.put("directMessage", true)
|
|
||||||
|> Jason.encode!()
|
|
||||||
|
|
||||||
Federator.publish_single_ap(%{
|
|
||||||
inbox: inbox,
|
|
||||||
json: json,
|
|
||||||
actor: actor,
|
|
||||||
id: activity.data["id"],
|
|
||||||
unreachable_since: unreachable_since
|
|
||||||
})
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def publish(actor, activity) do
|
|
||||||
public = is_public?(activity)
|
|
||||||
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
|
||||||
|
|
||||||
json = Jason.encode!(data)
|
|
||||||
|
|
||||||
recipients(actor, activity)
|
|
||||||
|> Enum.filter(&User.ap_enabled?/1)
|
|
||||||
|> Enum.map(fn %{info: %{source_data: data}} ->
|
|
||||||
(is_map(data["endpoints"]) && Map.get(data["endpoints"], "sharedInbox")) || data["inbox"]
|
|
||||||
end)
|
|
||||||
|> Enum.uniq()
|
|
||||||
|> Enum.filter(fn inbox -> should_federate?(inbox, public) end)
|
|
||||||
|> Instances.filter_reachable()
|
|
||||||
|> Enum.each(fn {inbox, unreachable_since} ->
|
|
||||||
Federator.publish_single_ap(%{
|
|
||||||
inbox: inbox,
|
|
||||||
json: json,
|
|
||||||
actor: actor,
|
|
||||||
id: activity.data["id"],
|
|
||||||
unreachable_since: unreachable_since
|
|
||||||
})
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def publish_one(%{inbox: inbox, json: json, actor: actor, id: id} = params) do
|
|
||||||
Logger.info("Federating #{id} to #{inbox}")
|
|
||||||
host = URI.parse(inbox).host
|
|
||||||
|
|
||||||
digest = "SHA-256=" <> (:crypto.hash(:sha256, json) |> Base.encode64())
|
|
||||||
|
|
||||||
date =
|
|
||||||
NaiveDateTime.utc_now()
|
|
||||||
|> Timex.format!("{WDshort}, {0D} {Mshort} {YYYY} {h24}:{m}:{s} GMT")
|
|
||||||
|
|
||||||
signature =
|
|
||||||
Pleroma.Web.HTTPSignatures.sign(actor, %{
|
|
||||||
host: host,
|
|
||||||
"content-length": byte_size(json),
|
|
||||||
digest: digest,
|
|
||||||
date: date
|
|
||||||
})
|
|
||||||
|
|
||||||
with {:ok, %{status: code}} when code in 200..299 <-
|
|
||||||
result =
|
|
||||||
@httpoison.post(
|
|
||||||
inbox,
|
|
||||||
json,
|
|
||||||
[
|
|
||||||
{"Content-Type", "application/activity+json"},
|
|
||||||
{"Date", date},
|
|
||||||
{"signature", signature},
|
|
||||||
{"digest", digest}
|
|
||||||
]
|
|
||||||
) do
|
|
||||||
if !Map.has_key?(params, :unreachable_since) || params[:unreachable_since],
|
|
||||||
do: Instances.set_reachable(inbox)
|
|
||||||
|
|
||||||
result
|
|
||||||
else
|
|
||||||
{_post_result, response} ->
|
|
||||||
unless params[:unreachable_since], do: Instances.set_unreachable(inbox)
|
|
||||||
{:error, response}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# filter out broken threads
|
# filter out broken threads
|
||||||
def contain_broken_threads(%Activity{} = activity, %User{} = user) do
|
def contain_broken_threads(%Activity{} = activity, %User{} = user) do
|
||||||
entire_thread_visible_for_user?(activity, user)
|
entire_thread_visible_for_user?(activity, user)
|
||||||
|
|
|
@ -155,7 +155,7 @@ def outbox(conn, %{"nickname" => nickname} = params) do
|
||||||
|
|
||||||
def inbox(%{assigns: %{valid_signature: true}} = conn, %{"nickname" => nickname} = params) do
|
def inbox(%{assigns: %{valid_signature: true}} = conn, %{"nickname" => nickname} = params) do
|
||||||
with %User{} = recipient <- User.get_cached_by_nickname(nickname),
|
with %User{} = recipient <- User.get_cached_by_nickname(nickname),
|
||||||
%User{} = actor <- User.get_or_fetch_by_ap_id(params["actor"]),
|
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(params["actor"]),
|
||||||
true <- Utils.recipient_in_message(recipient, actor, params),
|
true <- Utils.recipient_in_message(recipient, actor, params),
|
||||||
params <- Utils.maybe_splice_recipient(recipient.ap_id, params) do
|
params <- Utils.maybe_splice_recipient(recipient.ap_id, params) do
|
||||||
Federator.incoming_ap_doc(params)
|
Federator.incoming_ap_doc(params)
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
|
@moduledoc "Prevent followbots from following with a bit of heuristic"
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
# XXX: this should become User.normalize_by_ap_id() or similar, really.
|
# XXX: this should become User.normalize_by_ap_id() or similar, really.
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do
|
||||||
require Logger
|
require Logger
|
||||||
|
@moduledoc "Drop and log everything received"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
|
defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
|
|
||||||
|
@moduledoc "Ensure a re: is prepended on replies to a post with a Subject"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
@reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless])
|
@reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless])
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
@moduledoc "Block messages with too much mentions (configurable)"
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
defp delist_message(message, threshold) when threshold > 0 do
|
defp delist_message(message, threshold) when threshold > 0 do
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
||||||
|
@moduledoc "Reject or Word-Replace messages with a keyword or regex"
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
defp string_matches?(string, _) when not is_binary(string) do
|
defp string_matches?(string, _) when not is_binary(string) do
|
||||||
false
|
false
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy do
|
||||||
|
@moduledoc "Ensure no content placeholder is present (such as the dot from mastodon)"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do
|
||||||
|
@moduledoc "Does nothing (lets the messages go through unmodified)"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do
|
defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do
|
||||||
|
@moduledoc "Scrub configured hypertext markup"
|
||||||
alias Pleroma.HTML
|
alias Pleroma.HTML
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do
|
defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
@moduledoc "Rejects non-public (followers-only, direct) activities"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
@moduledoc "Filter activities depending on their origin instance"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
defp check_accept(%{host: actor_host} = _actor_info, object) do
|
defp check_accept(%{host: actor_host} = _actor_info, object) do
|
||||||
|
|
|
@ -5,6 +5,19 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
@moduledoc """
|
||||||
|
Apply policies based on user tags
|
||||||
|
|
||||||
|
This policy applies policies on a user activities depending on their tags
|
||||||
|
on your instance.
|
||||||
|
|
||||||
|
- `mrf_tag:media-force-nsfw`: Mark as sensitive on presence of attachments
|
||||||
|
- `mrf_tag:media-strip`: Remove attachments
|
||||||
|
- `mrf_tag:force-unlisted`: Mark as unlisted (removes from the federated timeline)
|
||||||
|
- `mrf_tag:sandbox`: Remove from public (local and federated) timelines
|
||||||
|
- `mrf_tag:disable-remote-subscription`: Reject non-local follow requests
|
||||||
|
- `mrf_tag:disable-any-subscription`: Reject any follow requests
|
||||||
|
"""
|
||||||
|
|
||||||
defp get_tags(%User{tags: tags}) when is_list(tags), do: tags
|
defp get_tags(%User{tags: tags}) when is_list(tags), do: tags
|
||||||
defp get_tags(_), do: []
|
defp get_tags(_), do: []
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy do
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
|
|
||||||
|
@moduledoc "Accept-list of users from specified instances"
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
|
||||||
defp filter_by_list(object, []), do: {:ok, object}
|
defp filter_by_list(object, []), do: {:ok, object}
|
||||||
|
|
201
lib/pleroma/web/activity_pub/publisher.ex
Normal file
201
lib/pleroma/web/activity_pub/publisher.ex
Normal file
|
@ -0,0 +1,201 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.ActivityPub.Publisher do
|
||||||
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Config
|
||||||
|
alias Pleroma.Instances
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.ActivityPub.Relay
|
||||||
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
|
|
||||||
|
import Pleroma.Web.ActivityPub.Visibility
|
||||||
|
|
||||||
|
@behaviour Pleroma.Web.Federator.Publisher
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
|
||||||
|
@httpoison Application.get_env(:pleroma, :httpoison)
|
||||||
|
|
||||||
|
@moduledoc """
|
||||||
|
ActivityPub outgoing federation module.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Determine if an activity can be represented by running it through Transmogrifier.
|
||||||
|
"""
|
||||||
|
def is_representable?(%Activity{} = activity) do
|
||||||
|
with {:ok, _data} <- Transmogrifier.prepare_outgoing(activity.data) do
|
||||||
|
true
|
||||||
|
else
|
||||||
|
_e ->
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Publish a single message to a peer. Takes a struct with the following
|
||||||
|
parameters set:
|
||||||
|
|
||||||
|
* `inbox`: the inbox to publish to
|
||||||
|
* `json`: the JSON message body representing the ActivityPub message
|
||||||
|
* `actor`: the actor which is signing the message
|
||||||
|
* `id`: the ActivityStreams URI of the message
|
||||||
|
"""
|
||||||
|
def publish_one(%{inbox: inbox, json: json, actor: %User{} = actor, id: id} = params) do
|
||||||
|
Logger.info("Federating #{id} to #{inbox}")
|
||||||
|
host = URI.parse(inbox).host
|
||||||
|
|
||||||
|
digest = "SHA-256=" <> (:crypto.hash(:sha256, json) |> Base.encode64())
|
||||||
|
|
||||||
|
date =
|
||||||
|
NaiveDateTime.utc_now()
|
||||||
|
|> Timex.format!("{WDshort}, {0D} {Mshort} {YYYY} {h24}:{m}:{s} GMT")
|
||||||
|
|
||||||
|
signature =
|
||||||
|
Pleroma.Web.HTTPSignatures.sign(actor, %{
|
||||||
|
host: host,
|
||||||
|
"content-length": byte_size(json),
|
||||||
|
digest: digest,
|
||||||
|
date: date
|
||||||
|
})
|
||||||
|
|
||||||
|
with {:ok, %{status: code}} when code in 200..299 <-
|
||||||
|
result =
|
||||||
|
@httpoison.post(
|
||||||
|
inbox,
|
||||||
|
json,
|
||||||
|
[
|
||||||
|
{"Content-Type", "application/activity+json"},
|
||||||
|
{"Date", date},
|
||||||
|
{"signature", signature},
|
||||||
|
{"digest", digest}
|
||||||
|
]
|
||||||
|
) do
|
||||||
|
if !Map.has_key?(params, :unreachable_since) || params[:unreachable_since],
|
||||||
|
do: Instances.set_reachable(inbox)
|
||||||
|
|
||||||
|
result
|
||||||
|
else
|
||||||
|
{_post_result, response} ->
|
||||||
|
unless params[:unreachable_since], do: Instances.set_unreachable(inbox)
|
||||||
|
{:error, response}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp should_federate?(inbox, public) do
|
||||||
|
if public do
|
||||||
|
true
|
||||||
|
else
|
||||||
|
inbox_info = URI.parse(inbox)
|
||||||
|
!Enum.member?(Pleroma.Config.get([:instance, :quarantined_instances], []), inbox_info.host)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp recipients(actor, activity) do
|
||||||
|
followers =
|
||||||
|
if actor.follower_address in activity.recipients do
|
||||||
|
{:ok, followers} = User.get_followers(actor)
|
||||||
|
Enum.filter(followers, &(!&1.local))
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
|
Pleroma.Web.Salmon.remote_users(actor, activity) ++ followers
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_cc_ap_ids(ap_id, recipients) do
|
||||||
|
host = Map.get(URI.parse(ap_id), :host)
|
||||||
|
|
||||||
|
recipients
|
||||||
|
|> Enum.filter(fn %User{ap_id: ap_id} -> Map.get(URI.parse(ap_id), :host) == host end)
|
||||||
|
|> Enum.map(& &1.ap_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Publishes an activity with BCC to all relevant peers.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def publish(actor, %{data: %{"bcc" => bcc}} = activity) when is_list(bcc) and bcc != [] do
|
||||||
|
public = is_public?(activity)
|
||||||
|
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
||||||
|
|
||||||
|
recipients = recipients(actor, activity)
|
||||||
|
|
||||||
|
recipients
|
||||||
|
|> Enum.filter(&User.ap_enabled?/1)
|
||||||
|
|> Enum.map(fn %{info: %{source_data: data}} -> data["inbox"] end)
|
||||||
|
|> Enum.filter(fn inbox -> should_federate?(inbox, public) end)
|
||||||
|
|> Instances.filter_reachable()
|
||||||
|
|> Enum.each(fn {inbox, unreachable_since} ->
|
||||||
|
%User{ap_id: ap_id} =
|
||||||
|
Enum.find(recipients, fn %{info: %{source_data: data}} -> data["inbox"] == inbox end)
|
||||||
|
|
||||||
|
cc = get_cc_ap_ids(ap_id, recipients)
|
||||||
|
|
||||||
|
json =
|
||||||
|
data
|
||||||
|
|> Map.put("cc", cc)
|
||||||
|
|> Map.put("directMessage", true)
|
||||||
|
|> Jason.encode!()
|
||||||
|
|
||||||
|
Pleroma.Web.Federator.Publisher.enqueue_one(__MODULE__, %{
|
||||||
|
inbox: inbox,
|
||||||
|
json: json,
|
||||||
|
actor: actor,
|
||||||
|
id: activity.data["id"],
|
||||||
|
unreachable_since: unreachable_since
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Publishes an activity to all relevant peers.
|
||||||
|
"""
|
||||||
|
def publish(%User{} = actor, %Activity{} = activity) do
|
||||||
|
public = is_public?(activity)
|
||||||
|
|
||||||
|
if public && Config.get([:instance, :allow_relay]) do
|
||||||
|
Logger.info(fn -> "Relaying #{activity.data["id"]} out" end)
|
||||||
|
Relay.publish(activity)
|
||||||
|
end
|
||||||
|
|
||||||
|
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
||||||
|
json = Jason.encode!(data)
|
||||||
|
|
||||||
|
recipients(actor, activity)
|
||||||
|
|> Enum.filter(fn user -> User.ap_enabled?(user) end)
|
||||||
|
|> Enum.map(fn %{info: %{source_data: data}} ->
|
||||||
|
(is_map(data["endpoints"]) && Map.get(data["endpoints"], "sharedInbox")) || data["inbox"]
|
||||||
|
end)
|
||||||
|
|> Enum.uniq()
|
||||||
|
|> Enum.filter(fn inbox -> should_federate?(inbox, public) end)
|
||||||
|
|> Instances.filter_reachable()
|
||||||
|
|> Enum.each(fn {inbox, unreachable_since} ->
|
||||||
|
Pleroma.Web.Federator.Publisher.enqueue_one(
|
||||||
|
__MODULE__,
|
||||||
|
%{
|
||||||
|
inbox: inbox,
|
||||||
|
json: json,
|
||||||
|
actor: actor,
|
||||||
|
id: activity.data["id"],
|
||||||
|
unreachable_since: unreachable_since
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def gather_webfinger_links(%User{} = user) do
|
||||||
|
[
|
||||||
|
%{"rel" => "self", "type" => "application/activity+json", "href" => user.ap_id},
|
||||||
|
%{
|
||||||
|
"rel" => "self",
|
||||||
|
"type" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
|
||||||
|
"href" => user.ap_id
|
||||||
|
}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
def gather_nodeinfo_protocol_names, do: ["activitypub"]
|
||||||
|
end
|
|
@ -15,7 +15,7 @@ def get_actor do
|
||||||
|
|
||||||
def follow(target_instance) do
|
def follow(target_instance) do
|
||||||
with %User{} = local_user <- get_actor(),
|
with %User{} = local_user <- get_actor(),
|
||||||
%User{} = target_user <- User.get_or_fetch_by_ap_id(target_instance),
|
{:ok, %User{} = target_user} <- User.get_or_fetch_by_ap_id(target_instance),
|
||||||
{:ok, activity} <- ActivityPub.follow(local_user, target_user) do
|
{:ok, activity} <- ActivityPub.follow(local_user, target_user) do
|
||||||
Logger.info("relay: followed instance: #{target_instance}; id=#{activity.data["id"]}")
|
Logger.info("relay: followed instance: #{target_instance}; id=#{activity.data["id"]}")
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
@ -28,7 +28,7 @@ def follow(target_instance) do
|
||||||
|
|
||||||
def unfollow(target_instance) do
|
def unfollow(target_instance) do
|
||||||
with %User{} = local_user <- get_actor(),
|
with %User{} = local_user <- get_actor(),
|
||||||
%User{} = target_user <- User.get_or_fetch_by_ap_id(target_instance),
|
{:ok, %User{} = target_user} <- User.get_or_fetch_by_ap_id(target_instance),
|
||||||
{:ok, activity} <- ActivityPub.unfollow(local_user, target_user) do
|
{:ok, activity} <- ActivityPub.unfollow(local_user, target_user) do
|
||||||
Logger.info("relay: unfollowed instance: #{target_instance}: id=#{activity.data["id"]}")
|
Logger.info("relay: unfollowed instance: #{target_instance}: id=#{activity.data["id"]}")
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
|
|
@ -126,7 +126,7 @@ def fix_implicit_addressing(%{"to" => to, "cc" => cc} = object, followers_collec
|
||||||
def fix_implicit_addressing(object, _), do: object
|
def fix_implicit_addressing(object, _), do: object
|
||||||
|
|
||||||
def fix_addressing(object) do
|
def fix_addressing(object) do
|
||||||
%User{} = user = User.get_or_fetch_by_ap_id(object["actor"])
|
{:ok, %User{} = user} = User.get_or_fetch_by_ap_id(object["actor"])
|
||||||
followers_collection = User.ap_followers(user)
|
followers_collection = User.ap_followers(user)
|
||||||
|
|
||||||
object
|
object
|
||||||
|
@ -407,7 +407,7 @@ def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = obj
|
||||||
|> fix_addressing
|
|> fix_addressing
|
||||||
|
|
||||||
with nil <- Activity.get_create_by_object_ap_id(object["id"]),
|
with nil <- Activity.get_create_by_object_ap_id(object["id"]),
|
||||||
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
|
{:ok, %User{} = user} <- User.get_or_fetch_by_ap_id(data["actor"]) do
|
||||||
object = fix_object(data["object"])
|
object = fix_object(data["object"])
|
||||||
|
|
||||||
params = %{
|
params = %{
|
||||||
|
@ -436,7 +436,7 @@ def handle_incoming(
|
||||||
%{"type" => "Follow", "object" => followed, "actor" => follower, "id" => id} = data
|
%{"type" => "Follow", "object" => followed, "actor" => follower, "id" => id} = data
|
||||||
) do
|
) do
|
||||||
with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
|
with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
|
||||||
%User{} = follower <- User.get_or_fetch_by_ap_id(follower),
|
{:ok, %User{} = follower} <- User.get_or_fetch_by_ap_id(follower),
|
||||||
{:ok, activity} <- ActivityPub.follow(follower, followed, id, false) do
|
{:ok, activity} <- ActivityPub.follow(follower, followed, id, false) do
|
||||||
with deny_follow_blocked <- Pleroma.Config.get([:user, :deny_follow_blocked]),
|
with deny_follow_blocked <- Pleroma.Config.get([:user, :deny_follow_blocked]),
|
||||||
{:user_blocked, false} <-
|
{:user_blocked, false} <-
|
||||||
|
@ -485,7 +485,7 @@ def handle_incoming(
|
||||||
%{"type" => "Accept", "object" => follow_object, "actor" => _actor, "id" => _id} = data
|
%{"type" => "Accept", "object" => follow_object, "actor" => _actor, "id" => _id} = data
|
||||||
) do
|
) do
|
||||||
with actor <- Containment.get_actor(data),
|
with actor <- Containment.get_actor(data),
|
||||||
%User{} = followed <- User.get_or_fetch_by_ap_id(actor),
|
{:ok, %User{} = followed} <- User.get_or_fetch_by_ap_id(actor),
|
||||||
{:ok, follow_activity} <- get_follow_activity(follow_object, followed),
|
{:ok, follow_activity} <- get_follow_activity(follow_object, followed),
|
||||||
{:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"),
|
{:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"),
|
||||||
%User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity.data["actor"]),
|
%User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity.data["actor"]),
|
||||||
|
@ -511,7 +511,7 @@ def handle_incoming(
|
||||||
%{"type" => "Reject", "object" => follow_object, "actor" => _actor, "id" => _id} = data
|
%{"type" => "Reject", "object" => follow_object, "actor" => _actor, "id" => _id} = data
|
||||||
) do
|
) do
|
||||||
with actor <- Containment.get_actor(data),
|
with actor <- Containment.get_actor(data),
|
||||||
%User{} = followed <- User.get_or_fetch_by_ap_id(actor),
|
{:ok, %User{} = followed} <- User.get_or_fetch_by_ap_id(actor),
|
||||||
{:ok, follow_activity} <- get_follow_activity(follow_object, followed),
|
{:ok, follow_activity} <- get_follow_activity(follow_object, followed),
|
||||||
{:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"),
|
{:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"),
|
||||||
%User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity.data["actor"]),
|
%User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity.data["actor"]),
|
||||||
|
@ -535,7 +535,7 @@ def handle_incoming(
|
||||||
%{"type" => "Like", "object" => object_id, "actor" => _actor, "id" => id} = data
|
%{"type" => "Like", "object" => object_id, "actor" => _actor, "id" => id} = data
|
||||||
) do
|
) do
|
||||||
with actor <- Containment.get_actor(data),
|
with actor <- Containment.get_actor(data),
|
||||||
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
|
||||||
{:ok, object} <- get_obj_helper(object_id),
|
{:ok, object} <- get_obj_helper(object_id),
|
||||||
{:ok, activity, _object} <- ActivityPub.like(actor, object, id, false) do
|
{:ok, activity, _object} <- ActivityPub.like(actor, object, id, false) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
@ -548,7 +548,7 @@ def handle_incoming(
|
||||||
%{"type" => "Announce", "object" => object_id, "actor" => _actor, "id" => id} = data
|
%{"type" => "Announce", "object" => object_id, "actor" => _actor, "id" => id} = data
|
||||||
) do
|
) do
|
||||||
with actor <- Containment.get_actor(data),
|
with actor <- Containment.get_actor(data),
|
||||||
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
|
||||||
{:ok, object} <- get_obj_helper(object_id),
|
{:ok, object} <- get_obj_helper(object_id),
|
||||||
public <- Visibility.is_public?(data),
|
public <- Visibility.is_public?(data),
|
||||||
{:ok, activity, _object} <- ActivityPub.announce(actor, object, id, false, public) do
|
{:ok, activity, _object} <- ActivityPub.announce(actor, object, id, false, public) do
|
||||||
|
@ -603,7 +603,7 @@ def handle_incoming(
|
||||||
object_id = Utils.get_ap_id(object_id)
|
object_id = Utils.get_ap_id(object_id)
|
||||||
|
|
||||||
with actor <- Containment.get_actor(data),
|
with actor <- Containment.get_actor(data),
|
||||||
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
|
||||||
{:ok, object} <- get_obj_helper(object_id),
|
{:ok, object} <- get_obj_helper(object_id),
|
||||||
:ok <- Containment.contain_origin(actor.ap_id, object.data),
|
:ok <- Containment.contain_origin(actor.ap_id, object.data),
|
||||||
{:ok, activity} <- ActivityPub.delete(object, false) do
|
{:ok, activity} <- ActivityPub.delete(object, false) do
|
||||||
|
@ -622,7 +622,7 @@ def handle_incoming(
|
||||||
} = data
|
} = data
|
||||||
) do
|
) do
|
||||||
with actor <- Containment.get_actor(data),
|
with actor <- Containment.get_actor(data),
|
||||||
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
|
||||||
{:ok, object} <- get_obj_helper(object_id),
|
{:ok, object} <- get_obj_helper(object_id),
|
||||||
{:ok, activity, _} <- ActivityPub.unannounce(actor, object, id, false) do
|
{:ok, activity, _} <- ActivityPub.unannounce(actor, object, id, false) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
@ -640,7 +640,7 @@ def handle_incoming(
|
||||||
} = _data
|
} = _data
|
||||||
) do
|
) do
|
||||||
with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
|
with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
|
||||||
%User{} = follower <- User.get_or_fetch_by_ap_id(follower),
|
{:ok, %User{} = follower} <- User.get_or_fetch_by_ap_id(follower),
|
||||||
{:ok, activity} <- ActivityPub.unfollow(follower, followed, id, false) do
|
{:ok, activity} <- ActivityPub.unfollow(follower, followed, id, false) do
|
||||||
User.unfollow(follower, followed)
|
User.unfollow(follower, followed)
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
@ -659,7 +659,7 @@ def handle_incoming(
|
||||||
) do
|
) do
|
||||||
with true <- Pleroma.Config.get([:activitypub, :accept_blocks]),
|
with true <- Pleroma.Config.get([:activitypub, :accept_blocks]),
|
||||||
%User{local: true} = blocked <- User.get_cached_by_ap_id(blocked),
|
%User{local: true} = blocked <- User.get_cached_by_ap_id(blocked),
|
||||||
%User{} = blocker <- User.get_or_fetch_by_ap_id(blocker),
|
{:ok, %User{} = blocker} <- User.get_or_fetch_by_ap_id(blocker),
|
||||||
{:ok, activity} <- ActivityPub.unblock(blocker, blocked, id, false) do
|
{:ok, activity} <- ActivityPub.unblock(blocker, blocked, id, false) do
|
||||||
User.unblock(blocker, blocked)
|
User.unblock(blocker, blocked)
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
@ -673,7 +673,7 @@ def handle_incoming(
|
||||||
) do
|
) do
|
||||||
with true <- Pleroma.Config.get([:activitypub, :accept_blocks]),
|
with true <- Pleroma.Config.get([:activitypub, :accept_blocks]),
|
||||||
%User{local: true} = blocked = User.get_cached_by_ap_id(blocked),
|
%User{local: true} = blocked = User.get_cached_by_ap_id(blocked),
|
||||||
%User{} = blocker = User.get_or_fetch_by_ap_id(blocker),
|
{:ok, %User{} = blocker} = User.get_or_fetch_by_ap_id(blocker),
|
||||||
{:ok, activity} <- ActivityPub.block(blocker, blocked, id, false) do
|
{:ok, activity} <- ActivityPub.block(blocker, blocked, id, false) do
|
||||||
User.unfollow(blocker, blocked)
|
User.unfollow(blocker, blocked)
|
||||||
User.block(blocker, blocked)
|
User.block(blocker, blocked)
|
||||||
|
@ -692,7 +692,7 @@ def handle_incoming(
|
||||||
} = data
|
} = data
|
||||||
) do
|
) do
|
||||||
with actor <- Containment.get_actor(data),
|
with actor <- Containment.get_actor(data),
|
||||||
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
|
||||||
{:ok, object} <- get_obj_helper(object_id),
|
{:ok, object} <- get_obj_helper(object_id),
|
||||||
{:ok, activity, _, _} <- ActivityPub.unlike(actor, object, id, false) do
|
{:ok, activity, _, _} <- ActivityPub.unlike(actor, object, id, false) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
@ -859,10 +859,16 @@ def add_mention_tags(object) do
|
||||||
|> Map.put("tag", tags ++ mentions)
|
|> Map.put("tag", tags ++ mentions)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_emoji_tags(%User{info: %{"emoji" => _emoji} = user_info} = object) do
|
||||||
|
user_info = add_emoji_tags(user_info)
|
||||||
|
|
||||||
|
object
|
||||||
|
|> Map.put(:info, user_info)
|
||||||
|
end
|
||||||
|
|
||||||
# TODO: we should probably send mtime instead of unix epoch time for updated
|
# TODO: we should probably send mtime instead of unix epoch time for updated
|
||||||
def add_emoji_tags(object) do
|
def add_emoji_tags(%{"emoji" => emoji} = object) do
|
||||||
tags = object["tag"] || []
|
tags = object["tag"] || []
|
||||||
emoji = object["emoji"] || []
|
|
||||||
|
|
||||||
out =
|
out =
|
||||||
emoji
|
emoji
|
||||||
|
@ -880,6 +886,10 @@ def add_emoji_tags(object) do
|
||||||
|> Map.put("tag", tags ++ out)
|
|> Map.put("tag", tags ++ out)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_emoji_tags(object) do
|
||||||
|
object
|
||||||
|
end
|
||||||
|
|
||||||
def set_conversation(object) do
|
def set_conversation(object) do
|
||||||
Map.put(object, "conversation", object["context"])
|
Map.put(object, "conversation", object["context"])
|
||||||
end
|
end
|
||||||
|
|
|
@ -682,7 +682,7 @@ def make_flag_data(params, additional) do
|
||||||
"""
|
"""
|
||||||
def fetch_ordered_collection(from, pages_left, acc \\ []) do
|
def fetch_ordered_collection(from, pages_left, acc \\ []) do
|
||||||
with {:ok, response} <- Tesla.get(from),
|
with {:ok, response} <- Tesla.get(from),
|
||||||
{:ok, collection} <- Poison.decode(response.body) do
|
{:ok, collection} <- Jason.decode(response.body) do
|
||||||
case collection["type"] do
|
case collection["type"] do
|
||||||
"OrderedCollection" ->
|
"OrderedCollection" ->
|
||||||
# If we've encountered the OrderedCollection and not the page,
|
# If we've encountered the OrderedCollection and not the page,
|
||||||
|
|
|
@ -69,6 +69,11 @@ def render("user.json", %{user: user}) do
|
||||||
|
|
||||||
endpoints = render("endpoints.json", %{user: user})
|
endpoints = render("endpoints.json", %{user: user})
|
||||||
|
|
||||||
|
user_tags =
|
||||||
|
user
|
||||||
|
|> Transmogrifier.add_emoji_tags()
|
||||||
|
|> Map.get("tag", [])
|
||||||
|
|
||||||
%{
|
%{
|
||||||
"id" => user.ap_id,
|
"id" => user.ap_id,
|
||||||
"type" => "Person",
|
"type" => "Person",
|
||||||
|
@ -87,7 +92,7 @@ def render("user.json", %{user: user}) do
|
||||||
"publicKeyPem" => public_key
|
"publicKeyPem" => public_key
|
||||||
},
|
},
|
||||||
"endpoints" => endpoints,
|
"endpoints" => endpoints,
|
||||||
"tag" => user.info.source_data["tag"] || []
|
"tag" => (user.info.source_data["tag"] || []) ++ user_tags
|
||||||
}
|
}
|
||||||
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|
||||||
|> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
|
|> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
|
||||||
|
|
|
@ -59,7 +59,7 @@ def user_create(
|
||||||
bio: "."
|
bio: "."
|
||||||
}
|
}
|
||||||
|
|
||||||
changeset = User.register_changeset(%User{}, user_data, confirmed: true)
|
changeset = User.register_changeset(%User{}, user_data, need_confirmation: false)
|
||||||
{:ok, user} = User.register(changeset)
|
{:ok, user} = User.register(changeset)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|
@ -101,7 +101,10 @@ def list_users(conn, params) do
|
||||||
search_params = %{
|
search_params = %{
|
||||||
query: params["query"],
|
query: params["query"],
|
||||||
page: page,
|
page: page,
|
||||||
page_size: page_size
|
page_size: page_size,
|
||||||
|
tags: params["tags"],
|
||||||
|
name: params["name"],
|
||||||
|
email: params["email"]
|
||||||
}
|
}
|
||||||
|
|
||||||
with {:ok, users, count} <- Search.user(Map.merge(search_params, filters)),
|
with {:ok, users, count} <- Search.user(Map.merge(search_params, filters)),
|
||||||
|
@ -116,11 +119,11 @@ def list_users(conn, params) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@filters ~w(local external active deactivated)
|
@filters ~w(local external active deactivated is_admin is_moderator)
|
||||||
|
|
||||||
defp maybe_parse_filters(filters) when is_nil(filters) or filters == "", do: %{}
|
|
||||||
|
|
||||||
@spec maybe_parse_filters(String.t()) :: %{required(String.t()) => true} | %{}
|
@spec maybe_parse_filters(String.t()) :: %{required(String.t()) => true} | %{}
|
||||||
|
defp maybe_parse_filters(filters) when is_nil(filters) or filters == "", do: %{}
|
||||||
|
|
||||||
defp maybe_parse_filters(filters) do
|
defp maybe_parse_filters(filters) do
|
||||||
filters
|
filters
|
||||||
|> String.split(",")
|
|> String.split(",")
|
||||||
|
|
|
@ -10,45 +10,23 @@ defmodule Pleroma.Web.AdminAPI.Search do
|
||||||
|
|
||||||
@page_size 50
|
@page_size 50
|
||||||
|
|
||||||
def user(%{query: term} = params) when is_nil(term) or term == "" do
|
defmacro not_empty_string(string) do
|
||||||
query = maybe_filtered_query(params)
|
quote do
|
||||||
|
is_binary(unquote(string)) and unquote(string) != ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec user(map()) :: {:ok, [User.t()], pos_integer()}
|
||||||
|
def user(params \\ %{}) do
|
||||||
|
query = User.Query.build(params) |> order_by([u], u.nickname)
|
||||||
|
|
||||||
paginated_query =
|
paginated_query =
|
||||||
maybe_filtered_query(params)
|
User.Query.paginate(query, params[:page] || 1, params[:page_size] || @page_size)
|
||||||
|> paginate(params[:page] || 1, params[:page_size] || @page_size)
|
|
||||||
|
|
||||||
count = query |> Repo.aggregate(:count, :id)
|
count = Repo.aggregate(query, :count, :id)
|
||||||
|
|
||||||
results = Repo.all(paginated_query)
|
results = Repo.all(paginated_query)
|
||||||
|
|
||||||
{:ok, results, count}
|
{:ok, results, count}
|
||||||
end
|
end
|
||||||
|
|
||||||
def user(%{query: term} = params) when is_binary(term) do
|
|
||||||
search_query = from(u in maybe_filtered_query(params), where: ilike(u.nickname, ^"%#{term}%"))
|
|
||||||
|
|
||||||
count = search_query |> Repo.aggregate(:count, :id)
|
|
||||||
|
|
||||||
results =
|
|
||||||
search_query
|
|
||||||
|> paginate(params[:page] || 1, params[:page_size] || @page_size)
|
|
||||||
|> Repo.all()
|
|
||||||
|
|
||||||
{:ok, results, count}
|
|
||||||
end
|
|
||||||
|
|
||||||
defp maybe_filtered_query(params) do
|
|
||||||
from(u in User, order_by: u.nickname)
|
|
||||||
|> User.maybe_local_user_query(params[:local])
|
|
||||||
|> User.maybe_external_user_query(params[:external])
|
|
||||||
|> User.maybe_active_user_query(params[:active])
|
|
||||||
|> User.maybe_deactivated_user_query(params[:deactivated])
|
|
||||||
end
|
|
||||||
|
|
||||||
defp paginate(query, page, page_size) do
|
|
||||||
from(u in query,
|
|
||||||
limit: ^page_size,
|
|
||||||
offset: ^((page - 1) * page_size)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,4 +42,30 @@ def oauth_consumer_template do
|
||||||
implementation().oauth_consumer_template() ||
|
implementation().oauth_consumer_template() ||
|
||||||
Pleroma.Config.get([:auth, :oauth_consumer_template], "consumer.html")
|
Pleroma.Config.get([:auth, :oauth_consumer_template], "consumer.html")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc "Gets user by nickname or email for auth."
|
||||||
|
@spec fetch_user(String.t()) :: User.t() | nil
|
||||||
|
def fetch_user(name) do
|
||||||
|
User.get_by_nickname_or_email(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Gets name and password from conn
|
||||||
|
#
|
||||||
|
@spec fetch_credentials(Plug.Conn.t() | map()) ::
|
||||||
|
{:ok, {name :: any, password :: any}} | {:error, :invalid_credentials}
|
||||||
|
def fetch_credentials(%Plug.Conn{params: params} = _),
|
||||||
|
do: fetch_credentials(params)
|
||||||
|
|
||||||
|
def fetch_credentials(params) do
|
||||||
|
case params do
|
||||||
|
%{"authorization" => %{"name" => name, "password" => password}} ->
|
||||||
|
{:ok, {name, password}}
|
||||||
|
|
||||||
|
%{"grant_type" => "password", "username" => name, "password" => password} ->
|
||||||
|
{:ok, {name, password}}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
{:error, :invalid_credentials}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,9 @@ defmodule Pleroma.Web.Auth.LDAPAuthenticator do
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
import Pleroma.Web.Auth.Authenticator,
|
||||||
|
only: [fetch_credentials: 1, fetch_user: 1]
|
||||||
|
|
||||||
@behaviour Pleroma.Web.Auth.Authenticator
|
@behaviour Pleroma.Web.Auth.Authenticator
|
||||||
@base Pleroma.Web.Auth.PleromaAuthenticator
|
@base Pleroma.Web.Auth.PleromaAuthenticator
|
||||||
|
|
||||||
|
@ -20,31 +23,21 @@ defmodule Pleroma.Web.Auth.LDAPAuthenticator do
|
||||||
defdelegate oauth_consumer_template, to: @base
|
defdelegate oauth_consumer_template, to: @base
|
||||||
|
|
||||||
def get_user(%Plug.Conn{} = conn) do
|
def get_user(%Plug.Conn{} = conn) do
|
||||||
if Pleroma.Config.get([:ldap, :enabled]) do
|
with {:ldap, true} <- {:ldap, Pleroma.Config.get([:ldap, :enabled])},
|
||||||
{name, password} =
|
{:ok, {name, password}} <- fetch_credentials(conn),
|
||||||
case conn.params do
|
%User{} = user <- ldap_user(name, password) do
|
||||||
%{"authorization" => %{"name" => name, "password" => password}} ->
|
|
||||||
{name, password}
|
|
||||||
|
|
||||||
%{"grant_type" => "password", "username" => name, "password" => password} ->
|
|
||||||
{name, password}
|
|
||||||
end
|
|
||||||
|
|
||||||
case ldap_user(name, password) do
|
|
||||||
%User{} = user ->
|
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
|
else
|
||||||
{:error, {:ldap_connection_error, _}} ->
|
{:error, {:ldap_connection_error, _}} ->
|
||||||
# When LDAP is unavailable, try default authenticator
|
# When LDAP is unavailable, try default authenticator
|
||||||
@base.get_user(conn)
|
@base.get_user(conn)
|
||||||
|
|
||||||
|
{:ldap, _} ->
|
||||||
|
@base.get_user(conn)
|
||||||
|
|
||||||
error ->
|
error ->
|
||||||
error
|
error
|
||||||
end
|
end
|
||||||
else
|
|
||||||
# Fall back to default authenticator
|
|
||||||
@base.get_user(conn)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp ldap_user(name, password) do
|
defp ldap_user(name, password) do
|
||||||
|
@ -94,7 +87,7 @@ defp bind_user(connection, ldap, name, password) do
|
||||||
|
|
||||||
case :eldap.simple_bind(connection, "#{uid}=#{name},#{base}", password) do
|
case :eldap.simple_bind(connection, "#{uid}=#{name},#{base}", password) do
|
||||||
:ok ->
|
:ok ->
|
||||||
case User.get_by_nickname_or_email(name) do
|
case fetch_user(name) do
|
||||||
%User{} = user ->
|
%User{} = user ->
|
||||||
user
|
user
|
||||||
|
|
||||||
|
|
|
@ -8,19 +8,14 @@ defmodule Pleroma.Web.Auth.PleromaAuthenticator do
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
|
import Pleroma.Web.Auth.Authenticator,
|
||||||
|
only: [fetch_credentials: 1, fetch_user: 1]
|
||||||
|
|
||||||
@behaviour Pleroma.Web.Auth.Authenticator
|
@behaviour Pleroma.Web.Auth.Authenticator
|
||||||
|
|
||||||
def get_user(%Plug.Conn{} = conn) do
|
def get_user(%Plug.Conn{} = conn) do
|
||||||
{name, password} =
|
with {:ok, {name, password}} <- fetch_credentials(conn),
|
||||||
case conn.params do
|
{_, %User{} = user} <- {:user, fetch_user(name)},
|
||||||
%{"authorization" => %{"name" => name, "password" => password}} ->
|
|
||||||
{name, password}
|
|
||||||
|
|
||||||
%{"grant_type" => "password", "username" => name, "password" => password} ->
|
|
||||||
{name, password}
|
|
||||||
end
|
|
||||||
|
|
||||||
with {_, %User{} = user} <- {:user, User.get_by_nickname_or_email(name)},
|
|
||||||
{_, true} <- {:checkpw, Pbkdf2.checkpw(password, user.password_hash)} do
|
{_, true} <- {:checkpw, Pbkdf2.checkpw(password, user.password_hash)} do
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
else
|
else
|
||||||
|
@ -79,7 +74,7 @@ def create_from_registration(
|
||||||
password_confirmation: random_password
|
password_confirmation: random_password
|
||||||
},
|
},
|
||||||
external: true,
|
external: true,
|
||||||
confirmed: true
|
need_confirmation: false
|
||||||
)
|
)
|
||||||
|> Repo.insert(),
|
|> Repo.insert(),
|
||||||
{:ok, _} <-
|
{:ok, _} <-
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.CommonAPI do
|
defmodule Pleroma.Web.CommonAPI do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Bookmark
|
||||||
alias Pleroma.Formatter
|
alias Pleroma.Formatter
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.ThreadMute
|
alias Pleroma.ThreadMute
|
||||||
|
@ -155,8 +156,8 @@ def post(user, %{"status" => status} = data) do
|
||||||
{to, cc} <- to_for_user_and_mentions(user, mentions, in_reply_to, visibility),
|
{to, cc} <- to_for_user_and_mentions(user, mentions, in_reply_to, visibility),
|
||||||
bcc <- bcc_for_list(user, visibility),
|
bcc <- bcc_for_list(user, visibility),
|
||||||
context <- make_context(in_reply_to),
|
context <- make_context(in_reply_to),
|
||||||
cw <- data["spoiler_text"],
|
cw <- data["spoiler_text"] || "",
|
||||||
full_payload <- String.trim(status <> (data["spoiler_text"] || "")),
|
full_payload <- String.trim(status <> cw),
|
||||||
length when length in 1..limit <- String.length(full_payload),
|
length when length in 1..limit <- String.length(full_payload),
|
||||||
object <-
|
object <-
|
||||||
make_note_data(
|
make_note_data(
|
||||||
|
@ -174,10 +175,7 @@ def post(user, %{"status" => status} = data) do
|
||||||
Map.put(
|
Map.put(
|
||||||
object,
|
object,
|
||||||
"emoji",
|
"emoji",
|
||||||
(Formatter.get_emoji(status) ++ Formatter.get_emoji(data["spoiler_text"]))
|
Formatter.get_emoji_map(full_payload)
|
||||||
|> Enum.reduce(%{}, fn {name, file, _}, acc ->
|
|
||||||
Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}")
|
|
||||||
end)
|
|
||||||
) do
|
) do
|
||||||
ActivityPub.create(
|
ActivityPub.create(
|
||||||
%{
|
%{
|
||||||
|
@ -284,6 +282,15 @@ def thread_muted?(user, activity) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def bookmarked?(user, activity) do
|
||||||
|
with %Bookmark{} <- Bookmark.get(user.id, activity.id) do
|
||||||
|
true
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def report(user, data) do
|
def report(user, data) do
|
||||||
with {:account_id, %{"account_id" => account_id}} <- {:account_id, data},
|
with {:account_id, %{"account_id" => account_id}} <- {:account_id, data},
|
||||||
{:account, %User{} = account} <- {:account, User.get_cached_by_id(account_id)},
|
{:account, %User{} = account} <- {:account, User.get_cached_by_id(account_id)},
|
||||||
|
|
|
@ -190,6 +190,18 @@ def format_input(text, "text/plain", options) do
|
||||||
end).()
|
end).()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Formatting text as BBCode.
|
||||||
|
"""
|
||||||
|
def format_input(text, "text/bbcode", options) do
|
||||||
|
text
|
||||||
|
|> String.replace(~r/\r/, "")
|
||||||
|
|> Formatter.html_escape("text/plain")
|
||||||
|
|> BBCode.to_html()
|
||||||
|
|> (fn {:ok, html} -> html end).()
|
||||||
|
|> Formatter.linkify(options)
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Formatting text to html.
|
Formatting text to html.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -10,12 +10,6 @@ defmodule Pleroma.Web.ControllerHelper do
|
||||||
def truthy_param?(blank_value) when blank_value in [nil, ""], do: nil
|
def truthy_param?(blank_value) when blank_value in [nil, ""], do: nil
|
||||||
def truthy_param?(value), do: value not in @falsy_param_values
|
def truthy_param?(value), do: value not in @falsy_param_values
|
||||||
|
|
||||||
def oauth_scopes(params, default) do
|
|
||||||
# Note: `scopes` is used by Mastodon — supporting it but sticking to
|
|
||||||
# OAuth's standard `scope` wherever we control it
|
|
||||||
Pleroma.Web.OAuth.parse_scopes(params["scope"] || params["scopes"], default)
|
|
||||||
end
|
|
||||||
|
|
||||||
def json_response(conn, status, json) do
|
def json_response(conn, status, json) do
|
||||||
conn
|
conn
|
||||||
|> put_status(status)
|
|> put_status(status)
|
||||||
|
|
|
@ -29,6 +29,13 @@ defmodule Pleroma.Web.Endpoint do
|
||||||
# credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
|
# credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
|
||||||
)
|
)
|
||||||
|
|
||||||
|
plug(Plug.Static.IndexHtml, at: "/pleroma/admin/")
|
||||||
|
|
||||||
|
plug(Plug.Static,
|
||||||
|
at: "/pleroma/admin/",
|
||||||
|
from: {:pleroma, "priv/static/adminfe/"}
|
||||||
|
)
|
||||||
|
|
||||||
# Code reloading can be explicitly enabled under the
|
# Code reloading can be explicitly enabled under the
|
||||||
# :code_reloader configuration of your endpoint.
|
# :code_reloader configuration of your endpoint.
|
||||||
if code_reloading? do
|
if code_reloading? do
|
||||||
|
|
|
@ -7,13 +7,10 @@ defmodule Pleroma.Web.Federator do
|
||||||
alias Pleroma.Object.Containment
|
alias Pleroma.Object.Containment
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.Relay
|
|
||||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
alias Pleroma.Web.Federator.Publisher
|
||||||
alias Pleroma.Web.Federator.RetryQueue
|
alias Pleroma.Web.Federator.RetryQueue
|
||||||
alias Pleroma.Web.OStatus
|
|
||||||
alias Pleroma.Web.Salmon
|
|
||||||
alias Pleroma.Web.WebFinger
|
alias Pleroma.Web.WebFinger
|
||||||
alias Pleroma.Web.Websub
|
alias Pleroma.Web.Websub
|
||||||
|
|
||||||
|
@ -42,14 +39,6 @@ def publish(activity, priority \\ 1) do
|
||||||
PleromaJobQueue.enqueue(:federator_outgoing, __MODULE__, [:publish, activity], priority)
|
PleromaJobQueue.enqueue(:federator_outgoing, __MODULE__, [:publish, activity], priority)
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish_single_ap(params) do
|
|
||||||
PleromaJobQueue.enqueue(:federator_outgoing, __MODULE__, [:publish_single_ap, params])
|
|
||||||
end
|
|
||||||
|
|
||||||
def publish_single_websub(websub) do
|
|
||||||
PleromaJobQueue.enqueue(:federator_outgoing, __MODULE__, [:publish_single_websub, websub])
|
|
||||||
end
|
|
||||||
|
|
||||||
def verify_websub(websub) do
|
def verify_websub(websub) do
|
||||||
PleromaJobQueue.enqueue(:federator_outgoing, __MODULE__, [:verify_websub, websub])
|
PleromaJobQueue.enqueue(:federator_outgoing, __MODULE__, [:verify_websub, websub])
|
||||||
end
|
end
|
||||||
|
@ -62,10 +51,6 @@ def refresh_subscriptions do
|
||||||
PleromaJobQueue.enqueue(:federator_outgoing, __MODULE__, [:refresh_subscriptions])
|
PleromaJobQueue.enqueue(:federator_outgoing, __MODULE__, [:refresh_subscriptions])
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish_single_salmon(params) do
|
|
||||||
PleromaJobQueue.enqueue(:federator_outgoing, __MODULE__, [:publish_single_salmon, params])
|
|
||||||
end
|
|
||||||
|
|
||||||
# Job Worker Callbacks
|
# Job Worker Callbacks
|
||||||
|
|
||||||
def perform(:refresh_subscriptions) do
|
def perform(:refresh_subscriptions) do
|
||||||
|
@ -95,23 +80,7 @@ def perform(:publish, activity) do
|
||||||
with actor when not is_nil(actor) <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
with actor when not is_nil(actor) <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
||||||
{:ok, actor} = WebFinger.ensure_keys_present(actor)
|
{:ok, actor} = WebFinger.ensure_keys_present(actor)
|
||||||
|
|
||||||
if Visibility.is_public?(activity) do
|
Publisher.publish(actor, activity)
|
||||||
if OStatus.is_representable?(activity) do
|
|
||||||
Logger.info(fn -> "Sending #{activity.data["id"]} out via WebSub" end)
|
|
||||||
Websub.publish(Pleroma.Web.OStatus.feed_path(actor), actor, activity)
|
|
||||||
|
|
||||||
Logger.info(fn -> "Sending #{activity.data["id"]} out via Salmon" end)
|
|
||||||
Pleroma.Web.Salmon.publish(actor, activity)
|
|
||||||
end
|
|
||||||
|
|
||||||
if Keyword.get(Application.get_env(:pleroma, :instance), :allow_relay) do
|
|
||||||
Logger.info(fn -> "Relaying #{activity.data["id"]} out" end)
|
|
||||||
Relay.publish(activity)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Logger.info(fn -> "Sending #{activity.data["id"]} out via AP" end)
|
|
||||||
Pleroma.Web.ActivityPub.ActivityPub.publish(actor, activity)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -148,25 +117,11 @@ def perform(:incoming_ap_doc, params) do
|
||||||
_e ->
|
_e ->
|
||||||
# Just drop those for now
|
# Just drop those for now
|
||||||
Logger.info("Unhandled activity")
|
Logger.info("Unhandled activity")
|
||||||
Logger.info(Poison.encode!(params, pretty: 2))
|
Logger.info(Jason.encode!(params, pretty: true))
|
||||||
:error
|
:error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform(:publish_single_salmon, params) do
|
|
||||||
Salmon.send_to_user(params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def perform(:publish_single_ap, params) do
|
|
||||||
case ActivityPub.publish_one(params) do
|
|
||||||
{:ok, _} ->
|
|
||||||
:ok
|
|
||||||
|
|
||||||
{:error, _} ->
|
|
||||||
RetryQueue.enqueue(params, ActivityPub)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def perform(
|
def perform(
|
||||||
:publish_single_websub,
|
:publish_single_websub,
|
||||||
%{xml: _xml, topic: _topic, callback: _callback, secret: _secret} = params
|
%{xml: _xml, topic: _topic, callback: _callback, secret: _secret} = params
|
||||||
|
|
95
lib/pleroma/web/federator/publisher.ex
Normal file
95
lib/pleroma/web/federator/publisher.ex
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.Federator.Publisher do
|
||||||
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Config
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.Federator.RetryQueue
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
|
||||||
|
@moduledoc """
|
||||||
|
Defines the contract used by federation implementations to publish messages to
|
||||||
|
their peers.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Determine whether an activity can be relayed using the federation module.
|
||||||
|
"""
|
||||||
|
@callback is_representable?(Pleroma.Activity.t()) :: boolean()
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Relays an activity to a specified peer, determined by the parameters. The
|
||||||
|
parameters used are controlled by the federation module.
|
||||||
|
"""
|
||||||
|
@callback publish_one(Map.t()) :: {:ok, Map.t()} | {:error, any()}
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Enqueue publishing a single activity.
|
||||||
|
"""
|
||||||
|
@spec enqueue_one(module(), Map.t()) :: :ok
|
||||||
|
def enqueue_one(module, %{} = params),
|
||||||
|
do: PleromaJobQueue.enqueue(:federation_outgoing, __MODULE__, [:publish_one, module, params])
|
||||||
|
|
||||||
|
@spec perform(atom(), module(), any()) :: {:ok, any()} | {:error, any()}
|
||||||
|
def perform(:publish_one, module, params) do
|
||||||
|
case apply(module, :publish_one, [params]) do
|
||||||
|
{:ok, _} ->
|
||||||
|
:ok
|
||||||
|
|
||||||
|
{:error, _e} ->
|
||||||
|
RetryQueue.enqueue(params, module)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform(type, _, _) do
|
||||||
|
Logger.debug("Unknown task: #{type}")
|
||||||
|
{:error, "Don't know what to do with this"}
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Relays an activity to all specified peers.
|
||||||
|
"""
|
||||||
|
@callback publish(Pleroma.User.t(), Pleroma.Activity.t()) :: :ok | {:error, any()}
|
||||||
|
|
||||||
|
@spec publish(Pleroma.User.t(), Pleroma.Activity.t()) :: :ok
|
||||||
|
def publish(%User{} = user, %Activity{} = activity) do
|
||||||
|
Config.get([:instance, :federation_publisher_modules])
|
||||||
|
|> Enum.each(fn module ->
|
||||||
|
if module.is_representable?(activity) do
|
||||||
|
Logger.info("Publishing #{activity.data["id"]} using #{inspect(module)}")
|
||||||
|
module.publish(user, activity)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Gathers links used by an outgoing federation module for WebFinger output.
|
||||||
|
"""
|
||||||
|
@callback gather_webfinger_links(Pleroma.User.t()) :: list()
|
||||||
|
|
||||||
|
@spec gather_webfinger_links(Pleroma.User.t()) :: list()
|
||||||
|
def gather_webfinger_links(%User{} = user) do
|
||||||
|
Config.get([:instance, :federation_publisher_modules])
|
||||||
|
|> Enum.reduce([], fn module, links ->
|
||||||
|
links ++ module.gather_webfinger_links(user)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Gathers nodeinfo protocol names supported by the federation module.
|
||||||
|
"""
|
||||||
|
@callback gather_nodeinfo_protocol_names() :: list()
|
||||||
|
|
||||||
|
@spec gather_nodeinfo_protocol_names() :: list()
|
||||||
|
def gather_nodeinfo_protocol_names do
|
||||||
|
Config.get([:instance, :federation_publisher_modules])
|
||||||
|
|> Enum.reduce([], fn module, links ->
|
||||||
|
links ++ module.gather_nodeinfo_protocol_names()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
|
@ -6,8 +6,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
use Pleroma.Web, :controller
|
use Pleroma.Web, :controller
|
||||||
alias Ecto.Changeset
|
alias Ecto.Changeset
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Bookmark
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
|
alias Pleroma.Conversation.Participation
|
||||||
alias Pleroma.Filter
|
alias Pleroma.Filter
|
||||||
|
alias Pleroma.Formatter
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Object.Fetcher
|
alias Pleroma.Object.Fetcher
|
||||||
|
@ -22,6 +25,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.MastodonAPI.AccountView
|
alias Pleroma.Web.MastodonAPI.AccountView
|
||||||
alias Pleroma.Web.MastodonAPI.AppView
|
alias Pleroma.Web.MastodonAPI.AppView
|
||||||
|
alias Pleroma.Web.MastodonAPI.ConversationView
|
||||||
alias Pleroma.Web.MastodonAPI.FilterView
|
alias Pleroma.Web.MastodonAPI.FilterView
|
||||||
alias Pleroma.Web.MastodonAPI.ListView
|
alias Pleroma.Web.MastodonAPI.ListView
|
||||||
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
||||||
|
@ -33,20 +37,31 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
alias Pleroma.Web.OAuth.App
|
alias Pleroma.Web.OAuth.App
|
||||||
alias Pleroma.Web.OAuth.Authorization
|
alias Pleroma.Web.OAuth.Authorization
|
||||||
|
alias Pleroma.Web.OAuth.Scopes
|
||||||
alias Pleroma.Web.OAuth.Token
|
alias Pleroma.Web.OAuth.Token
|
||||||
|
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||||
|
|
||||||
import Pleroma.Web.ControllerHelper, only: [oauth_scopes: 2]
|
alias Pleroma.Web.ControllerHelper
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
plug(
|
||||||
|
Pleroma.Plugs.RateLimitPlug,
|
||||||
|
%{
|
||||||
|
max_requests: Config.get([:app_account_creation, :max_requests]),
|
||||||
|
interval: Config.get([:app_account_creation, :interval])
|
||||||
|
}
|
||||||
|
when action in [:account_register]
|
||||||
|
)
|
||||||
|
|
||||||
@httpoison Application.get_env(:pleroma, :httpoison)
|
@httpoison Application.get_env(:pleroma, :httpoison)
|
||||||
@local_mastodon_name "Mastodon-Local"
|
@local_mastodon_name "Mastodon-Local"
|
||||||
|
|
||||||
action_fallback(:errors)
|
action_fallback(:errors)
|
||||||
|
|
||||||
def create_app(conn, params) do
|
def create_app(conn, params) do
|
||||||
scopes = oauth_scopes(params, ["read"])
|
scopes = Scopes.fetch_scopes(params, ["read"])
|
||||||
|
|
||||||
app_attrs =
|
app_attrs =
|
||||||
params
|
params
|
||||||
|
@ -85,7 +100,7 @@ def update_credentials(%{assigns: %{user: user}} = conn, params) do
|
||||||
user_params =
|
user_params =
|
||||||
%{}
|
%{}
|
||||||
|> add_if_present(params, "display_name", :name)
|
|> add_if_present(params, "display_name", :name)
|
||||||
|> add_if_present(params, "note", :bio, fn value -> {:ok, User.parse_bio(value)} end)
|
|> add_if_present(params, "note", :bio, fn value -> {:ok, User.parse_bio(value, user)} end)
|
||||||
|> add_if_present(params, "avatar", :avatar, fn value ->
|
|> add_if_present(params, "avatar", :avatar, fn value ->
|
||||||
with %Plug.Upload{} <- value,
|
with %Plug.Upload{} <- value,
|
||||||
{:ok, object} <- ActivityPub.upload(value, type: :avatar) do
|
{:ok, object} <- ActivityPub.upload(value, type: :avatar) do
|
||||||
|
@ -95,9 +110,20 @@ def update_credentials(%{assigns: %{user: user}} = conn, params) do
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
emojis_text = (user_params["display_name"] || "") <> (user_params["note"] || "")
|
||||||
|
|
||||||
|
user_info_emojis =
|
||||||
|
((user.info.emoji || []) ++ Formatter.get_emoji_map(emojis_text))
|
||||||
|
|> Enum.dedup()
|
||||||
|
|
||||||
info_params =
|
info_params =
|
||||||
%{}
|
[:no_rich_text, :locked, :hide_followers, :hide_follows, :hide_favorites, :show_role]
|
||||||
|> add_if_present(params, "locked", :locked, fn value -> {:ok, value == "true"} end)
|
|> Enum.reduce(%{}, fn key, acc ->
|
||||||
|
add_if_present(acc, params, to_string(key), key, fn value ->
|
||||||
|
{:ok, ControllerHelper.truthy_param?(value)}
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|> add_if_present(params, "default_scope", :default_scope)
|
||||||
|> add_if_present(params, "header", :banner, fn value ->
|
|> add_if_present(params, "header", :banner, fn value ->
|
||||||
with %Plug.Upload{} <- value,
|
with %Plug.Upload{} <- value,
|
||||||
{:ok, object} <- ActivityPub.upload(value, type: :banner) do
|
{:ok, object} <- ActivityPub.upload(value, type: :banner) do
|
||||||
|
@ -106,8 +132,9 @@ def update_credentials(%{assigns: %{user: user}} = conn, params) do
|
||||||
_ -> :error
|
_ -> :error
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|> Map.put(:emoji, user_info_emojis)
|
||||||
|
|
||||||
info_cng = User.Info.mastodon_profile_update(user.info, info_params)
|
info_cng = User.Info.profile_update(user.info, info_params)
|
||||||
|
|
||||||
with changeset <- User.update_changeset(user, user_params),
|
with changeset <- User.update_changeset(user, user_params),
|
||||||
changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng),
|
changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng),
|
||||||
|
@ -151,7 +178,7 @@ def user(%{assigns: %{user: for_user}} = conn, %{"id" => nickname_or_id}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@mastodon_api_level "2.5.0"
|
@mastodon_api_level "2.7.2"
|
||||||
|
|
||||||
def masto_instance(conn, _params) do
|
def masto_instance(conn, _params) do
|
||||||
instance = Config.get(:instance)
|
instance = Config.get(:instance)
|
||||||
|
@ -545,10 +572,9 @@ def unpin_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do
|
||||||
|
|
||||||
def bookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
def bookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
|
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
|
||||||
%Object{} = object <- Object.normalize(activity),
|
|
||||||
%User{} = user <- User.get_cached_by_nickname(user.nickname),
|
%User{} = user <- User.get_cached_by_nickname(user.nickname),
|
||||||
true <- Visibility.visible_for_user?(activity, user),
|
true <- Visibility.visible_for_user?(activity, user),
|
||||||
{:ok, user} <- User.bookmark(user, object.data["id"]) do
|
{:ok, _bookmark} <- Bookmark.create(user.id, activity.id) do
|
||||||
conn
|
conn
|
||||||
|> put_view(StatusView)
|
|> put_view(StatusView)
|
||||||
|> try_render("status.json", %{activity: activity, for: user, as: :activity})
|
|> try_render("status.json", %{activity: activity, for: user, as: :activity})
|
||||||
|
@ -557,10 +583,9 @@ def bookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
|
|
||||||
def unbookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
def unbookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
|
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
|
||||||
%Object{} = object <- Object.normalize(activity),
|
|
||||||
%User{} = user <- User.get_cached_by_nickname(user.nickname),
|
%User{} = user <- User.get_cached_by_nickname(user.nickname),
|
||||||
true <- Visibility.visible_for_user?(activity, user),
|
true <- Visibility.visible_for_user?(activity, user),
|
||||||
{:ok, user} <- User.unbookmark(user, object.data["id"]) do
|
{:ok, _bookmark} <- Bookmark.destroy(user.id, activity.id) do
|
||||||
conn
|
conn
|
||||||
|> put_view(StatusView)
|
|> put_view(StatusView)
|
||||||
|> try_render("status.json", %{activity: activity, for: user, as: :activity})
|
|> try_render("status.json", %{activity: activity, for: user, as: :activity})
|
||||||
|
@ -683,7 +708,7 @@ def upload(%{assigns: %{user: user}} = conn, %{"file" => file} = data) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def favourited_by(conn, %{"id" => id}) do
|
def favourited_by(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
with %Activity{data: %{"object" => object}} <- Repo.get(Activity, id),
|
with %Activity{data: %{"object" => object}} <- Repo.get(Activity, id),
|
||||||
%Object{data: %{"likes" => likes}} <- Object.normalize(object) do
|
%Object{data: %{"likes" => likes}} <- Object.normalize(object) do
|
||||||
q = from(u in User, where: u.ap_id in ^likes)
|
q = from(u in User, where: u.ap_id in ^likes)
|
||||||
|
@ -691,13 +716,13 @@ def favourited_by(conn, %{"id" => id}) do
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_view(AccountView)
|
|> put_view(AccountView)
|
||||||
|> render(AccountView, "accounts.json", %{users: users, as: :user})
|
|> render(AccountView, "accounts.json", %{for: user, users: users, as: :user})
|
||||||
else
|
else
|
||||||
_ -> json(conn, [])
|
_ -> json(conn, [])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def reblogged_by(conn, %{"id" => id}) do
|
def reblogged_by(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
with %Activity{data: %{"object" => object}} <- Repo.get(Activity, id),
|
with %Activity{data: %{"object" => object}} <- Repo.get(Activity, id),
|
||||||
%Object{data: %{"announcements" => announces}} <- Object.normalize(object) do
|
%Object{data: %{"announcements" => announces}} <- Object.normalize(object) do
|
||||||
q = from(u in User, where: u.ap_id in ^announces)
|
q = from(u in User, where: u.ap_id in ^announces)
|
||||||
|
@ -705,7 +730,7 @@ def reblogged_by(conn, %{"id" => id}) do
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_view(AccountView)
|
|> put_view(AccountView)
|
||||||
|> render("accounts.json", %{users: users, as: :user})
|
|> render("accounts.json", %{for: user, users: users, as: :user})
|
||||||
else
|
else
|
||||||
_ -> json(conn, [])
|
_ -> json(conn, [])
|
||||||
end
|
end
|
||||||
|
@ -762,7 +787,7 @@ def followers(%{assigns: %{user: for_user}} = conn, %{"id" => id} = params) do
|
||||||
conn
|
conn
|
||||||
|> add_link_headers(:followers, followers, user)
|
|> add_link_headers(:followers, followers, user)
|
||||||
|> put_view(AccountView)
|
|> put_view(AccountView)
|
||||||
|> render("accounts.json", %{users: followers, as: :user})
|
|> render("accounts.json", %{for: for_user, users: followers, as: :user})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -779,7 +804,7 @@ def following(%{assigns: %{user: for_user}} = conn, %{"id" => id} = params) do
|
||||||
conn
|
conn
|
||||||
|> add_link_headers(:following, followers, user)
|
|> add_link_headers(:following, followers, user)
|
||||||
|> put_view(AccountView)
|
|> put_view(AccountView)
|
||||||
|> render("accounts.json", %{users: followers, as: :user})
|
|> render("accounts.json", %{for: for_user, users: followers, as: :user})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -787,7 +812,7 @@ def follow_requests(%{assigns: %{user: followed}} = conn, _params) do
|
||||||
with {:ok, follow_requests} <- User.get_follow_requests(followed) do
|
with {:ok, follow_requests} <- User.get_follow_requests(followed) do
|
||||||
conn
|
conn
|
||||||
|> put_view(AccountView)
|
|> put_view(AccountView)
|
||||||
|> render("accounts.json", %{users: follow_requests, as: :user})
|
|> render("accounts.json", %{for: followed, users: follow_requests, as: :user})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1124,15 +1149,19 @@ def user_favourites(%{assigns: %{user: for_user}} = conn, %{"id" => id} = params
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def bookmarks(%{assigns: %{user: user}} = conn, _) do
|
def bookmarks(%{assigns: %{user: user}} = conn, params) do
|
||||||
user = User.get_cached_by_id(user.id)
|
user = User.get_cached_by_id(user.id)
|
||||||
|
|
||||||
|
bookmarks =
|
||||||
|
Bookmark.for_user_query(user.id)
|
||||||
|
|> Pagination.fetch_paginated(params)
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
user.bookmarks
|
bookmarks
|
||||||
|> Enum.map(fn id -> Activity.get_create_by_object_ap_id(id) end)
|
|> Enum.map(fn b -> Map.put(b.activity, :bookmark, Map.delete(b, :activity)) end)
|
||||||
|> Enum.reverse()
|
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|
|> add_link_headers(:bookmarks, bookmarks)
|
||||||
|> put_view(StatusView)
|
|> put_view(StatusView)
|
||||||
|> render("index.json", %{activities: activities, for: user, as: :activity})
|
|> render("index.json", %{activities: activities, for: user, as: :activity})
|
||||||
end
|
end
|
||||||
|
@ -1207,7 +1236,7 @@ def list_accounts(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
{:ok, users} = Pleroma.List.get_following(list) do
|
{:ok, users} = Pleroma.List.get_following(list) do
|
||||||
conn
|
conn
|
||||||
|> put_view(AccountView)
|
|> put_view(AccountView)
|
||||||
|> render("accounts.json", %{users: users, as: :user})
|
|> render("accounts.json", %{for: user, users: users, as: :user})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1265,8 +1294,7 @@ def index(%{assigns: %{user: user}} = conn, _params) do
|
||||||
initial_state =
|
initial_state =
|
||||||
%{
|
%{
|
||||||
meta: %{
|
meta: %{
|
||||||
streaming_api_base_url:
|
streaming_api_base_url: Pleroma.Web.Endpoint.websocket_url(),
|
||||||
String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"),
|
|
||||||
access_token: token,
|
access_token: token,
|
||||||
locale: "en",
|
locale: "en",
|
||||||
domain: Pleroma.Web.Endpoint.host(),
|
domain: Pleroma.Web.Endpoint.host(),
|
||||||
|
@ -1518,7 +1546,7 @@ def create_filter(
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
phrase: phrase,
|
phrase: phrase,
|
||||||
context: context,
|
context: context,
|
||||||
hide: Map.get(params, "irreversible", nil),
|
hide: Map.get(params, "irreversible", false),
|
||||||
whole_word: Map.get(params, "boolean", true)
|
whole_word: Map.get(params, "boolean", true)
|
||||||
# expires_at
|
# expires_at
|
||||||
}
|
}
|
||||||
|
@ -1623,7 +1651,7 @@ def suggestions(%{assigns: %{user: user}} = conn, _) do
|
||||||
x,
|
x,
|
||||||
"id",
|
"id",
|
||||||
case User.get_or_fetch(x["acct"]) do
|
case User.get_or_fetch(x["acct"]) do
|
||||||
%{id: id} -> id
|
{:ok, %User{id: id}} -> id
|
||||||
_ -> 0
|
_ -> 0
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
@ -1675,6 +1703,78 @@ def reports(%{assigns: %{user: user}} = conn, params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def account_register(
|
||||||
|
%{assigns: %{app: app}} = conn,
|
||||||
|
%{"username" => nickname, "email" => _, "password" => _, "agreement" => true} = params
|
||||||
|
) do
|
||||||
|
params =
|
||||||
|
params
|
||||||
|
|> Map.take([
|
||||||
|
"email",
|
||||||
|
"captcha_solution",
|
||||||
|
"captcha_token",
|
||||||
|
"captcha_answer_data",
|
||||||
|
"token",
|
||||||
|
"password"
|
||||||
|
])
|
||||||
|
|> Map.put("nickname", nickname)
|
||||||
|
|> Map.put("fullname", params["fullname"] || nickname)
|
||||||
|
|> Map.put("bio", params["bio"] || "")
|
||||||
|
|> Map.put("confirm", params["password"])
|
||||||
|
|
||||||
|
with {:ok, user} <- TwitterAPI.register_user(params, need_confirmation: true),
|
||||||
|
{:ok, token} <- Token.create_token(app, user, %{scopes: app.scopes}) do
|
||||||
|
json(conn, %{
|
||||||
|
token_type: "Bearer",
|
||||||
|
access_token: token.token,
|
||||||
|
scope: app.scopes,
|
||||||
|
created_at: Token.Utils.format_created_at(token)
|
||||||
|
})
|
||||||
|
else
|
||||||
|
{:error, errors} ->
|
||||||
|
conn
|
||||||
|
|> put_status(400)
|
||||||
|
|> json(Jason.encode!(errors))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def account_register(%{assigns: %{app: _app}} = conn, _params) do
|
||||||
|
conn
|
||||||
|
|> put_status(400)
|
||||||
|
|> json(%{error: "Missing parameters"})
|
||||||
|
end
|
||||||
|
|
||||||
|
def account_register(conn, _) do
|
||||||
|
conn
|
||||||
|
|> put_status(403)
|
||||||
|
|> json(%{error: "Invalid credentials"})
|
||||||
|
end
|
||||||
|
|
||||||
|
def conversations(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
participations = Participation.for_user_with_last_activity_id(user, params)
|
||||||
|
|
||||||
|
conversations =
|
||||||
|
Enum.map(participations, fn participation ->
|
||||||
|
ConversationView.render("participation.json", %{participation: participation, user: user})
|
||||||
|
end)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> add_link_headers(:conversations, participations)
|
||||||
|
|> json(conversations)
|
||||||
|
end
|
||||||
|
|
||||||
|
def conversation_read(%{assigns: %{user: user}} = conn, %{"id" => participation_id}) do
|
||||||
|
with %Participation{} = participation <-
|
||||||
|
Repo.get_by(Participation, id: participation_id, user_id: user.id),
|
||||||
|
{:ok, participation} <- Participation.mark_as_read(participation) do
|
||||||
|
participation_view =
|
||||||
|
ConversationView.render("participation.json", %{participation: participation, user: user})
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> json(participation_view)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def try_render(conn, target, params)
|
def try_render(conn, target, params)
|
||||||
when is_binary(target) do
|
when is_binary(target) do
|
||||||
res = render(conn, target, params)
|
res = render(conn, target, params)
|
||||||
|
|
|
@ -113,21 +113,23 @@ defp do_render("account.json", %{user: user} = opts) do
|
||||||
bot: bot,
|
bot: bot,
|
||||||
source: %{
|
source: %{
|
||||||
note: "",
|
note: "",
|
||||||
privacy: user_info.default_scope,
|
sensitive: false,
|
||||||
sensitive: false
|
pleroma: %{}
|
||||||
},
|
},
|
||||||
|
|
||||||
# Pleroma extension
|
# Pleroma extension
|
||||||
pleroma:
|
pleroma: %{
|
||||||
%{
|
|
||||||
confirmation_pending: user_info.confirmation_pending,
|
confirmation_pending: user_info.confirmation_pending,
|
||||||
tags: user.tags,
|
tags: user.tags,
|
||||||
is_moderator: user.info.is_moderator,
|
hide_followers: user.info.hide_followers,
|
||||||
is_admin: user.info.is_admin,
|
hide_follows: user.info.hide_follows,
|
||||||
|
hide_favorites: user.info.hide_favorites,
|
||||||
relationship: relationship
|
relationship: relationship
|
||||||
}
|
}
|
||||||
|> with_notification_settings(user, opts[:for])
|
|
||||||
}
|
}
|
||||||
|
|> maybe_put_role(user, opts[:for])
|
||||||
|
|> maybe_put_settings(user, opts[:for], user_info)
|
||||||
|
|> maybe_put_notification_settings(user, opts[:for])
|
||||||
end
|
end
|
||||||
|
|
||||||
defp username_from_nickname(string) when is_binary(string) do
|
defp username_from_nickname(string) when is_binary(string) do
|
||||||
|
@ -136,9 +138,37 @@ defp username_from_nickname(string) when is_binary(string) do
|
||||||
|
|
||||||
defp username_from_nickname(_), do: nil
|
defp username_from_nickname(_), do: nil
|
||||||
|
|
||||||
defp with_notification_settings(data, %User{id: user_id} = user, %User{id: user_id}) do
|
defp maybe_put_settings(
|
||||||
Map.put(data, :notification_settings, user.info.notification_settings)
|
data,
|
||||||
|
%User{id: user_id} = user,
|
||||||
|
%User{id: user_id},
|
||||||
|
user_info
|
||||||
|
) do
|
||||||
|
data
|
||||||
|
|> Kernel.put_in([:source, :privacy], user_info.default_scope)
|
||||||
|
|> Kernel.put_in([:source, :pleroma, :show_role], user.info.show_role)
|
||||||
|
|> Kernel.put_in([:source, :pleroma, :no_rich_text], user.info.no_rich_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp with_notification_settings(data, _, _), do: data
|
defp maybe_put_settings(data, _, _, _), do: data
|
||||||
|
|
||||||
|
defp maybe_put_role(data, %User{info: %{show_role: true}} = user, _) do
|
||||||
|
data
|
||||||
|
|> Kernel.put_in([:pleroma, :is_admin], user.info.is_admin)
|
||||||
|
|> Kernel.put_in([:pleroma, :is_moderator], user.info.is_moderator)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp maybe_put_role(data, %User{id: user_id} = user, %User{id: user_id}) do
|
||||||
|
data
|
||||||
|
|> Kernel.put_in([:pleroma, :is_admin], user.info.is_admin)
|
||||||
|
|> Kernel.put_in([:pleroma, :is_moderator], user.info.is_moderator)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp maybe_put_role(data, _, _), do: data
|
||||||
|
|
||||||
|
defp maybe_put_notification_settings(data, %User{id: user_id} = user, %User{id: user_id}) do
|
||||||
|
Kernel.put_in(data, [:pleroma, :notification_settings], user.info.notification_settings)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp maybe_put_notification_settings(data, _, _), do: data
|
||||||
end
|
end
|
||||||
|
|
38
lib/pleroma/web/mastodon_api/views/conversation_view.ex
Normal file
38
lib/pleroma/web/mastodon_api/views/conversation_view.ex
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
defmodule Pleroma.Web.MastodonAPI.ConversationView do
|
||||||
|
use Pleroma.Web, :view
|
||||||
|
|
||||||
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
alias Pleroma.Web.MastodonAPI.AccountView
|
||||||
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
|
|
||||||
|
def render("participation.json", %{participation: participation, user: user}) do
|
||||||
|
participation = Repo.preload(participation, conversation: :users)
|
||||||
|
|
||||||
|
last_activity_id =
|
||||||
|
with nil <- participation.last_activity_id do
|
||||||
|
ActivityPub.fetch_latest_activity_id_for_context(participation.conversation.ap_id, %{
|
||||||
|
"user" => user,
|
||||||
|
"blocking_user" => user
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
activity = Activity.get_by_id_with_object(last_activity_id)
|
||||||
|
|
||||||
|
last_status = StatusView.render("status.json", %{activity: activity, for: user})
|
||||||
|
|
||||||
|
accounts =
|
||||||
|
AccountView.render("accounts.json", %{
|
||||||
|
users: participation.conversation.users,
|
||||||
|
as: :user
|
||||||
|
})
|
||||||
|
|
||||||
|
%{
|
||||||
|
id: participation.id |> to_string(),
|
||||||
|
accounts: accounts,
|
||||||
|
unread: !participation.read,
|
||||||
|
last_status: last_status
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
|
@ -75,17 +75,22 @@ def render("index.json", opts) do
|
||||||
|
|
||||||
def render(
|
def render(
|
||||||
"status.json",
|
"status.json",
|
||||||
%{activity: %{data: %{"type" => "Announce", "object" => object}} = activity} = opts
|
%{activity: %{data: %{"type" => "Announce", "object" => _object}} = activity} = opts
|
||||||
) do
|
) do
|
||||||
user = get_user(activity.data["actor"])
|
user = get_user(activity.data["actor"])
|
||||||
created_at = Utils.to_masto_date(activity.data["published"])
|
created_at = Utils.to_masto_date(activity.data["published"])
|
||||||
|
activity_object = Object.normalize(activity)
|
||||||
|
|
||||||
|
reblogged_activity =
|
||||||
|
Activity.create_by_object_ap_id(activity_object.data["id"])
|
||||||
|
|> Activity.with_preloaded_bookmark(opts[:for])
|
||||||
|
|> Repo.one()
|
||||||
|
|
||||||
reblogged_activity = Activity.get_create_by_object_ap_id(object)
|
|
||||||
reblogged = render("status.json", Map.put(opts, :activity, reblogged_activity))
|
reblogged = render("status.json", Map.put(opts, :activity, reblogged_activity))
|
||||||
|
|
||||||
activity_object = Object.normalize(activity)
|
|
||||||
favorited = opts[:for] && opts[:for].ap_id in (activity_object.data["likes"] || [])
|
favorited = opts[:for] && opts[:for].ap_id in (activity_object.data["likes"] || [])
|
||||||
bookmarked = opts[:for] && activity_object.data["id"] in opts[:for].bookmarks
|
|
||||||
|
bookmarked = Activity.get_bookmark(reblogged_activity, opts[:for]) != nil
|
||||||
|
|
||||||
mentions =
|
mentions =
|
||||||
activity.recipients
|
activity.recipients
|
||||||
|
@ -95,8 +100,8 @@ def render(
|
||||||
|
|
||||||
%{
|
%{
|
||||||
id: to_string(activity.id),
|
id: to_string(activity.id),
|
||||||
uri: object,
|
uri: activity_object.data["id"],
|
||||||
url: object,
|
url: activity_object.data["id"],
|
||||||
account: AccountView.render("account.json", %{user: user}),
|
account: AccountView.render("account.json", %{user: user}),
|
||||||
in_reply_to_id: nil,
|
in_reply_to_id: nil,
|
||||||
in_reply_to_account_id: nil,
|
in_reply_to_account_id: nil,
|
||||||
|
@ -148,7 +153,7 @@ def render("status.json", %{activity: %{data: %{"object" => _object}} = activity
|
||||||
|
|
||||||
favorited = opts[:for] && opts[:for].ap_id in (object.data["likes"] || [])
|
favorited = opts[:for] && opts[:for].ap_id in (object.data["likes"] || [])
|
||||||
|
|
||||||
bookmarked = opts[:for] && object.data["id"] in opts[:for].bookmarks
|
bookmarked = Activity.get_bookmark(activity, opts[:for]) != nil
|
||||||
|
|
||||||
attachment_data = object.data["attachment"] || []
|
attachment_data = object.data["attachment"] || []
|
||||||
attachments = render_many(attachment_data, StatusView, "attachment.json", as: :attachment)
|
attachments = render_many(attachment_data, StatusView, "attachment.json", as: :attachment)
|
||||||
|
|
|
@ -13,10 +13,23 @@ def url("/" <> _ = url), do: url
|
||||||
|
|
||||||
def url(url) do
|
def url(url) do
|
||||||
config = Application.get_env(:pleroma, :media_proxy, [])
|
config = Application.get_env(:pleroma, :media_proxy, [])
|
||||||
|
domain = URI.parse(url).host
|
||||||
|
|
||||||
if !Keyword.get(config, :enabled, false) or String.starts_with?(url, Pleroma.Web.base_url()) do
|
cond do
|
||||||
|
!Keyword.get(config, :enabled, false) or String.starts_with?(url, Pleroma.Web.base_url()) ->
|
||||||
url
|
url
|
||||||
else
|
|
||||||
|
Enum.any?(Pleroma.Config.get([:media_proxy, :whitelist]), fn pattern ->
|
||||||
|
String.equivalent?(domain, pattern)
|
||||||
|
end) ->
|
||||||
|
url
|
||||||
|
|
||||||
|
true ->
|
||||||
|
encode_url(url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def encode_url(url) do
|
||||||
secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base]
|
secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base]
|
||||||
|
|
||||||
# Must preserve `%2F` for compatibility with S3
|
# Must preserve `%2F` for compatibility with S3
|
||||||
|
@ -37,7 +50,6 @@ def url(url) do
|
||||||
|
|
||||||
build_url(sig64, base64, filename(url))
|
build_url(sig64, base64, filename(url))
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def decode_url(sig, url) do
|
def decode_url(sig, url) do
|
||||||
secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base]
|
secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base]
|
||||||
|
|
|
@ -10,6 +10,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web
|
alias Pleroma.Web
|
||||||
alias Pleroma.Web.ActivityPub.MRF
|
alias Pleroma.Web.ActivityPub.MRF
|
||||||
|
alias Pleroma.Web.Federator.Publisher
|
||||||
|
|
||||||
plug(Pleroma.Web.FederatingPlug)
|
plug(Pleroma.Web.FederatingPlug)
|
||||||
|
|
||||||
|
@ -137,7 +138,7 @@ def raw_nodeinfo do
|
||||||
name: Pleroma.Application.name() |> String.downcase(),
|
name: Pleroma.Application.name() |> String.downcase(),
|
||||||
version: Pleroma.Application.version()
|
version: Pleroma.Application.version()
|
||||||
},
|
},
|
||||||
protocols: ["ostatus", "activitypub"],
|
protocols: Publisher.gather_nodeinfo_protocol_names(),
|
||||||
services: %{
|
services: %{
|
||||||
inbound: [],
|
inbound: [],
|
||||||
outbound: []
|
outbound: []
|
||||||
|
|
|
@ -3,18 +3,4 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.OAuth do
|
defmodule Pleroma.Web.OAuth do
|
||||||
def parse_scopes(scopes, _default) when is_list(scopes) do
|
|
||||||
Enum.filter(scopes, &(&1 not in [nil, ""]))
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse_scopes(scopes, default) when is_binary(scopes) do
|
|
||||||
scopes
|
|
||||||
|> String.trim()
|
|
||||||
|> String.split(~r/[\s,]+/)
|
|
||||||
|> parse_scopes(default)
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse_scopes(_, default) do
|
|
||||||
default
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Web.OAuth.App do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
schema "apps" do
|
schema "apps" do
|
||||||
field(:client_name, :string)
|
field(:client_name, :string)
|
||||||
field(:redirect_uris, :string)
|
field(:redirect_uris, :string)
|
||||||
|
|
|
@ -13,6 +13,8 @@ defmodule Pleroma.Web.OAuth.Authorization do
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
schema "oauth_authorizations" do
|
schema "oauth_authorizations" do
|
||||||
field(:token, :string)
|
field(:token, :string)
|
||||||
field(:scopes, {:array, :string}, default: [])
|
field(:scopes, {:array, :string}, default: [])
|
||||||
|
@ -24,28 +26,45 @@ defmodule Pleroma.Web.OAuth.Authorization do
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec create_authorization(App.t(), User.t() | %{}, [String.t()] | nil) ::
|
||||||
|
{:ok, Authorization.t()} | {:error, Changeset.t()}
|
||||||
def create_authorization(%App{} = app, %User{} = user, scopes \\ nil) do
|
def create_authorization(%App{} = app, %User{} = user, scopes \\ nil) do
|
||||||
scopes = scopes || app.scopes
|
%{
|
||||||
token = :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
|
scopes: scopes || app.scopes,
|
||||||
|
|
||||||
authorization = %Authorization{
|
|
||||||
token: token,
|
|
||||||
used: false,
|
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
app_id: app.id,
|
app_id: app.id
|
||||||
scopes: scopes,
|
|
||||||
valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10)
|
|
||||||
}
|
}
|
||||||
|
|> create_changeset()
|
||||||
Repo.insert(authorization)
|
|> Repo.insert()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec create_changeset(map()) :: Changeset.t()
|
||||||
|
def create_changeset(attrs \\ %{}) do
|
||||||
|
%Authorization{}
|
||||||
|
|> cast(attrs, [:user_id, :app_id, :scopes, :valid_until])
|
||||||
|
|> validate_required([:app_id, :scopes])
|
||||||
|
|> add_token()
|
||||||
|
|> add_lifetime()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp add_token(changeset) do
|
||||||
|
token = :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
|
||||||
|
put_change(changeset, :token, token)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp add_lifetime(changeset) do
|
||||||
|
put_change(changeset, :valid_until, NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10))
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec use_changeset(Authtorizatiton.t(), map()) :: Changeset.t()
|
||||||
def use_changeset(%Authorization{} = auth, params) do
|
def use_changeset(%Authorization{} = auth, params) do
|
||||||
auth
|
auth
|
||||||
|> cast(params, [:used])
|
|> cast(params, [:used])
|
||||||
|> validate_required([:used])
|
|> validate_required([:used])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec use_token(Authorization.t()) ::
|
||||||
|
{:ok, Authorization.t()} | {:error, Changeset.t()} | {:error, String.t()}
|
||||||
def use_token(%Authorization{used: false, valid_until: valid_until} = auth) do
|
def use_token(%Authorization{used: false, valid_until: valid_until} = auth) do
|
||||||
if NaiveDateTime.diff(NaiveDateTime.utc_now(), valid_until) < 0 do
|
if NaiveDateTime.diff(NaiveDateTime.utc_now(), valid_until) < 0 do
|
||||||
Repo.update(use_changeset(auth, %{used: true}))
|
Repo.update(use_changeset(auth, %{used: true}))
|
||||||
|
@ -56,6 +75,7 @@ def use_token(%Authorization{used: false, valid_until: valid_until} = auth) do
|
||||||
|
|
||||||
def use_token(%Authorization{used: true}), do: {:error, "already used"}
|
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
|
def delete_user_authorizations(%User{id: user_id}) do
|
||||||
from(
|
from(
|
||||||
a in Pleroma.Web.OAuth.Authorization,
|
a in Pleroma.Web.OAuth.Authorization,
|
||||||
|
@ -63,4 +83,11 @@ def delete_user_authorizations(%User{id: user_id}) do
|
||||||
)
|
)
|
||||||
|> Repo.delete_all()
|
|> Repo.delete_all()
|
||||||
end
|
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
|
||||||
|
from(t in __MODULE__, where: t.app_id == ^app_id and t.token == ^token)
|
||||||
|
|> Repo.find_resource()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,11 +13,14 @@ defmodule Pleroma.Web.OAuth.OAuthController do
|
||||||
alias Pleroma.Web.OAuth.App
|
alias Pleroma.Web.OAuth.App
|
||||||
alias Pleroma.Web.OAuth.Authorization
|
alias Pleroma.Web.OAuth.Authorization
|
||||||
alias Pleroma.Web.OAuth.Token
|
alias Pleroma.Web.OAuth.Token
|
||||||
|
alias Pleroma.Web.OAuth.Token.Strategy.RefreshToken
|
||||||
import Pleroma.Web.ControllerHelper, only: [oauth_scopes: 2]
|
alias Pleroma.Web.OAuth.Token.Strategy.Revoke, as: RevokeToken
|
||||||
|
alias Pleroma.Web.OAuth.Scopes
|
||||||
|
|
||||||
if Pleroma.Config.oauth_consumer_enabled?(), do: plug(Ueberauth)
|
if Pleroma.Config.oauth_consumer_enabled?(), do: plug(Ueberauth)
|
||||||
|
|
||||||
|
@expires_in Pleroma.Config.get([:oauth2, :token_expires_in], 600)
|
||||||
|
|
||||||
plug(:fetch_session)
|
plug(:fetch_session)
|
||||||
plug(:fetch_flash)
|
plug(:fetch_flash)
|
||||||
|
|
||||||
|
@ -53,7 +56,7 @@ def authorize(conn, params), do: do_authorize(conn, params)
|
||||||
defp do_authorize(conn, params) do
|
defp do_authorize(conn, params) do
|
||||||
app = Repo.get_by(App, client_id: params["client_id"])
|
app = Repo.get_by(App, client_id: params["client_id"])
|
||||||
available_scopes = (app && app.scopes) || []
|
available_scopes = (app && app.scopes) || []
|
||||||
scopes = oauth_scopes(params, nil) || available_scopes
|
scopes = Scopes.fetch_scopes(params, available_scopes)
|
||||||
|
|
||||||
# Note: `params` might differ from `conn.params`; use `@params` not `@conn.params` in template
|
# Note: `params` might differ from `conn.params`; use `@params` not `@conn.params` in template
|
||||||
render(conn, Authenticator.auth_template(), %{
|
render(conn, Authenticator.auth_template(), %{
|
||||||
|
@ -109,7 +112,7 @@ def after_create_authorization(conn, auth, %{
|
||||||
|
|
||||||
defp handle_create_authorization_error(
|
defp handle_create_authorization_error(
|
||||||
conn,
|
conn,
|
||||||
{scopes_issue, _},
|
{:error, scopes_issue},
|
||||||
%{"authorization" => _} = params
|
%{"authorization" => _} = params
|
||||||
)
|
)
|
||||||
when scopes_issue in [:unsupported_scopes, :missing_scopes] do
|
when scopes_issue in [:unsupported_scopes, :missing_scopes] do
|
||||||
|
@ -138,25 +141,33 @@ defp handle_create_authorization_error(conn, error, %{"authorization" => _}) do
|
||||||
Authenticator.handle_error(conn, error)
|
Authenticator.handle_error(conn, error)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc "Renew access_token with refresh_token"
|
||||||
|
def token_exchange(
|
||||||
|
conn,
|
||||||
|
%{"grant_type" => "refresh_token", "refresh_token" => token} = params
|
||||||
|
) do
|
||||||
|
with %App{} = app <- get_app_from_request(conn, params),
|
||||||
|
{:ok, %{user: user} = token} <- Token.get_by_refresh_token(app, token),
|
||||||
|
{:ok, token} <- RefreshToken.grant(token) do
|
||||||
|
response_attrs = %{created_at: Token.Utils.format_created_at(token)}
|
||||||
|
|
||||||
|
json(conn, response_token(user, token, response_attrs))
|
||||||
|
else
|
||||||
|
_error ->
|
||||||
|
put_status(conn, 400)
|
||||||
|
|> json(%{error: "Invalid credentials"})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def token_exchange(conn, %{"grant_type" => "authorization_code"} = params) do
|
def token_exchange(conn, %{"grant_type" => "authorization_code"} = params) do
|
||||||
with %App{} = app <- get_app_from_request(conn, params),
|
with %App{} = app <- get_app_from_request(conn, params),
|
||||||
fixed_token = fix_padding(params["code"]),
|
fixed_token = Token.Utils.fix_padding(params["code"]),
|
||||||
%Authorization{} = auth <-
|
{:ok, auth} <- Authorization.get_by_token(app, fixed_token),
|
||||||
Repo.get_by(Authorization, token: fixed_token, app_id: app.id),
|
|
||||||
%User{} = user <- User.get_cached_by_id(auth.user_id),
|
%User{} = user <- User.get_cached_by_id(auth.user_id),
|
||||||
{:ok, token} <- Token.exchange_token(app, auth),
|
{:ok, token} <- Token.exchange_token(app, auth) do
|
||||||
{:ok, inserted_at} <- DateTime.from_naive(token.inserted_at, "Etc/UTC") do
|
response_attrs = %{created_at: Token.Utils.format_created_at(token)}
|
||||||
response = %{
|
|
||||||
token_type: "Bearer",
|
|
||||||
access_token: token.token,
|
|
||||||
refresh_token: token.refresh_token,
|
|
||||||
created_at: DateTime.to_unix(inserted_at),
|
|
||||||
expires_in: 60 * 10,
|
|
||||||
scope: Enum.join(token.scopes, " "),
|
|
||||||
me: user.ap_id
|
|
||||||
}
|
|
||||||
|
|
||||||
json(conn, response)
|
json(conn, response_token(user, token, response_attrs))
|
||||||
else
|
else
|
||||||
_error ->
|
_error ->
|
||||||
put_status(conn, 400)
|
put_status(conn, 400)
|
||||||
|
@ -172,21 +183,10 @@ def token_exchange(
|
||||||
%App{} = app <- get_app_from_request(conn, params),
|
%App{} = app <- get_app_from_request(conn, params),
|
||||||
{:auth_active, true} <- {:auth_active, User.auth_active?(user)},
|
{:auth_active, true} <- {:auth_active, User.auth_active?(user)},
|
||||||
{:user_active, true} <- {:user_active, !user.info.deactivated},
|
{:user_active, true} <- {:user_active, !user.info.deactivated},
|
||||||
scopes <- oauth_scopes(params, app.scopes),
|
{:ok, scopes} <- validate_scopes(app, params),
|
||||||
[] <- scopes -- app.scopes,
|
|
||||||
true <- Enum.any?(scopes),
|
|
||||||
{:ok, auth} <- Authorization.create_authorization(app, user, scopes),
|
{:ok, auth} <- Authorization.create_authorization(app, user, scopes),
|
||||||
{:ok, token} <- Token.exchange_token(app, auth) do
|
{:ok, token} <- Token.exchange_token(app, auth) do
|
||||||
response = %{
|
json(conn, response_token(user, token))
|
||||||
token_type: "Bearer",
|
|
||||||
access_token: token.token,
|
|
||||||
refresh_token: token.refresh_token,
|
|
||||||
expires_in: 60 * 10,
|
|
||||||
scope: Enum.join(token.scopes, " "),
|
|
||||||
me: user.ap_id
|
|
||||||
}
|
|
||||||
|
|
||||||
json(conn, response)
|
|
||||||
else
|
else
|
||||||
{:auth_active, false} ->
|
{:auth_active, false} ->
|
||||||
# Per https://github.com/tootsuite/mastodon/blob/
|
# Per https://github.com/tootsuite/mastodon/blob/
|
||||||
|
@ -218,10 +218,34 @@ def token_exchange(
|
||||||
token_exchange(conn, params)
|
token_exchange(conn, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def token_revoke(conn, %{"token" => token} = params) do
|
def token_exchange(conn, %{"grant_type" => "client_credentials"} = params) do
|
||||||
with %App{} = app <- get_app_from_request(conn, params),
|
with %App{} = app <- get_app_from_request(conn, params),
|
||||||
%Token{} = token <- Repo.get_by(Token, token: token, app_id: app.id),
|
{:ok, auth} <- Authorization.create_authorization(app, %User{}),
|
||||||
{:ok, %Token{}} <- Repo.delete(token) do
|
{:ok, token} <- Token.exchange_token(app, auth),
|
||||||
|
{:ok, inserted_at} <- DateTime.from_naive(token.inserted_at, "Etc/UTC") do
|
||||||
|
response = %{
|
||||||
|
token_type: "Bearer",
|
||||||
|
access_token: token.token,
|
||||||
|
refresh_token: token.refresh_token,
|
||||||
|
created_at: DateTime.to_unix(inserted_at),
|
||||||
|
expires_in: 60 * 10,
|
||||||
|
scope: Enum.join(token.scopes, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
json(conn, response)
|
||||||
|
else
|
||||||
|
_error ->
|
||||||
|
put_status(conn, 400)
|
||||||
|
|> json(%{error: "Invalid credentials"})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Bad request
|
||||||
|
def token_exchange(conn, params), do: bad_request(conn, params)
|
||||||
|
|
||||||
|
def token_revoke(conn, %{"token" => _token} = params) do
|
||||||
|
with %App{} = app <- get_app_from_request(conn, params),
|
||||||
|
{:ok, _token} <- RevokeToken.revoke(app, params) do
|
||||||
json(conn, %{})
|
json(conn, %{})
|
||||||
else
|
else
|
||||||
_error ->
|
_error ->
|
||||||
|
@ -230,17 +254,27 @@ def token_revoke(conn, %{"token" => token} = params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def token_revoke(conn, params), do: bad_request(conn, params)
|
||||||
|
|
||||||
|
# Response for bad request
|
||||||
|
defp bad_request(conn, _) do
|
||||||
|
conn
|
||||||
|
|> put_status(500)
|
||||||
|
|> json(%{error: "Bad request"})
|
||||||
|
end
|
||||||
|
|
||||||
@doc "Prepares OAuth request to provider for Ueberauth"
|
@doc "Prepares OAuth request to provider for Ueberauth"
|
||||||
def prepare_request(conn, %{"provider" => provider, "authorization" => auth_attrs}) do
|
def prepare_request(conn, %{"provider" => provider, "authorization" => auth_attrs}) do
|
||||||
scope =
|
scope =
|
||||||
oauth_scopes(auth_attrs, [])
|
auth_attrs
|
||||||
|> Enum.join(" ")
|
|> Scopes.fetch_scopes([])
|
||||||
|
|> Scopes.to_string()
|
||||||
|
|
||||||
state =
|
state =
|
||||||
auth_attrs
|
auth_attrs
|
||||||
|> Map.delete("scopes")
|
|> Map.delete("scopes")
|
||||||
|> Map.put("scope", scope)
|
|> Map.put("scope", scope)
|
||||||
|> Poison.encode!()
|
|> Jason.encode!()
|
||||||
|
|
||||||
params =
|
params =
|
||||||
auth_attrs
|
auth_attrs
|
||||||
|
@ -278,16 +312,13 @@ def callback(conn, params) do
|
||||||
params = callback_params(params)
|
params = callback_params(params)
|
||||||
|
|
||||||
with {:ok, registration} <- Authenticator.get_registration(conn) do
|
with {:ok, registration} <- Authenticator.get_registration(conn) do
|
||||||
user = Repo.preload(registration, :user).user
|
|
||||||
auth_attrs = Map.take(params, ~w(client_id redirect_uri scope scopes state))
|
auth_attrs = Map.take(params, ~w(client_id redirect_uri scope scopes state))
|
||||||
|
|
||||||
if user do
|
case Repo.get_assoc(registration, :user) do
|
||||||
create_authorization(
|
{:ok, user} ->
|
||||||
conn,
|
create_authorization(conn, %{"authorization" => auth_attrs}, user: user)
|
||||||
%{"authorization" => auth_attrs},
|
|
||||||
user: user
|
_ ->
|
||||||
)
|
|
||||||
else
|
|
||||||
registration_params =
|
registration_params =
|
||||||
Map.merge(auth_attrs, %{
|
Map.merge(auth_attrs, %{
|
||||||
"nickname" => Registration.nickname(registration),
|
"nickname" => Registration.nickname(registration),
|
||||||
|
@ -307,7 +338,7 @@ def callback(conn, params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp callback_params(%{"state" => state} = params) do
|
defp callback_params(%{"state" => state} = params) do
|
||||||
Map.merge(params, Poison.decode!(state))
|
Map.merge(params, Jason.decode!(state))
|
||||||
end
|
end
|
||||||
|
|
||||||
def registration_details(conn, %{"authorization" => auth_attrs}) do
|
def registration_details(conn, %{"authorization" => auth_attrs}) do
|
||||||
|
@ -315,7 +346,7 @@ def registration_details(conn, %{"authorization" => auth_attrs}) do
|
||||||
client_id: auth_attrs["client_id"],
|
client_id: auth_attrs["client_id"],
|
||||||
redirect_uri: auth_attrs["redirect_uri"],
|
redirect_uri: auth_attrs["redirect_uri"],
|
||||||
state: auth_attrs["state"],
|
state: auth_attrs["state"],
|
||||||
scopes: oauth_scopes(auth_attrs, []),
|
scopes: Scopes.fetch_scopes(auth_attrs, []),
|
||||||
nickname: auth_attrs["nickname"],
|
nickname: auth_attrs["nickname"],
|
||||||
email: auth_attrs["email"]
|
email: auth_attrs["email"]
|
||||||
})
|
})
|
||||||
|
@ -390,46 +421,37 @@ defp do_create_authorization(
|
||||||
{:get_user, (user && {:ok, user}) || Authenticator.get_user(conn)},
|
{:get_user, (user && {:ok, user}) || Authenticator.get_user(conn)},
|
||||||
%App{} = app <- Repo.get_by(App, client_id: client_id),
|
%App{} = app <- Repo.get_by(App, client_id: client_id),
|
||||||
true <- redirect_uri in String.split(app.redirect_uris),
|
true <- redirect_uri in String.split(app.redirect_uris),
|
||||||
scopes <- oauth_scopes(auth_attrs, []),
|
{:ok, scopes} <- validate_scopes(app, auth_attrs),
|
||||||
{:unsupported_scopes, []} <- {:unsupported_scopes, scopes -- app.scopes},
|
|
||||||
# Note: `scope` param is intentionally not optional in this context
|
|
||||||
{:missing_scopes, false} <- {:missing_scopes, scopes == []},
|
|
||||||
{:auth_active, true} <- {:auth_active, User.auth_active?(user)} do
|
{:auth_active, true} <- {:auth_active, User.auth_active?(user)} do
|
||||||
Authorization.create_authorization(app, user, scopes)
|
Authorization.create_authorization(app, user, scopes)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# XXX - for whatever reason our token arrives urlencoded, but Plug.Conn should be
|
defp get_app_from_request(conn, params) do
|
||||||
# decoding it. Investigate sometime.
|
conn
|
||||||
defp fix_padding(token) do
|
|> fetch_client_credentials(params)
|
||||||
token
|
|> fetch_client
|
||||||
|> URI.decode()
|
|
||||||
|> Base.url_decode64!(padding: false)
|
|
||||||
|> Base.url_encode64(padding: false)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_app_from_request(conn, params) do
|
defp fetch_client({id, secret}) when is_binary(id) and is_binary(secret) do
|
||||||
|
Repo.get_by(App, client_id: id, client_secret: secret)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp fetch_client({_id, _secret}), do: nil
|
||||||
|
|
||||||
|
defp fetch_client_credentials(conn, params) do
|
||||||
# Per RFC 6749, HTTP Basic is preferred to body params
|
# Per RFC 6749, HTTP Basic is preferred to body params
|
||||||
{client_id, client_secret} =
|
|
||||||
with ["Basic " <> encoded] <- get_req_header(conn, "authorization"),
|
with ["Basic " <> encoded] <- get_req_header(conn, "authorization"),
|
||||||
{:ok, decoded} <- Base.decode64(encoded),
|
{:ok, decoded} <- Base.decode64(encoded),
|
||||||
[id, secret] <-
|
[id, secret] <-
|
||||||
String.split(decoded, ":")
|
Enum.map(
|
||||||
|> Enum.map(fn s -> URI.decode_www_form(s) end) do
|
String.split(decoded, ":"),
|
||||||
|
fn s -> URI.decode_www_form(s) end
|
||||||
|
) do
|
||||||
{id, secret}
|
{id, secret}
|
||||||
else
|
else
|
||||||
_ -> {params["client_id"], params["client_secret"]}
|
_ -> {params["client_id"], params["client_secret"]}
|
||||||
end
|
end
|
||||||
|
|
||||||
if client_id && client_secret do
|
|
||||||
Repo.get_by(
|
|
||||||
App,
|
|
||||||
client_id: client_id,
|
|
||||||
client_secret: client_secret
|
|
||||||
)
|
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Special case: Local MastodonFE
|
# Special case: Local MastodonFE
|
||||||
|
@ -441,4 +463,24 @@ defp get_session_registration_id(conn), do: get_session(conn, :registration_id)
|
||||||
|
|
||||||
defp put_session_registration_id(conn, registration_id),
|
defp put_session_registration_id(conn, registration_id),
|
||||||
do: put_session(conn, :registration_id, registration_id)
|
do: put_session(conn, :registration_id, registration_id)
|
||||||
|
|
||||||
|
defp response_token(%User{} = user, token, opts \\ %{}) do
|
||||||
|
%{
|
||||||
|
token_type: "Bearer",
|
||||||
|
access_token: token.token,
|
||||||
|
refresh_token: token.refresh_token,
|
||||||
|
expires_in: @expires_in,
|
||||||
|
scope: Enum.join(token.scopes, " "),
|
||||||
|
me: user.ap_id
|
||||||
|
}
|
||||||
|
|> Map.merge(opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec validate_scopes(App.t(), map()) ::
|
||||||
|
{:ok, list()} | {:error, :missing_scopes | :unsupported_scopes}
|
||||||
|
defp validate_scopes(app, params) do
|
||||||
|
params
|
||||||
|
|> Scopes.fetch_scopes(app.scopes)
|
||||||
|
|> Scopes.validates(app.scopes)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
67
lib/pleroma/web/oauth/scopes.ex
Normal file
67
lib/pleroma/web/oauth/scopes.ex
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.OAuth.Scopes do
|
||||||
|
@moduledoc """
|
||||||
|
Functions for dealing with scopes.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Fetch scopes from requiest params.
|
||||||
|
|
||||||
|
Note: `scopes` is used by Mastodon — supporting it but sticking to
|
||||||
|
OAuth's standard `scope` wherever we control it
|
||||||
|
"""
|
||||||
|
@spec fetch_scopes(map(), list()) :: list()
|
||||||
|
def fetch_scopes(params, default) do
|
||||||
|
parse_scopes(params["scope"] || params["scopes"], default)
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_scopes(scopes, _default) when is_list(scopes) do
|
||||||
|
Enum.filter(scopes, &(&1 not in [nil, ""]))
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_scopes(scopes, default) when is_binary(scopes) do
|
||||||
|
scopes
|
||||||
|
|> to_list
|
||||||
|
|> parse_scopes(default)
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_scopes(_, default) do
|
||||||
|
default
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Convert scopes string to list
|
||||||
|
"""
|
||||||
|
@spec to_list(binary()) :: [binary()]
|
||||||
|
def to_list(nil), do: []
|
||||||
|
|
||||||
|
def to_list(str) do
|
||||||
|
str
|
||||||
|
|> String.trim()
|
||||||
|
|> String.split(~r/[\s,]+/)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Convert scopes list to string
|
||||||
|
"""
|
||||||
|
@spec to_string(list()) :: binary()
|
||||||
|
def to_string(scopes), do: Enum.join(scopes, " ")
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Validates scopes.
|
||||||
|
"""
|
||||||
|
@spec validates(list() | nil, list()) ::
|
||||||
|
{:ok, list()} | {:error, :missing_scopes | :unsupported_scopes}
|
||||||
|
def validates([], _app_scopes), do: {:error, :missing_scopes}
|
||||||
|
def validates(nil, _app_scopes), do: {:error, :missing_scopes}
|
||||||
|
|
||||||
|
def validates(scopes, app_scopes) do
|
||||||
|
case scopes -- app_scopes do
|
||||||
|
[] -> {:ok, scopes}
|
||||||
|
_ -> {:error, :unsupported_scopes}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.OAuth.Token do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
@ -13,6 +14,9 @@ defmodule Pleroma.Web.OAuth.Token do
|
||||||
alias Pleroma.Web.OAuth.Authorization
|
alias Pleroma.Web.OAuth.Authorization
|
||||||
alias Pleroma.Web.OAuth.Token
|
alias Pleroma.Web.OAuth.Token
|
||||||
|
|
||||||
|
@expires_in Pleroma.Config.get([:oauth2, :token_expires_in], 600)
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
schema "oauth_tokens" do
|
schema "oauth_tokens" do
|
||||||
field(:token, :string)
|
field(:token, :string)
|
||||||
field(:refresh_token, :string)
|
field(:refresh_token, :string)
|
||||||
|
@ -24,28 +28,72 @@ defmodule Pleroma.Web.OAuth.Token do
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc "Gets token for app by access 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
|
||||||
|
from(t in __MODULE__, where: t.app_id == ^app_id and t.token == ^token)
|
||||||
|
|> Repo.find_resource()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc "Gets token for app by refresh token"
|
||||||
|
@spec get_by_refresh_token(App.t(), String.t()) :: {:ok, t()} | {:error, :not_found}
|
||||||
|
def get_by_refresh_token(%App{id: app_id} = _app, token) do
|
||||||
|
from(t in __MODULE__,
|
||||||
|
where: t.app_id == ^app_id and t.refresh_token == ^token,
|
||||||
|
preload: [:user]
|
||||||
|
)
|
||||||
|
|> Repo.find_resource()
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec exchange_token(App.t(), Authorization.t()) ::
|
||||||
|
{:ok, Token.t()} | {:error, Changeset.t()}
|
||||||
def exchange_token(app, auth) do
|
def exchange_token(app, auth) do
|
||||||
with {:ok, auth} <- Authorization.use_token(auth),
|
with {:ok, auth} <- Authorization.use_token(auth),
|
||||||
true <- auth.app_id == app.id do
|
true <- auth.app_id == app.id do
|
||||||
create_token(app, User.get_cached_by_id(auth.user_id), auth.scopes)
|
user = if auth.user_id, do: User.get_cached_by_id(auth.user_id), else: %User{}
|
||||||
|
|
||||||
|
create_token(
|
||||||
|
app,
|
||||||
|
user,
|
||||||
|
%{scopes: auth.scopes}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_token(%App{} = app, %User{} = user, scopes \\ nil) do
|
defp put_token(changeset) do
|
||||||
scopes = scopes || app.scopes
|
changeset
|
||||||
token = :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
|
|> change(%{token: Token.Utils.generate_token()})
|
||||||
refresh_token = :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
|
|> validate_required([:token])
|
||||||
|
|> unique_constraint(:token)
|
||||||
|
end
|
||||||
|
|
||||||
token = %Token{
|
defp put_refresh_token(changeset, attrs) do
|
||||||
token: token,
|
refresh_token = Map.get(attrs, :refresh_token, Token.Utils.generate_token())
|
||||||
refresh_token: refresh_token,
|
|
||||||
scopes: scopes,
|
|
||||||
user_id: user.id,
|
|
||||||
app_id: app.id,
|
|
||||||
valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10)
|
|
||||||
}
|
|
||||||
|
|
||||||
Repo.insert(token)
|
changeset
|
||||||
|
|> change(%{refresh_token: refresh_token})
|
||||||
|
|> validate_required([:refresh_token])
|
||||||
|
|> unique_constraint(:refresh_token)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp put_valid_until(changeset, attrs) do
|
||||||
|
expires_in =
|
||||||
|
Map.get(attrs, :valid_until, NaiveDateTime.add(NaiveDateTime.utc_now(), @expires_in))
|
||||||
|
|
||||||
|
changeset
|
||||||
|
|> change(%{valid_until: expires_in})
|
||||||
|
|> validate_required([:valid_until])
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec create_token(App.t(), User.t(), map()) :: {:ok, Token} | {:error, Changeset.t()}
|
||||||
|
def create_token(%App{} = app, %User{} = user, attrs \\ %{}) do
|
||||||
|
%__MODULE__{user_id: user.id, app_id: app.id}
|
||||||
|
|> cast(%{scopes: attrs[:scopes] || app.scopes}, [:scopes])
|
||||||
|
|> validate_required([:scopes, :app_id])
|
||||||
|
|> put_valid_until(attrs)
|
||||||
|
|> put_token()
|
||||||
|
|> put_refresh_token(attrs)
|
||||||
|
|> Repo.insert()
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_user_tokens(%User{id: user_id}) do
|
def delete_user_tokens(%User{id: user_id}) do
|
||||||
|
@ -73,4 +121,10 @@ def get_user_tokens(%User{id: user_id}) do
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|> Repo.preload(:app)
|
|> Repo.preload(:app)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_expired?(%__MODULE__{valid_until: valid_until}) do
|
||||||
|
NaiveDateTime.diff(NaiveDateTime.utc_now(), valid_until) > 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_expired?(_), do: false
|
||||||
end
|
end
|
||||||
|
|
54
lib/pleroma/web/oauth/token/strategy/refresh_token.ex
Normal file
54
lib/pleroma/web/oauth/token/strategy/refresh_token.ex
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
defmodule Pleroma.Web.OAuth.Token.Strategy.RefreshToken do
|
||||||
|
@moduledoc """
|
||||||
|
Functions for dealing with refresh token strategy.
|
||||||
|
"""
|
||||||
|
|
||||||
|
alias Pleroma.Config
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.Web.OAuth.Token
|
||||||
|
alias Pleroma.Web.OAuth.Token.Strategy.Revoke
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Will grant access token by refresh token.
|
||||||
|
"""
|
||||||
|
@spec grant(Token.t()) :: {:ok, Token.t()} | {:error, any()}
|
||||||
|
def grant(token) do
|
||||||
|
access_token = Repo.preload(token, [:user, :app])
|
||||||
|
|
||||||
|
result =
|
||||||
|
Repo.transaction(fn ->
|
||||||
|
token_params = %{
|
||||||
|
app: access_token.app,
|
||||||
|
user: access_token.user,
|
||||||
|
scopes: access_token.scopes
|
||||||
|
}
|
||||||
|
|
||||||
|
access_token
|
||||||
|
|> revoke_access_token()
|
||||||
|
|> create_access_token(token_params)
|
||||||
|
end)
|
||||||
|
|
||||||
|
case result do
|
||||||
|
{:ok, {:error, reason}} -> {:error, reason}
|
||||||
|
{:ok, {:ok, token}} -> {:ok, token}
|
||||||
|
{:error, reason} -> {:error, reason}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp revoke_access_token(token) do
|
||||||
|
Revoke.revoke(token)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp create_access_token({:error, error}, _), do: {:error, error}
|
||||||
|
|
||||||
|
defp create_access_token({:ok, token}, %{app: app, user: user} = token_params) do
|
||||||
|
Token.create_token(app, user, add_refresh_token(token_params, token.refresh_token))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp add_refresh_token(params, token) do
|
||||||
|
case Config.get([:oauth2, :issue_new_refresh_token], false) do
|
||||||
|
true -> Map.put(params, :refresh_token, token)
|
||||||
|
false -> params
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
22
lib/pleroma/web/oauth/token/strategy/revoke.ex
Normal file
22
lib/pleroma/web/oauth/token/strategy/revoke.ex
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
defmodule Pleroma.Web.OAuth.Token.Strategy.Revoke do
|
||||||
|
@moduledoc """
|
||||||
|
Functions for dealing with revocation.
|
||||||
|
"""
|
||||||
|
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.Web.OAuth.App
|
||||||
|
alias Pleroma.Web.OAuth.Token
|
||||||
|
|
||||||
|
@doc "Finds and revokes access token for app and by token"
|
||||||
|
@spec revoke(App.t(), map()) :: {:ok, Token.t()} | {:error, :not_found | Ecto.Changeset.t()}
|
||||||
|
def revoke(%App{} = app, %{"token" => token} = _attrs) do
|
||||||
|
with {:ok, token} <- Token.get_by_token(app, token),
|
||||||
|
do: revoke(token)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc "Revokes access token"
|
||||||
|
@spec revoke(Token.t()) :: {:ok, Token.t()} | {:error, Ecto.Changeset.t()}
|
||||||
|
def revoke(%Token{} = token) do
|
||||||
|
Repo.delete(token)
|
||||||
|
end
|
||||||
|
end
|
30
lib/pleroma/web/oauth/token/utils.ex
Normal file
30
lib/pleroma/web/oauth/token/utils.ex
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
defmodule Pleroma.Web.OAuth.Token.Utils do
|
||||||
|
@moduledoc """
|
||||||
|
Auxiliary functions for dealing with tokens.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@doc "convert token inserted_at to unix timestamp"
|
||||||
|
def format_created_at(%{inserted_at: inserted_at} = _token) do
|
||||||
|
inserted_at
|
||||||
|
|> DateTime.from_naive!("Etc/UTC")
|
||||||
|
|> DateTime.to_unix()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
@spec generate_token(keyword()) :: binary()
|
||||||
|
def generate_token(opts \\ []) do
|
||||||
|
opts
|
||||||
|
|> Keyword.get(:size, 32)
|
||||||
|
|> :crypto.strong_rand_bytes()
|
||||||
|
|> Base.url_encode64(padding: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
# XXX - for whatever reason our token arrives urlencoded, but Plug.Conn should be
|
||||||
|
# decoding it. Investigate sometime.
|
||||||
|
def fix_padding(token) do
|
||||||
|
token
|
||||||
|
|> URI.decode()
|
||||||
|
|> Base.url_decode64!(padding: false)
|
||||||
|
|> Base.url_encode64(padding: false)
|
||||||
|
end
|
||||||
|
end
|
|
@ -18,14 +18,17 @@ defp get_href(id) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_in_reply_to(%{"object" => %{"inReplyTo" => in_reply_to}}) do
|
defp get_in_reply_to(activity) do
|
||||||
|
with %Object{data: %{"inReplyTo" => in_reply_to}} <- Object.normalize(activity) do
|
||||||
[
|
[
|
||||||
{:"thr:in-reply-to",
|
{:"thr:in-reply-to",
|
||||||
[ref: to_charlist(in_reply_to), href: to_charlist(get_href(in_reply_to))], []}
|
[ref: to_charlist(in_reply_to), href: to_charlist(get_href(in_reply_to))], []}
|
||||||
]
|
]
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
[]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_in_reply_to(_), do: []
|
|
||||||
|
|
||||||
defp get_mentions(to) do
|
defp get_mentions(to) do
|
||||||
Enum.map(to, fn id ->
|
Enum.map(to, fn id ->
|
||||||
|
@ -98,7 +101,7 @@ def to_simple_form(%{data: %{"type" => "Create"}} = activity, user, with_author)
|
||||||
[]}
|
[]}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
in_reply_to = get_in_reply_to(activity.data)
|
in_reply_to = get_in_reply_to(activity)
|
||||||
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
||||||
mentions = activity.recipients |> get_mentions
|
mentions = activity.recipients |> get_mentions
|
||||||
|
|
||||||
|
@ -146,7 +149,6 @@ def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) d
|
||||||
updated_at = activity.data["published"]
|
updated_at = activity.data["published"]
|
||||||
inserted_at = activity.data["published"]
|
inserted_at = activity.data["published"]
|
||||||
|
|
||||||
_in_reply_to = get_in_reply_to(activity.data)
|
|
||||||
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
||||||
mentions = activity.recipients |> get_mentions
|
mentions = activity.recipients |> get_mentions
|
||||||
|
|
||||||
|
@ -177,7 +179,6 @@ def to_simple_form(%{data: %{"type" => "Announce"}} = activity, user, with_autho
|
||||||
updated_at = activity.data["published"]
|
updated_at = activity.data["published"]
|
||||||
inserted_at = activity.data["published"]
|
inserted_at = activity.data["published"]
|
||||||
|
|
||||||
_in_reply_to = get_in_reply_to(activity.data)
|
|
||||||
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
||||||
|
|
||||||
retweeted_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
|
retweeted_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
|
||||||
|
|
|
@ -16,6 +16,7 @@ defmodule Pleroma.Web.OStatus do
|
||||||
alias Pleroma.Web
|
alias Pleroma.Web
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
alias Pleroma.Web.OStatus.DeleteHandler
|
alias Pleroma.Web.OStatus.DeleteHandler
|
||||||
alias Pleroma.Web.OStatus.FollowHandler
|
alias Pleroma.Web.OStatus.FollowHandler
|
||||||
alias Pleroma.Web.OStatus.NoteHandler
|
alias Pleroma.Web.OStatus.NoteHandler
|
||||||
|
@ -30,7 +31,7 @@ def is_representable?(%Activity{} = activity) do
|
||||||
is_nil(object) ->
|
is_nil(object) ->
|
||||||
false
|
false
|
||||||
|
|
||||||
object.data["type"] == "Note" ->
|
Visibility.is_public?(activity) && object.data["type"] == "Note" ->
|
||||||
true
|
true
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
|
|
|
@ -21,8 +21,10 @@ defmodule Pleroma.Web.Push.Impl do
|
||||||
@doc "Performs sending notifications for user subscriptions"
|
@doc "Performs sending notifications for user subscriptions"
|
||||||
@spec perform(Notification.t()) :: list(any) | :error
|
@spec perform(Notification.t()) :: list(any) | :error
|
||||||
def perform(
|
def perform(
|
||||||
%{activity: %{data: %{"type" => activity_type}, id: activity_id}, user_id: user_id} =
|
%{
|
||||||
notif
|
activity: %{data: %{"type" => activity_type}, id: activity_id} = activity,
|
||||||
|
user_id: user_id
|
||||||
|
} = notif
|
||||||
)
|
)
|
||||||
when activity_type in @types do
|
when activity_type in @types do
|
||||||
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
|
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
|
||||||
|
@ -30,13 +32,14 @@ def perform(
|
||||||
type = Activity.mastodon_notification_type(notif.activity)
|
type = Activity.mastodon_notification_type(notif.activity)
|
||||||
gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key)
|
gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key)
|
||||||
avatar_url = User.avatar_url(actor)
|
avatar_url = User.avatar_url(actor)
|
||||||
|
object = Object.normalize(activity)
|
||||||
|
|
||||||
for subscription <- fetch_subsriptions(user_id),
|
for subscription <- fetch_subsriptions(user_id),
|
||||||
get_in(subscription.data, ["alerts", type]) do
|
get_in(subscription.data, ["alerts", type]) do
|
||||||
%{
|
%{
|
||||||
title: format_title(notif),
|
title: format_title(notif),
|
||||||
access_token: subscription.token.token,
|
access_token: subscription.token.token,
|
||||||
body: format_body(notif, actor),
|
body: format_body(notif, actor, object),
|
||||||
notification_id: notif.id,
|
notification_id: notif.id,
|
||||||
notification_type: type,
|
notification_type: type,
|
||||||
icon: avatar_url,
|
icon: avatar_url,
|
||||||
|
@ -95,25 +98,25 @@ def build_sub(subscription) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_body(
|
def format_body(
|
||||||
%{activity: %{data: %{"type" => "Create", "object" => %{"content" => content}}}},
|
%{activity: %{data: %{"type" => "Create"}}},
|
||||||
actor
|
actor,
|
||||||
|
%{data: %{"content" => content}}
|
||||||
) do
|
) do
|
||||||
"@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}"
|
"@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_body(
|
def format_body(
|
||||||
%{activity: %{data: %{"type" => "Announce", "object" => activity_id}}},
|
%{activity: %{data: %{"type" => "Announce"}}},
|
||||||
actor
|
actor,
|
||||||
|
%{data: %{"content" => content}}
|
||||||
) do
|
) do
|
||||||
%Activity{data: %{"object" => %{"id" => object_id}}} = Activity.get_by_ap_id(activity_id)
|
|
||||||
%Object{data: %{"content" => content}} = Object.get_by_ap_id(object_id)
|
|
||||||
|
|
||||||
"@#{actor.nickname} repeated: #{Utils.scrub_html_and_truncate(content, 80)}"
|
"@#{actor.nickname} repeated: #{Utils.scrub_html_and_truncate(content, 80)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_body(
|
def format_body(
|
||||||
%{activity: %{data: %{"type" => type}}},
|
%{activity: %{data: %{"type" => type}}},
|
||||||
actor
|
actor,
|
||||||
|
_object
|
||||||
)
|
)
|
||||||
when type in ["Follow", "Like"] do
|
when type in ["Follow", "Like"] do
|
||||||
case type do
|
case type do
|
||||||
|
|
|
@ -146,34 +146,52 @@ defmodule Pleroma.Web.Router do
|
||||||
scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
|
scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
|
||||||
pipe_through([:admin_api, :oauth_write])
|
pipe_through([:admin_api, :oauth_write])
|
||||||
|
|
||||||
post("/user/follow", AdminAPIController, :user_follow)
|
post("/users/follow", AdminAPIController, :user_follow)
|
||||||
post("/user/unfollow", AdminAPIController, :user_unfollow)
|
post("/users/unfollow", AdminAPIController, :user_unfollow)
|
||||||
|
|
||||||
get("/users", AdminAPIController, :list_users)
|
|
||||||
get("/users/:nickname", AdminAPIController, :user_show)
|
|
||||||
|
|
||||||
|
# TODO: to be removed at version 1.0
|
||||||
delete("/user", AdminAPIController, :user_delete)
|
delete("/user", AdminAPIController, :user_delete)
|
||||||
patch("/users/:nickname/toggle_activation", AdminAPIController, :user_toggle_activation)
|
|
||||||
post("/user", AdminAPIController, :user_create)
|
post("/user", AdminAPIController, :user_create)
|
||||||
|
|
||||||
|
delete("/users", AdminAPIController, :user_delete)
|
||||||
|
post("/users", AdminAPIController, :user_create)
|
||||||
|
patch("/users/:nickname/toggle_activation", AdminAPIController, :user_toggle_activation)
|
||||||
put("/users/tag", AdminAPIController, :tag_users)
|
put("/users/tag", AdminAPIController, :tag_users)
|
||||||
delete("/users/tag", AdminAPIController, :untag_users)
|
delete("/users/tag", AdminAPIController, :untag_users)
|
||||||
|
|
||||||
|
# TODO: to be removed at version 1.0
|
||||||
get("/permission_group/:nickname", AdminAPIController, :right_get)
|
get("/permission_group/:nickname", AdminAPIController, :right_get)
|
||||||
get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
|
get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
|
||||||
post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
|
post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
|
||||||
delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
|
delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
|
||||||
|
|
||||||
put("/activation_status/:nickname", AdminAPIController, :set_activation_status)
|
get("/users/:nickname/permission_group", AdminAPIController, :right_get)
|
||||||
|
get("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_get)
|
||||||
|
post("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_add)
|
||||||
|
|
||||||
|
delete(
|
||||||
|
"/users/:nickname/permission_group/:permission_group",
|
||||||
|
AdminAPIController,
|
||||||
|
:right_delete
|
||||||
|
)
|
||||||
|
|
||||||
|
put("/users/:nickname/activation_status", AdminAPIController, :set_activation_status)
|
||||||
|
|
||||||
post("/relay", AdminAPIController, :relay_follow)
|
post("/relay", AdminAPIController, :relay_follow)
|
||||||
delete("/relay", AdminAPIController, :relay_unfollow)
|
delete("/relay", AdminAPIController, :relay_unfollow)
|
||||||
|
|
||||||
get("/invite_token", AdminAPIController, :get_invite_token)
|
get("/users/invite_token", AdminAPIController, :get_invite_token)
|
||||||
get("/invites", AdminAPIController, :invites)
|
get("/users/invites", AdminAPIController, :invites)
|
||||||
post("/revoke_invite", AdminAPIController, :revoke_invite)
|
post("/users/revoke_invite", AdminAPIController, :revoke_invite)
|
||||||
post("/email_invite", AdminAPIController, :email_invite)
|
post("/users/email_invite", AdminAPIController, :email_invite)
|
||||||
|
|
||||||
|
# TODO: to be removed at version 1.0
|
||||||
get("/password_reset", AdminAPIController, :get_password_reset)
|
get("/password_reset", AdminAPIController, :get_password_reset)
|
||||||
|
|
||||||
|
get("/users/:nickname/password_reset", AdminAPIController, :get_password_reset)
|
||||||
|
|
||||||
|
get("/users", AdminAPIController, :list_users)
|
||||||
|
get("/users/:nickname", AdminAPIController, :user_show)
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/", Pleroma.Web.TwitterAPI do
|
scope "/", Pleroma.Web.TwitterAPI do
|
||||||
|
@ -276,6 +294,9 @@ defmodule Pleroma.Web.Router do
|
||||||
|
|
||||||
get("/suggestions", MastodonAPIController, :suggestions)
|
get("/suggestions", MastodonAPIController, :suggestions)
|
||||||
|
|
||||||
|
get("/conversations", MastodonAPIController, :conversations)
|
||||||
|
post("/conversations/:id/read", MastodonAPIController, :conversation_read)
|
||||||
|
|
||||||
get("/endorsements", MastodonAPIController, :empty_array)
|
get("/endorsements", MastodonAPIController, :empty_array)
|
||||||
|
|
||||||
get("/pleroma/flavour", MastodonAPIController, :get_flavour)
|
get("/pleroma/flavour", MastodonAPIController, :get_flavour)
|
||||||
|
@ -364,6 +385,8 @@ defmodule Pleroma.Web.Router do
|
||||||
scope "/api/v1", Pleroma.Web.MastodonAPI do
|
scope "/api/v1", Pleroma.Web.MastodonAPI do
|
||||||
pipe_through(:api)
|
pipe_through(:api)
|
||||||
|
|
||||||
|
post("/accounts", MastodonAPIController, :account_register)
|
||||||
|
|
||||||
get("/instance", MastodonAPIController, :masto_instance)
|
get("/instance", MastodonAPIController, :masto_instance)
|
||||||
get("/instance/peers", MastodonAPIController, :peers)
|
get("/instance/peers", MastodonAPIController, :peers)
|
||||||
post("/apps", MastodonAPIController, :create_app)
|
post("/apps", MastodonAPIController, :create_app)
|
||||||
|
|
|
@ -3,12 +3,18 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.Salmon do
|
defmodule Pleroma.Web.Salmon do
|
||||||
|
@behaviour Pleroma.Web.Federator.Publisher
|
||||||
|
|
||||||
@httpoison Application.get_env(:pleroma, :httpoison)
|
@httpoison Application.get_env(:pleroma, :httpoison)
|
||||||
|
|
||||||
use Bitwise
|
use Bitwise
|
||||||
|
|
||||||
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Instances
|
alias Pleroma.Instances
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
|
alias Pleroma.Web.Federator.Publisher
|
||||||
|
alias Pleroma.Web.OStatus
|
||||||
alias Pleroma.Web.OStatus.ActivityRepresenter
|
alias Pleroma.Web.OStatus.ActivityRepresenter
|
||||||
alias Pleroma.Web.XML
|
alias Pleroma.Web.XML
|
||||||
|
|
||||||
|
@ -180,12 +186,12 @@ def remote_users(%User{id: user_id}, %{data: %{"to" => to} = data}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "Pushes an activity to remote account."
|
@doc "Pushes an activity to remote account."
|
||||||
def send_to_user(%{recipient: %{info: %{salmon: salmon}}} = params),
|
def publish_one(%{recipient: %{info: %{salmon: salmon}}} = params),
|
||||||
do: send_to_user(Map.put(params, :recipient, salmon))
|
do: publish_one(Map.put(params, :recipient, salmon))
|
||||||
|
|
||||||
def send_to_user(%{recipient: url, feed: feed, poster: poster} = params) when is_binary(url) do
|
def publish_one(%{recipient: url, feed: feed} = params) when is_binary(url) do
|
||||||
with {:ok, %{status: code}} when code in 200..299 <-
|
with {:ok, %{status: code}} when code in 200..299 <-
|
||||||
poster.(
|
@httpoison.post(
|
||||||
url,
|
url,
|
||||||
feed,
|
feed,
|
||||||
[{"Content-Type", "application/magic-envelope+xml"}]
|
[{"Content-Type", "application/magic-envelope+xml"}]
|
||||||
|
@ -199,11 +205,11 @@ def send_to_user(%{recipient: url, feed: feed, poster: poster} = params) when is
|
||||||
e ->
|
e ->
|
||||||
unless params[:unreachable_since], do: Instances.set_reachable(url)
|
unless params[:unreachable_since], do: Instances.set_reachable(url)
|
||||||
Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end)
|
Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end)
|
||||||
:error
|
{:error, "Unreachable instance"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_to_user(_), do: :noop
|
def publish_one(_), do: :noop
|
||||||
|
|
||||||
@supported_activities [
|
@supported_activities [
|
||||||
"Create",
|
"Create",
|
||||||
|
@ -214,13 +220,19 @@ def send_to_user(_), do: :noop
|
||||||
"Delete"
|
"Delete"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def is_representable?(%Activity{data: %{"type" => type}} = activity)
|
||||||
|
when type in @supported_activities,
|
||||||
|
do: Visibility.is_public?(activity)
|
||||||
|
|
||||||
|
def is_representable?(_), do: false
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Publishes an activity to remote accounts
|
Publishes an activity to remote accounts
|
||||||
"""
|
"""
|
||||||
@spec publish(User.t(), Pleroma.Activity.t(), Pleroma.HTTP.t()) :: none
|
@spec publish(User.t(), Pleroma.Activity.t()) :: none
|
||||||
def publish(user, activity, poster \\ &@httpoison.post/3)
|
def publish(user, activity)
|
||||||
|
|
||||||
def publish(%{info: %{keys: keys}} = user, %{data: %{"type" => type}} = activity, poster)
|
def publish(%{info: %{keys: keys}} = user, %{data: %{"type" => type}} = activity)
|
||||||
when type in @supported_activities do
|
when type in @supported_activities do
|
||||||
feed = ActivityRepresenter.to_simple_form(activity, user, true)
|
feed = ActivityRepresenter.to_simple_form(activity, user, true)
|
||||||
|
|
||||||
|
@ -244,15 +256,29 @@ def publish(%{info: %{keys: keys}} = user, %{data: %{"type" => type}} = activity
|
||||||
|> Enum.each(fn remote_user ->
|
|> Enum.each(fn remote_user ->
|
||||||
Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end)
|
Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end)
|
||||||
|
|
||||||
Pleroma.Web.Federator.publish_single_salmon(%{
|
Publisher.enqueue_one(__MODULE__, %{
|
||||||
recipient: remote_user,
|
recipient: remote_user,
|
||||||
feed: feed,
|
feed: feed,
|
||||||
poster: poster,
|
|
||||||
unreachable_since: reachable_urls_metadata[remote_user.info.salmon]
|
unreachable_since: reachable_urls_metadata[remote_user.info.salmon]
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish(%{id: id}, _, _), do: Logger.debug(fn -> "Keys missing for user #{id}" end)
|
def publish(%{id: id}, _), do: Logger.debug(fn -> "Keys missing for user #{id}" end)
|
||||||
|
|
||||||
|
def gather_webfinger_links(%User{} = user) do
|
||||||
|
{:ok, _private, public} = keys_from_pem(user.info.keys)
|
||||||
|
magic_key = encode_key(public)
|
||||||
|
|
||||||
|
[
|
||||||
|
%{"rel" => "salmon", "href" => OStatus.salmon_path(user)},
|
||||||
|
%{
|
||||||
|
"rel" => "magic-public-key",
|
||||||
|
"href" => "data:application/magic-public-key,#{magic_key}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
def gather_nodeinfo_protocol_names, do: []
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.Streamer do
|
||||||
use GenServer
|
use GenServer
|
||||||
require Logger
|
require Logger
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Conversation.Participation
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
@ -71,6 +72,15 @@ def handle_cast(%{action: :stream, topic: "direct", item: item}, topics) do
|
||||||
{:noreply, topics}
|
{:noreply, topics}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_cast(%{action: :stream, topic: "participation", item: participation}, topics) do
|
||||||
|
user_topic = "direct:#{participation.user_id}"
|
||||||
|
Logger.debug("Trying to push a conversation participation to #{user_topic}\n\n")
|
||||||
|
|
||||||
|
push_to_socket(topics, user_topic, participation)
|
||||||
|
|
||||||
|
{:noreply, topics}
|
||||||
|
end
|
||||||
|
|
||||||
def handle_cast(%{action: :stream, topic: "list", item: item}, topics) do
|
def handle_cast(%{action: :stream, topic: "list", item: item}, topics) do
|
||||||
# filter the recipient list if the activity is not public, see #270.
|
# filter the recipient list if the activity is not public, see #270.
|
||||||
recipient_lists =
|
recipient_lists =
|
||||||
|
@ -192,6 +202,19 @@ defp represent_update(%Activity{} = activity) do
|
||||||
|> Jason.encode!()
|
|> Jason.encode!()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def represent_conversation(%Participation{} = participation) do
|
||||||
|
%{
|
||||||
|
event: "conversation",
|
||||||
|
payload:
|
||||||
|
Pleroma.Web.MastodonAPI.ConversationView.render("participation.json", %{
|
||||||
|
participation: participation,
|
||||||
|
user: participation.user
|
||||||
|
})
|
||||||
|
|> Jason.encode!()
|
||||||
|
}
|
||||||
|
|> Jason.encode!()
|
||||||
|
end
|
||||||
|
|
||||||
def push_to_socket(topics, topic, %Activity{data: %{"type" => "Announce"}} = item) do
|
def push_to_socket(topics, topic, %Activity{data: %{"type" => "Announce"}} = item) do
|
||||||
Enum.each(topics[topic] || [], fn socket ->
|
Enum.each(topics[topic] || [], fn socket ->
|
||||||
# Get the current user so we have up-to-date blocks etc.
|
# Get the current user so we have up-to-date blocks etc.
|
||||||
|
@ -214,6 +237,12 @@ def push_to_socket(topics, topic, %Activity{data: %{"type" => "Announce"}} = ite
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def push_to_socket(topics, topic, %Participation{} = participation) do
|
||||||
|
Enum.each(topics[topic] || [], fn socket ->
|
||||||
|
send(socket.transport_pid, {:text, represent_conversation(participation)})
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
def push_to_socket(topics, topic, %Activity{
|
def push_to_socket(topics, topic, %Activity{
|
||||||
data: %{"type" => "Delete", "deleted_activity_id" => deleted_activity_id}
|
data: %{"type" => "Delete", "deleted_activity_id" => deleted_activity_id}
|
||||||
}) do
|
}) do
|
||||||
|
|
|
@ -352,7 +352,7 @@ def change_password(%{assigns: %{user: user}} = conn, params) do
|
||||||
def delete_account(%{assigns: %{user: user}} = conn, params) do
|
def delete_account(%{assigns: %{user: user}} = conn, params) do
|
||||||
case CommonAPI.Utils.confirm_current_password(user, params["password"]) do
|
case CommonAPI.Utils.confirm_current_password(user, params["password"]) do
|
||||||
{:ok, user} ->
|
{:ok, user} ->
|
||||||
Task.start(fn -> User.delete(user) end)
|
User.delete(user)
|
||||||
json(conn, %{status: "success"})
|
json(conn, %{status: "success"})
|
||||||
|
|
||||||
{:error, msg} ->
|
{:error, msg} ->
|
||||||
|
|
|
@ -128,7 +128,7 @@ def upload(%Plug.Upload{} = file, %User{} = user, format \\ "xml") do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_user(params) do
|
def register_user(params, opts \\ []) do
|
||||||
token = params["token"]
|
token = params["token"]
|
||||||
|
|
||||||
params = %{
|
params = %{
|
||||||
|
@ -162,13 +162,22 @@ def register_user(params) do
|
||||||
# I have no idea how this error handling works
|
# I have no idea how this error handling works
|
||||||
{:error, %{error: Jason.encode!(%{captcha: [error]})}}
|
{:error, %{error: Jason.encode!(%{captcha: [error]})}}
|
||||||
else
|
else
|
||||||
registrations_open = Pleroma.Config.get([:instance, :registrations_open])
|
registration_process(
|
||||||
registration_process(registrations_open, params, token)
|
params,
|
||||||
|
%{
|
||||||
|
registrations_open: Pleroma.Config.get([:instance, :registrations_open]),
|
||||||
|
token: token
|
||||||
|
},
|
||||||
|
opts
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp registration_process(registration_open, params, token)
|
defp registration_process(params, %{registrations_open: true}, opts) do
|
||||||
when registration_open == false or is_nil(registration_open) do
|
create_user(params, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp registration_process(params, %{token: token}, opts) do
|
||||||
invite =
|
invite =
|
||||||
unless is_nil(token) do
|
unless is_nil(token) do
|
||||||
Repo.get_by(UserInviteToken, %{token: token})
|
Repo.get_by(UserInviteToken, %{token: token})
|
||||||
|
@ -182,19 +191,15 @@ defp registration_process(registration_open, params, token)
|
||||||
|
|
||||||
invite when valid_invite? ->
|
invite when valid_invite? ->
|
||||||
UserInviteToken.update_usage!(invite)
|
UserInviteToken.update_usage!(invite)
|
||||||
create_user(params)
|
create_user(params, opts)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
{:error, "Expired token"}
|
{:error, "Expired token"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp registration_process(true, params, _token) do
|
defp create_user(params, opts) do
|
||||||
create_user(params)
|
changeset = User.register_changeset(%User{}, params, opts)
|
||||||
end
|
|
||||||
|
|
||||||
defp create_user(params) do
|
|
||||||
changeset = User.register_changeset(%User{}, params)
|
|
||||||
|
|
||||||
case User.register(changeset) do
|
case User.register(changeset) do
|
||||||
{:ok, user} ->
|
{:ok, user} ->
|
||||||
|
@ -293,7 +298,7 @@ def search(_user, %{"q" => query} = params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_external_profile(for_user, uri) do
|
def get_external_profile(for_user, uri) do
|
||||||
with %User{} = user <- User.get_or_fetch(uri) do
|
with {:ok, %User{} = user} <- User.get_or_fetch(uri) do
|
||||||
{:ok, UserView.render("show.json", %{user: user, for: for_user})}
|
{:ok, UserView.render("show.json", %{user: user, for: for_user})}
|
||||||
else
|
else
|
||||||
_e ->
|
_e ->
|
||||||
|
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
||||||
|
|
||||||
alias Ecto.Changeset
|
alias Ecto.Changeset
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Formatter
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
@ -181,6 +182,7 @@ def dm_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
|> Map.put("blocking_user", user)
|
|> Map.put("blocking_user", user)
|
||||||
|> Map.put("user", user)
|
|> Map.put("user", user)
|
||||||
|> Map.put(:visibility, "direct")
|
|> Map.put(:visibility, "direct")
|
||||||
|
|> Map.put(:order, :desc)
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
ActivityPub.fetch_activities_query([user.ap_id], params)
|
ActivityPub.fetch_activities_query([user.ap_id], params)
|
||||||
|
@ -438,7 +440,7 @@ def confirm_email(conn, %{"user_id" => uid, "token" => token}) do
|
||||||
true <- user.local,
|
true <- user.local,
|
||||||
true <- user.info.confirmation_pending,
|
true <- user.info.confirmation_pending,
|
||||||
true <- user.info.confirmation_token == token,
|
true <- user.info.confirmation_token == token,
|
||||||
info_change <- User.Info.confirmation_changeset(user.info, :confirmed),
|
info_change <- User.Info.confirmation_changeset(user.info, need_confirmation: false),
|
||||||
changeset <- Changeset.change(user) |> Changeset.put_embed(:info, info_change),
|
changeset <- Changeset.change(user) |> Changeset.put_embed(:info, info_change),
|
||||||
{:ok, _} <- User.update_and_set_cache(changeset) do
|
{:ok, _} <- User.update_and_set_cache(changeset) do
|
||||||
conn
|
conn
|
||||||
|
@ -653,7 +655,22 @@ defp build_info_cng(user, params) do
|
||||||
|
|
||||||
defp parse_profile_bio(user, params) do
|
defp parse_profile_bio(user, params) do
|
||||||
if bio = params["description"] do
|
if bio = params["description"] do
|
||||||
Map.put(params, "bio", User.parse_bio(bio, user))
|
emojis_text = (params["description"] || "") <> " " <> (params["name"] || "")
|
||||||
|
|
||||||
|
emojis =
|
||||||
|
((user.info.emoji || []) ++ Formatter.get_emoji_map(emojis_text))
|
||||||
|
|> Enum.dedup()
|
||||||
|
|
||||||
|
user_info =
|
||||||
|
user.info
|
||||||
|
|> Map.put(
|
||||||
|
"emoji",
|
||||||
|
emojis
|
||||||
|
)
|
||||||
|
|
||||||
|
params
|
||||||
|
|> Map.put("bio", User.parse_bio(bio, user))
|
||||||
|
|> Map.put("info", user_info)
|
||||||
else
|
else
|
||||||
params
|
params
|
||||||
end
|
end
|
||||||
|
|
|
@ -170,7 +170,7 @@ def render("activity.json", %{activity: %{data: %{"type" => "Announce"}} = activ
|
||||||
created_at = activity.data["published"] |> Utils.date_to_asctime()
|
created_at = activity.data["published"] |> Utils.date_to_asctime()
|
||||||
announced_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
|
announced_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
|
||||||
|
|
||||||
text = "#{user.nickname} retweeted a status."
|
text = "#{user.nickname} repeated a status."
|
||||||
|
|
||||||
retweeted_status = render("activity.json", Map.merge(opts, %{activity: announced_activity}))
|
retweeted_status = render("activity.json", Map.merge(opts, %{activity: announced_activity}))
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,13 @@ defp do_render("user.json", %{user: user = %User{}} = assigns) do
|
||||||
{String.trim(name, ":"), url}
|
{String.trim(name, ":"), url}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
emoji = Enum.dedup(emoji ++ user.info.emoji)
|
||||||
|
|
||||||
|
description_html =
|
||||||
|
(user.bio || "")
|
||||||
|
|> HTML.filter_tags(User.html_filter_policy(for_user))
|
||||||
|
|> Formatter.emojify(emoji)
|
||||||
|
|
||||||
# ``fields`` is an array of mastodon profile field, containing ``{"name": "…", "value": "…"}``.
|
# ``fields`` is an array of mastodon profile field, containing ``{"name": "…", "value": "…"}``.
|
||||||
# For example: [{"name": "Pronoun", "value": "she/her"}, …]
|
# For example: [{"name": "Pronoun", "value": "she/her"}, …]
|
||||||
fields =
|
fields =
|
||||||
|
@ -74,10 +81,11 @@ defp do_render("user.json", %{user: user = %User{}} = assigns) do
|
||||||
|> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
|
|> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
|
||||||
|> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
|
|> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
|
||||||
|
|
||||||
data = %{
|
data =
|
||||||
|
%{
|
||||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
||||||
"description" => HTML.strip_tags((user.bio || "") |> String.replace("<br>", "\n")),
|
"description" => HTML.strip_tags((user.bio || "") |> String.replace("<br>", "\n")),
|
||||||
"description_html" => HTML.filter_tags(user.bio, User.html_filter_policy(for_user)),
|
"description_html" => description_html,
|
||||||
"favourites_count" => 0,
|
"favourites_count" => 0,
|
||||||
"followers_count" => user_info[:follower_count],
|
"followers_count" => user_info[:follower_count],
|
||||||
"following" => following,
|
"following" => following,
|
||||||
|
@ -95,10 +103,6 @@ defp do_render("user.json", %{user: user = %User{}} = assigns) do
|
||||||
"profile_image_url_https" => image,
|
"profile_image_url_https" => image,
|
||||||
"profile_image_url_profile_size" => image,
|
"profile_image_url_profile_size" => image,
|
||||||
"profile_image_url_original" => image,
|
"profile_image_url_original" => image,
|
||||||
"rights" => %{
|
|
||||||
"delete_others_notice" => !!user.info.is_moderator,
|
|
||||||
"admin" => !!user.info.is_admin
|
|
||||||
},
|
|
||||||
"screen_name" => user.nickname,
|
"screen_name" => user.nickname,
|
||||||
"statuses_count" => user_info[:note_count],
|
"statuses_count" => user_info[:note_count],
|
||||||
"statusnet_profile_url" => user.ap_id,
|
"statusnet_profile_url" => user.ap_id,
|
||||||
|
@ -106,8 +110,6 @@ defp do_render("user.json", %{user: user = %User{}} = assigns) do
|
||||||
"background_image" => image_url(user.info.background) |> MediaProxy.url(),
|
"background_image" => image_url(user.info.background) |> MediaProxy.url(),
|
||||||
"is_local" => user.local,
|
"is_local" => user.local,
|
||||||
"locked" => user.info.locked,
|
"locked" => user.info.locked,
|
||||||
"default_scope" => user.info.default_scope,
|
|
||||||
"no_rich_text" => user.info.no_rich_text,
|
|
||||||
"hide_followers" => user.info.hide_followers,
|
"hide_followers" => user.info.hide_followers,
|
||||||
"hide_follows" => user.info.hide_follows,
|
"hide_follows" => user.info.hide_follows,
|
||||||
"fields" => fields,
|
"fields" => fields,
|
||||||
|
@ -120,12 +122,8 @@ defp do_render("user.json", %{user: user = %User{}} = assigns) do
|
||||||
}
|
}
|
||||||
|> maybe_with_activation_status(user, for_user)
|
|> maybe_with_activation_status(user, for_user)
|
||||||
}
|
}
|
||||||
|
|> maybe_with_user_settings(user, for_user)
|
||||||
data =
|
|> maybe_with_role(user, for_user)
|
||||||
if(user.info.is_admin || user.info.is_moderator,
|
|
||||||
do: maybe_with_role(data, user, for_user),
|
|
||||||
else: data
|
|
||||||
)
|
|
||||||
|
|
||||||
if assigns[:token] do
|
if assigns[:token] do
|
||||||
Map.put(data, "token", token_string(assigns[:token]))
|
Map.put(data, "token", token_string(assigns[:token]))
|
||||||
|
@ -141,15 +139,35 @@ defp maybe_with_activation_status(data, user, %User{info: %{is_admin: true}}) do
|
||||||
defp maybe_with_activation_status(data, _, _), do: data
|
defp maybe_with_activation_status(data, _, _), do: data
|
||||||
|
|
||||||
defp maybe_with_role(data, %User{id: id} = user, %User{id: id}) do
|
defp maybe_with_role(data, %User{id: id} = user, %User{id: id}) do
|
||||||
Map.merge(data, %{"role" => role(user), "show_role" => user.info.show_role})
|
Map.merge(data, %{
|
||||||
|
"role" => role(user),
|
||||||
|
"show_role" => user.info.show_role,
|
||||||
|
"rights" => %{
|
||||||
|
"delete_others_notice" => !!user.info.is_moderator,
|
||||||
|
"admin" => !!user.info.is_admin
|
||||||
|
}
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_with_role(data, %User{info: %{show_role: true}} = user, _user) do
|
defp maybe_with_role(data, %User{info: %{show_role: true}} = user, _user) do
|
||||||
Map.merge(data, %{"role" => role(user)})
|
Map.merge(data, %{
|
||||||
|
"role" => role(user),
|
||||||
|
"rights" => %{
|
||||||
|
"delete_others_notice" => !!user.info.is_moderator,
|
||||||
|
"admin" => !!user.info.is_admin
|
||||||
|
}
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_with_role(data, _, _), do: data
|
defp maybe_with_role(data, _, _), do: data
|
||||||
|
|
||||||
|
defp maybe_with_user_settings(data, %User{info: info, id: id} = _user, %User{id: id}) do
|
||||||
|
data
|
||||||
|
|> Kernel.put_in(["default_scope"], info.default_scope)
|
||||||
|
|> Kernel.put_in(["no_rich_text"], info.no_rich_text)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp maybe_with_user_settings(data, _, _), do: data
|
||||||
defp role(%User{info: %{:is_admin => true}}), do: "admin"
|
defp role(%User{info: %{:is_admin => true}}), do: "admin"
|
||||||
defp role(%User{info: %{:is_moderator => true}}), do: "moderator"
|
defp role(%User{info: %{:is_moderator => true}}), do: "moderator"
|
||||||
defp role(_), do: "member"
|
defp role(_), do: "member"
|
||||||
|
|
|
@ -7,7 +7,7 @@ defmodule Pleroma.Web.WebFinger do
|
||||||
|
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web
|
alias Pleroma.Web
|
||||||
alias Pleroma.Web.OStatus
|
alias Pleroma.Web.Federator.Publisher
|
||||||
alias Pleroma.Web.Salmon
|
alias Pleroma.Web.Salmon
|
||||||
alias Pleroma.Web.XML
|
alias Pleroma.Web.XML
|
||||||
alias Pleroma.XmlBuilder
|
alias Pleroma.XmlBuilder
|
||||||
|
@ -50,70 +50,40 @@ def webfinger(resource, fmt) when fmt in ["XML", "JSON"] do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def represent_user(user, "JSON") do
|
defp gather_links(%User{} = user) do
|
||||||
{:ok, user} = ensure_keys_present(user)
|
[
|
||||||
{:ok, _private, public} = Salmon.keys_from_pem(user.info.keys)
|
|
||||||
magic_key = Salmon.encode_key(public)
|
|
||||||
|
|
||||||
%{
|
|
||||||
"subject" => "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host()}",
|
|
||||||
"aliases" => [user.ap_id],
|
|
||||||
"links" => [
|
|
||||||
%{
|
|
||||||
"rel" => "http://schemas.google.com/g/2010#updates-from",
|
|
||||||
"type" => "application/atom+xml",
|
|
||||||
"href" => OStatus.feed_path(user)
|
|
||||||
},
|
|
||||||
%{
|
%{
|
||||||
"rel" => "http://webfinger.net/rel/profile-page",
|
"rel" => "http://webfinger.net/rel/profile-page",
|
||||||
"type" => "text/html",
|
"type" => "text/html",
|
||||||
"href" => user.ap_id
|
"href" => user.ap_id
|
||||||
},
|
|
||||||
%{"rel" => "salmon", "href" => OStatus.salmon_path(user)},
|
|
||||||
%{
|
|
||||||
"rel" => "magic-public-key",
|
|
||||||
"href" => "data:application/magic-public-key,#{magic_key}"
|
|
||||||
},
|
|
||||||
%{"rel" => "self", "type" => "application/activity+json", "href" => user.ap_id},
|
|
||||||
%{
|
|
||||||
"rel" => "self",
|
|
||||||
"type" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
|
|
||||||
"href" => user.ap_id
|
|
||||||
},
|
|
||||||
%{
|
|
||||||
"rel" => "http://ostatus.org/schema/1.0/subscribe",
|
|
||||||
"template" => OStatus.remote_follow_path()
|
|
||||||
}
|
}
|
||||||
]
|
] ++ Publisher.gather_webfinger_links(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def represent_user(user, "JSON") do
|
||||||
|
{:ok, user} = ensure_keys_present(user)
|
||||||
|
|
||||||
|
%{
|
||||||
|
"subject" => "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host()}",
|
||||||
|
"aliases" => [user.ap_id],
|
||||||
|
"links" => gather_links(user)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def represent_user(user, "XML") do
|
def represent_user(user, "XML") do
|
||||||
{:ok, user} = ensure_keys_present(user)
|
{:ok, user} = ensure_keys_present(user)
|
||||||
{:ok, _private, public} = Salmon.keys_from_pem(user.info.keys)
|
|
||||||
magic_key = Salmon.encode_key(public)
|
links =
|
||||||
|
gather_links(user)
|
||||||
|
|> Enum.map(fn link -> {:Link, link} end)
|
||||||
|
|
||||||
{
|
{
|
||||||
:XRD,
|
:XRD,
|
||||||
%{xmlns: "http://docs.oasis-open.org/ns/xri/xrd-1.0"},
|
%{xmlns: "http://docs.oasis-open.org/ns/xri/xrd-1.0"},
|
||||||
[
|
[
|
||||||
{:Subject, "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host()}"},
|
{:Subject, "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host()}"},
|
||||||
{:Alias, user.ap_id},
|
{:Alias, user.ap_id}
|
||||||
{:Link,
|
] ++ links
|
||||||
%{
|
|
||||||
rel: "http://schemas.google.com/g/2010#updates-from",
|
|
||||||
type: "application/atom+xml",
|
|
||||||
href: OStatus.feed_path(user)
|
|
||||||
}},
|
|
||||||
{:Link,
|
|
||||||
%{rel: "http://webfinger.net/rel/profile-page", type: "text/html", href: user.ap_id}},
|
|
||||||
{:Link, %{rel: "salmon", href: OStatus.salmon_path(user)}},
|
|
||||||
{:Link,
|
|
||||||
%{rel: "magic-public-key", href: "data:application/magic-public-key,#{magic_key}"}},
|
|
||||||
{:Link, %{rel: "self", type: "application/activity+json", href: user.ap_id}},
|
|
||||||
{:Link,
|
|
||||||
%{rel: "http://ostatus.org/schema/1.0/subscribe", template: OStatus.remote_follow_path()}}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|> XmlBuilder.to_doc()
|
|> XmlBuilder.to_doc()
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,10 +4,14 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.Websub do
|
defmodule Pleroma.Web.Websub do
|
||||||
alias Ecto.Changeset
|
alias Ecto.Changeset
|
||||||
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Instances
|
alias Pleroma.Instances
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
alias Pleroma.Web.Endpoint
|
alias Pleroma.Web.Endpoint
|
||||||
alias Pleroma.Web.Federator
|
alias Pleroma.Web.Federator
|
||||||
|
alias Pleroma.Web.Federator.Publisher
|
||||||
alias Pleroma.Web.OStatus
|
alias Pleroma.Web.OStatus
|
||||||
alias Pleroma.Web.OStatus.FeedRepresenter
|
alias Pleroma.Web.OStatus.FeedRepresenter
|
||||||
alias Pleroma.Web.Router.Helpers
|
alias Pleroma.Web.Router.Helpers
|
||||||
|
@ -18,6 +22,8 @@ defmodule Pleroma.Web.Websub do
|
||||||
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
|
@behaviour Pleroma.Web.Federator.Publisher
|
||||||
|
|
||||||
@httpoison Application.get_env(:pleroma, :httpoison)
|
@httpoison Application.get_env(:pleroma, :httpoison)
|
||||||
|
|
||||||
def verify(subscription, getter \\ &@httpoison.get/3) do
|
def verify(subscription, getter \\ &@httpoison.get/3) do
|
||||||
|
@ -56,6 +62,13 @@ def verify(subscription, getter \\ &@httpoison.get/3) do
|
||||||
"Undo",
|
"Undo",
|
||||||
"Delete"
|
"Delete"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def is_representable?(%Activity{data: %{"type" => type}} = activity)
|
||||||
|
when type in @supported_activities,
|
||||||
|
do: Visibility.is_public?(activity)
|
||||||
|
|
||||||
|
def is_representable?(_), do: false
|
||||||
|
|
||||||
def publish(topic, user, %{data: %{"type" => type}} = activity)
|
def publish(topic, user, %{data: %{"type" => type}} = activity)
|
||||||
when type in @supported_activities do
|
when type in @supported_activities do
|
||||||
response =
|
response =
|
||||||
|
@ -88,12 +101,14 @@ def publish(topic, user, %{data: %{"type" => type}} = activity)
|
||||||
unreachable_since: reachable_callbacks_metadata[sub.callback]
|
unreachable_since: reachable_callbacks_metadata[sub.callback]
|
||||||
}
|
}
|
||||||
|
|
||||||
Federator.publish_single_websub(data)
|
Publisher.enqueue_one(__MODULE__, data)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish(_, _, _), do: ""
|
def publish(_, _, _), do: ""
|
||||||
|
|
||||||
|
def publish(actor, activity), do: publish(Pleroma.Web.OStatus.feed_path(actor), actor, activity)
|
||||||
|
|
||||||
def sign(secret, doc) do
|
def sign(secret, doc) do
|
||||||
:crypto.hmac(:sha, secret, to_string(doc)) |> Base.encode16() |> String.downcase()
|
:crypto.hmac(:sha, secret, to_string(doc)) |> Base.encode16() |> String.downcase()
|
||||||
end
|
end
|
||||||
|
@ -299,4 +314,20 @@ def publish_one(%{xml: xml, topic: topic, callback: callback, secret: secret} =
|
||||||
{:error, response}
|
{:error, response}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def gather_webfinger_links(%User{} = user) do
|
||||||
|
[
|
||||||
|
%{
|
||||||
|
"rel" => "http://schemas.google.com/g/2010#updates-from",
|
||||||
|
"type" => "application/atom+xml",
|
||||||
|
"href" => OStatus.feed_path(user)
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
"rel" => "http://ostatus.org/schema/1.0/subscribe",
|
||||||
|
"template" => OStatus.remote_follow_path()
|
||||||
|
}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
def gather_nodeinfo_protocol_names, do: ["ostatus"]
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,6 +35,7 @@ def to_doc(content), do: ~s(<?xml version="1.0" encoding="UTF-8"?>) <> to_xml(co
|
||||||
defp make_open_tag(tag, attributes) do
|
defp make_open_tag(tag, attributes) do
|
||||||
attributes_string =
|
attributes_string =
|
||||||
for {attribute, value} <- attributes do
|
for {attribute, value} <- attributes do
|
||||||
|
value = String.replace(value, "\"", """)
|
||||||
"#{attribute}=\"#{value}\""
|
"#{attribute}=\"#{value}\""
|
||||||
end
|
end
|
||||||
|> Enum.join(" ")
|
|> Enum.join(" ")
|
||||||
|
|
17
mix.exs
17
mix.exs
|
@ -16,11 +16,11 @@ def project do
|
||||||
|
|
||||||
# Docs
|
# Docs
|
||||||
name: "Pleroma",
|
name: "Pleroma",
|
||||||
|
homepage_url: "https://pleroma.social/",
|
||||||
source_url: "https://git.pleroma.social/pleroma/pleroma",
|
source_url: "https://git.pleroma.social/pleroma/pleroma",
|
||||||
|
docs: [
|
||||||
source_url_pattern:
|
source_url_pattern:
|
||||||
"https://git.pleroma.social/pleroma/pleroma/blob/develop/%{path}#L%{line}",
|
"https://git.pleroma.social/pleroma/pleroma/blob/develop/%{path}#L%{line}",
|
||||||
homepage_url: "https://pleroma.social/",
|
|
||||||
docs: [
|
|
||||||
logo: "priv/static/static/logo.png",
|
logo: "priv/static/static/logo.png",
|
||||||
extras: ["README.md", "CHANGELOG.md"] ++ Path.wildcard("docs/**/*.md"),
|
extras: ["README.md", "CHANGELOG.md"] ++ Path.wildcard("docs/**/*.md"),
|
||||||
groups_for_extras: [
|
groups_for_extras: [
|
||||||
|
@ -41,7 +41,7 @@ def project do
|
||||||
def application do
|
def application do
|
||||||
[
|
[
|
||||||
mod: {Pleroma.Application, []},
|
mod: {Pleroma.Application, []},
|
||||||
extra_applications: [:logger, :runtime_tools, :comeonin, :quack],
|
extra_applications: [:logger, :runtime_tools, :comeonin, :esshd, :quack],
|
||||||
included_applications: [:ex_syslogger]
|
included_applications: [:ex_syslogger]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
@ -84,9 +84,10 @@ defp deps do
|
||||||
{:ex_aws, "~> 2.0"},
|
{:ex_aws, "~> 2.0"},
|
||||||
{:ex_aws_s3, "~> 2.0"},
|
{:ex_aws_s3, "~> 2.0"},
|
||||||
{:earmark, "~> 1.3"},
|
{:earmark, "~> 1.3"},
|
||||||
|
{:bbcode, "~> 0.1"},
|
||||||
{:ex_machina, "~> 2.3", only: :test},
|
{:ex_machina, "~> 2.3", only: :test},
|
||||||
{:credo, "~> 0.9.3", only: [:dev, :test]},
|
{:credo, "~> 0.9.3", only: [:dev, :test]},
|
||||||
{:mock, "~> 0.3.1", only: :test},
|
{:mock, "~> 0.3.3", only: :test},
|
||||||
{:crypt,
|
{:crypt,
|
||||||
git: "https://github.com/msantos/crypt", ref: "1f2b58927ab57e72910191a7ebaeff984382a1d3"},
|
git: "https://github.com/msantos/crypt", ref: "1f2b58927ab57e72910191a7ebaeff984382a1d3"},
|
||||||
{:cors_plug, "~> 1.5"},
|
{:cors_plug, "~> 1.5"},
|
||||||
|
@ -101,7 +102,7 @@ defp deps do
|
||||||
{:ueberauth, "~> 0.4"},
|
{:ueberauth, "~> 0.4"},
|
||||||
{:auto_linker,
|
{:auto_linker,
|
||||||
git: "https://git.pleroma.social/pleroma/auto_linker.git",
|
git: "https://git.pleroma.social/pleroma/auto_linker.git",
|
||||||
ref: "90613b4bae875a3610c275b7056b61ffdd53210d"},
|
ref: "c00c4e75b35367fa42c95ffd9b8c455bf9995829"},
|
||||||
{:pleroma_job_queue, "~> 0.2.0"},
|
{:pleroma_job_queue, "~> 0.2.0"},
|
||||||
{:telemetry, "~> 0.3"},
|
{:telemetry, "~> 0.3"},
|
||||||
{:prometheus_ex, "~> 3.0"},
|
{:prometheus_ex, "~> 3.0"},
|
||||||
|
@ -110,7 +111,11 @@ defp deps do
|
||||||
{:prometheus_ecto, "~> 1.4"},
|
{:prometheus_ecto, "~> 1.4"},
|
||||||
{:prometheus_process_collector, "~> 1.4"},
|
{:prometheus_process_collector, "~> 1.4"},
|
||||||
{:recon, github: "ferd/recon", tag: "2.4.0"},
|
{:recon, github: "ferd/recon", tag: "2.4.0"},
|
||||||
{:quack, "~> 0.1.1"}
|
{:quack, "~> 0.1.1"},
|
||||||
|
{:benchee, "~> 1.0"},
|
||||||
|
{:esshd, "~> 0.1.0"},
|
||||||
|
{:ex_rated, "~> 1.2"},
|
||||||
|
{:plug_static_index_html, "~> 1.0.0"}
|
||||||
] ++ oauth_deps
|
] ++ oauth_deps
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
11
mix.lock
11
mix.lock
|
@ -1,7 +1,9 @@
|
||||||
%{
|
%{
|
||||||
"accept": {:hex, :accept, "0.3.5", "b33b127abca7cc948bbe6caa4c263369abf1347cfa9d8e699c6d214660f10cd1", [:rebar3], [], "hexpm"},
|
"accept": {:hex, :accept, "0.3.5", "b33b127abca7cc948bbe6caa4c263369abf1347cfa9d8e699c6d214660f10cd1", [:rebar3], [], "hexpm"},
|
||||||
"auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "90613b4bae875a3610c275b7056b61ffdd53210d", [ref: "90613b4bae875a3610c275b7056b61ffdd53210d"]},
|
"auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "c00c4e75b35367fa42c95ffd9b8c455bf9995829", [ref: "c00c4e75b35367fa42c95ffd9b8c455bf9995829"]},
|
||||||
"base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [:rebar], [], "hexpm"},
|
"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"},
|
||||||
|
"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"},
|
"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"},
|
"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"},
|
||||||
"calendar": {:hex, :calendar, "0.17.4", "22c5e8d98a4db9494396e5727108dffb820ee0d18fed4b0aa8ab76e4f5bc32f1", [:mix], [{:tzdata, "~> 0.5.8 or ~> 0.1.201603", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
|
"calendar": {:hex, :calendar, "0.17.4", "22c5e8d98a4db9494396e5727108dffb820ee0d18fed4b0aa8ab76e4f5bc32f1", [:mix], [{:tzdata, "~> 0.5.8 or ~> 0.1.201603", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
|
@ -16,14 +18,18 @@
|
||||||
"crypt": {:git, "https://github.com/msantos/crypt", "1f2b58927ab57e72910191a7ebaeff984382a1d3", [ref: "1f2b58927ab57e72910191a7ebaeff984382a1d3"]},
|
"crypt": {:git, "https://github.com/msantos/crypt", "1f2b58927ab57e72910191a7ebaeff984382a1d3", [ref: "1f2b58927ab57e72910191a7ebaeff984382a1d3"]},
|
||||||
"db_connection": {:hex, :db_connection, "2.0.5", "ddb2ba6761a08b2bb9ca0e7d260e8f4dd39067426d835c24491a321b7f92a4da", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
|
"db_connection": {:hex, :db_connection, "2.0.5", "ddb2ba6761a08b2bb9ca0e7d260e8f4dd39067426d835c24491a321b7f92a4da", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"},
|
"decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"},
|
||||||
|
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm"},
|
||||||
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"},
|
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"},
|
||||||
"ecto": {:hex, :ecto, "3.0.7", "44dda84ac6b17bbbdeb8ac5dfef08b7da253b37a453c34ab1a98de7f7e5fec7f", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"},
|
"ecto": {:hex, :ecto, "3.0.7", "44dda84ac6b17bbbdeb8ac5dfef08b7da253b37a453c34ab1a98de7f7e5fec7f", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
"ecto_sql": {:hex, :ecto_sql, "3.0.5", "7e44172b4f7aca4469f38d7f6a3da394dbf43a1bcf0ca975e958cb957becd74e", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.6", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.3.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
|
"ecto_sql": {:hex, :ecto_sql, "3.0.5", "7e44172b4f7aca4469f38d7f6a3da394dbf43a1bcf0ca975e958cb957becd74e", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.6", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.3.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
|
"esshd": {:hex, :esshd, "0.1.0", "6f93a2062adb43637edad0ea7357db2702a4b80dd9683482fe00f5134e97f4c1", [:mix], [], "hexpm"},
|
||||||
"eternal": {:hex, :eternal, "1.2.0", "e2a6b6ce3b8c248f7dc31451aefca57e3bdf0e48d73ae5043229380a67614c41", [:mix], [], "hexpm"},
|
"eternal": {:hex, :eternal, "1.2.0", "e2a6b6ce3b8c248f7dc31451aefca57e3bdf0e48d73ae5043229380a67614c41", [:mix], [], "hexpm"},
|
||||||
|
"ex2ms": {:hex, :ex2ms, "1.5.0", "19e27f9212be9a96093fed8cdfbef0a2b56c21237196d26760f11dfcfae58e97", [:mix], [], "hexpm"},
|
||||||
"ex_aws": {:hex, :ex_aws, "2.1.0", "b92651527d6c09c479f9013caa9c7331f19cba38a650590d82ebf2c6c16a1d8a", [:mix], [{:configparser_ex, "~> 2.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "1.6.3 or 1.6.5 or 1.7.1 or 1.8.6 or ~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:poison, ">= 1.2.0", [hex: :poison, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:xml_builder, "~> 0.1.0", [hex: :xml_builder, repo: "hexpm", optional: true]}], "hexpm"},
|
"ex_aws": {:hex, :ex_aws, "2.1.0", "b92651527d6c09c479f9013caa9c7331f19cba38a650590d82ebf2c6c16a1d8a", [:mix], [{:configparser_ex, "~> 2.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "1.6.3 or 1.6.5 or 1.7.1 or 1.8.6 or ~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:poison, ">= 1.2.0", [hex: :poison, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:xml_builder, "~> 0.1.0", [hex: :xml_builder, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
"ex_aws_s3": {:hex, :ex_aws_s3, "2.0.1", "9e09366e77f25d3d88c5393824e613344631be8db0d1839faca49686e99b6704", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm"},
|
"ex_aws_s3": {:hex, :ex_aws_s3, "2.0.1", "9e09366e77f25d3d88c5393824e613344631be8db0d1839faca49686e99b6704", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
|
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"ex_machina": {:hex, :ex_machina, "2.3.0", "92a5ad0a8b10ea6314b876a99c8c9e3f25f4dde71a2a835845b136b9adaf199a", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm"},
|
"ex_machina": {:hex, :ex_machina, "2.3.0", "92a5ad0a8b10ea6314b876a99c8c9e3f25f4dde71a2a835845b136b9adaf199a", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
|
"ex_rated": {:hex, :ex_rated, "1.3.2", "6aeb32abb46ea6076f417a9ce8cb1cf08abf35fb2d42375beaad4dd72b550bf1", [:mix], [{:ex2ms, "~> 1.5", [hex: :ex2ms, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"ex_syslogger": {:git, "https://github.com/slashmili/ex_syslogger.git", "f3963399047af17e038897c69e20d552e6899e1d", [tag: "1.4.0"]},
|
"ex_syslogger": {:git, "https://github.com/slashmili/ex_syslogger.git", "f3963399047af17e038897c69e20d552e6899e1d", [tag: "1.4.0"]},
|
||||||
"floki": {:hex, :floki, "0.20.4", "be42ac911fece24b4c72f3b5846774b6e61b83fe685c2fc9d62093277fb3bc86", [:mix], [{:html_entities, "~> 0.4.0", [hex: :html_entities, repo: "hexpm", optional: false]}, {:mochiweb, "~> 2.15", [hex: :mochiweb, repo: "hexpm", optional: false]}], "hexpm"},
|
"floki": {:hex, :floki, "0.20.4", "be42ac911fece24b4c72f3b5846774b6e61b83fe685c2fc9d62093277fb3bc86", [:mix], [{:html_entities, "~> 0.4.0", [hex: :html_entities, repo: "hexpm", optional: false]}, {:mochiweb, "~> 2.15", [hex: :mochiweb, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"gen_smtp": {:hex, :gen_smtp, "0.13.0", "11f08504c4bdd831dc520b8f84a1dce5ce624474a797394e7aafd3c29f5dcd25", [:rebar3], [], "hexpm"},
|
"gen_smtp": {:hex, :gen_smtp, "0.13.0", "11f08504c4bdd831dc520b8f84a1dce5ce624474a797394e7aafd3c29f5dcd25", [:rebar3], [], "hexpm"},
|
||||||
|
@ -42,7 +48,7 @@
|
||||||
"mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"},
|
"mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"},
|
||||||
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"},
|
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"},
|
||||||
"mochiweb": {:hex, :mochiweb, "2.15.0", "e1daac474df07651e5d17cc1e642c4069c7850dc4508d3db7263a0651330aacc", [:rebar3], [], "hexpm"},
|
"mochiweb": {:hex, :mochiweb, "2.15.0", "e1daac474df07651e5d17cc1e642c4069c7850dc4508d3db7263a0651330aacc", [:rebar3], [], "hexpm"},
|
||||||
"mock": {:hex, :mock, "0.3.1", "994f00150f79a0ea50dc9d86134cd9ebd0d177ad60bd04d1e46336cdfdb98ff9", [:mix], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
|
"mock": {:hex, :mock, "0.3.3", "42a433794b1291a9cf1525c6d26b38e039e0d3a360732b5e467bfc77ef26c914", [:mix], [{:meck, "~> 0.8.13", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"mogrify": {:hex, :mogrify, "0.6.1", "de1b527514f2d95a7bbe9642eb556061afb337e220cf97adbf3a4e6438ed70af", [:mix], [], "hexpm"},
|
"mogrify": {:hex, :mogrify, "0.6.1", "de1b527514f2d95a7bbe9642eb556061afb337e220cf97adbf3a4e6438ed70af", [:mix], [], "hexpm"},
|
||||||
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
|
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
|
||||||
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
|
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
|
||||||
|
@ -55,6 +61,7 @@
|
||||||
"plug": {:hex, :plug, "1.7.2", "d7b7db7fbd755e8283b6c0a50be71ec0a3d67d9213d74422d9372effc8e87fd1", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"},
|
"plug": {:hex, :plug, "1.7.2", "d7b7db7fbd755e8283b6c0a50be71ec0a3d67d9213d74422d9372effc8e87fd1", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"plug_cowboy": {:hex, :plug_cowboy, "2.0.1", "d798f8ee5acc86b7d42dbe4450b8b0dadf665ce588236eb0a751a132417a980e", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
|
"plug_cowboy": {:hex, :plug_cowboy, "2.0.1", "d798f8ee5acc86b7d42dbe4450b8b0dadf665ce588236eb0a751a132417a980e", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
|
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
|
||||||
|
"plug_static_index_html": {:hex, :plug_static_index_html, "1.0.0", "840123d4d3975585133485ea86af73cb2600afd7f2a976f9f5fd8b3808e636a0", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
|
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
|
||||||
"poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm"},
|
"poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm"},
|
||||||
"postgrex": {:hex, :postgrex, "0.14.1", "63247d4a5ad6b9de57a0bac5d807e1c32d41e39c04b8a4156a26c63bcd8a2e49", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
|
"postgrex": {:hex, :postgrex, "0.14.1", "63247d4a5ad6b9de57a0bac5d807e1c32d41e39c04b8a4156a26c63bcd8a2e49", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
|
|
26
priv/repo/migrations/20190408123347_create_conversations.exs
Normal file
26
priv/repo/migrations/20190408123347_create_conversations.exs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Repo.Migrations.CreateConversations do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create table(:conversations) do
|
||||||
|
add(:ap_id, :string, null: false)
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
create table(:conversation_participations) do
|
||||||
|
add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
|
||||||
|
add(:conversation_id, references(:conversations, on_delete: :delete_all))
|
||||||
|
add(:read, :boolean, default: false)
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
create index(:conversation_participations, [:conversation_id])
|
||||||
|
create unique_index(:conversation_participations, [:user_id, :conversation_id])
|
||||||
|
create unique_index(:conversations, [:ap_id])
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.AddParticipationUpdatedAtIndex do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create index(:conversation_participations, ["updated_at desc"])
|
||||||
|
end
|
||||||
|
end
|
14
priv/repo/migrations/20190413082658_create_bookmarks.exs
Normal file
14
priv/repo/migrations/20190413082658_create_bookmarks.exs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.CreateBookmarks do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create table(:bookmarks) do
|
||||||
|
add(:user_id, references(:users, type: :uuid, on_delete: :delete_all))
|
||||||
|
add(:activity_id, references(:activities, type: :uuid, on_delete: :delete_all))
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
create(unique_index(:bookmarks, [:user_id, :activity_id]))
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,29 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.MigrateOldBookmarks do
|
||||||
|
use Ecto.Migration
|
||||||
|
import Ecto.Query
|
||||||
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Bookmark
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Repo
|
||||||
|
|
||||||
|
def change do
|
||||||
|
query =
|
||||||
|
from(u in User,
|
||||||
|
where: u.local == true,
|
||||||
|
where: fragment("array_length(bookmarks, 1)") > 0,
|
||||||
|
select: %{id: u.id, bookmarks: fragment("bookmarks")}
|
||||||
|
)
|
||||||
|
|
||||||
|
Repo.stream(query)
|
||||||
|
|> Enum.each(fn %{id: user_id, bookmarks: bookmarks} ->
|
||||||
|
Enum.each(bookmarks, fn ap_id ->
|
||||||
|
activity = Activity.get_create_by_object_ap_id(ap_id)
|
||||||
|
unless is_nil(activity), do: {:ok, _} = Bookmark.create(user_id, activity.id)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
alter table(:users) do
|
||||||
|
remove(:bookmarks)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.AddFTSIndexToObjects do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
drop_if_exists index(:activities, ["(to_tsvector('english', data->'object'->>'content'))"], using: :gin, name: :activities_fts)
|
||||||
|
create index(:objects, ["(to_tsvector('english', data->>'content'))"], using: :gin, name: :objects_fts)
|
||||||
|
end
|
||||||
|
end
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue