add: implement 9 new scopes, 21 new api endpoints
This commit is contained in:
parent
c3139ef1d2
commit
8f16068a34
14 changed files with 973 additions and 35 deletions
|
@ -136,7 +136,7 @@ impl DataManager {
|
|||
/// * `id` - the ID of the post the requested posts are commenting on
|
||||
/// * `batch` - the limit of posts in each page
|
||||
/// * `page` - the page number
|
||||
pub async fn get_post_comments(
|
||||
pub async fn get_replies_by_post(
|
||||
&self,
|
||||
id: usize,
|
||||
batch: usize,
|
||||
|
@ -517,6 +517,30 @@ impl DataManager {
|
|||
out
|
||||
}
|
||||
|
||||
/// Filter to update posts to clean their owner for public APIs.
|
||||
pub fn posts_owner_filter(&self, posts: &Vec<FullPost>) -> Vec<FullPost> {
|
||||
let mut out: Vec<FullPost> = Vec::new();
|
||||
|
||||
for mut post in posts.clone() {
|
||||
post.1.clean();
|
||||
|
||||
// reposting
|
||||
if let Some((ref mut x, _)) = post.3 {
|
||||
x.clean();
|
||||
}
|
||||
|
||||
// question
|
||||
if let Some((_, ref mut x)) = post.4 {
|
||||
x.clean();
|
||||
}
|
||||
|
||||
// ...
|
||||
out.push(post);
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
/// Get all posts from the given user (from most recent).
|
||||
///
|
||||
/// # Arguments
|
||||
|
|
|
@ -27,7 +27,7 @@ impl DataManager {
|
|||
}
|
||||
}
|
||||
|
||||
auto_method!(get_user_warning_by_ip(&str)@get_user_warning_from_row -> "SELECT * FROM user_warnings WHERE ip = $1" --name="user warning" --returns=UserWarning --cache-key-tmpl="atto.user_warning:{}");
|
||||
auto_method!(get_user_warning_by_id(usize)@get_user_warning_from_row -> "SELECT * FROM user_warnings WHERE id = $1" --name="user warning" --returns=UserWarning --cache-key-tmpl="atto.user_warning:{}");
|
||||
|
||||
/// Get all user warnings by user (paginated).
|
||||
///
|
||||
|
|
|
@ -28,6 +28,18 @@ impl DataManager {
|
|||
|
||||
auto_method!(get_userfollow_by_id()@get_userfollow_from_row -> "SELECT * FROM userfollows WHERE id = $1" --name="user follow" --returns=UserFollow --cache-key-tmpl="atto.userfollow:{}");
|
||||
|
||||
/// Filter to update userfollows to clean their users for public APIs.
|
||||
pub fn userfollows_user_filter(&self, x: &Vec<(UserFollow, User)>) -> Vec<(UserFollow, User)> {
|
||||
let mut out: Vec<(UserFollow, User)> = Vec::new();
|
||||
|
||||
for mut y in x.clone() {
|
||||
y.1.clean();
|
||||
out.push(y);
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
/// Get a user follow by `initiator` and `receiver` (in that order).
|
||||
pub async fn get_userfollow_by_initiator_receiver(
|
||||
&self,
|
||||
|
|
|
@ -387,6 +387,22 @@ impl User {
|
|||
)
|
||||
.ok()
|
||||
}
|
||||
|
||||
/// Clean the struct for public viewing.
|
||||
pub fn clean(&mut self) {
|
||||
self.password = String::new();
|
||||
self.salt = String::new();
|
||||
|
||||
self.tokens = Vec::new();
|
||||
self.grants = Vec::new();
|
||||
|
||||
self.recovery_codes = Vec::new();
|
||||
self.totp = String::new();
|
||||
|
||||
self.settings = UserSettings::default();
|
||||
self.stripe_id = String::new();
|
||||
self.connections = HashMap::new();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
|
@ -446,7 +462,7 @@ impl Notification {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct UserFollow {
|
||||
pub id: usize,
|
||||
pub created: usize,
|
||||
|
|
|
@ -36,6 +36,8 @@ pub enum PkceChallengeMethod {
|
|||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum AppScope {
|
||||
/// Read the profile of other user's on behalf of the user.
|
||||
UserReadProfiles,
|
||||
/// Read the user's profile (username, bio, etc).
|
||||
UserReadProfile,
|
||||
/// Read the user's settings.
|
||||
|
@ -52,6 +54,10 @@ pub enum AppScope {
|
|||
UserReadCommunities,
|
||||
/// Connect to sockets on the user's behalf.
|
||||
UserReadSockets,
|
||||
/// Read the user's notifications.
|
||||
UserReadNotifications,
|
||||
/// Read the user's requests.
|
||||
UserReadRequests,
|
||||
/// Create posts as the user.
|
||||
UserCreatePosts,
|
||||
/// Create messages as the user.
|
||||
|
@ -82,6 +88,16 @@ pub enum AppScope {
|
|||
///
|
||||
/// Also includes managing the membership of users in the user's communities.
|
||||
UserManageMemberships,
|
||||
/// Follow/unfollow users on behalf of the user.
|
||||
UserManageFollowing,
|
||||
/// Accept follow requests on behalf of the user.
|
||||
UserManageFollowers,
|
||||
/// Block/unblock users on behalf of the user.
|
||||
UserManageBlocks,
|
||||
/// Manage the user's notifications.
|
||||
UserManageNotifications,
|
||||
/// Manage the user's requests.
|
||||
UserManageRequests,
|
||||
/// Edit posts created by the user.
|
||||
UserEditPosts,
|
||||
/// Edit drafts created by the user.
|
||||
|
@ -94,6 +110,8 @@ pub enum AppScope {
|
|||
ModPurgePosts,
|
||||
/// Restore deleted posts.
|
||||
ModDeletePosts,
|
||||
/// Manage user warnings.
|
||||
ModManageWarnings,
|
||||
/// Get a list of all emojis available to the user.
|
||||
UserReadEmojis,
|
||||
/// Create emojis on behalf of the user.
|
||||
|
@ -116,6 +134,7 @@ impl AppScope {
|
|||
let mut out: Vec<AppScope> = Vec::new();
|
||||
for scope in input.split(" ") {
|
||||
out.push(match scope {
|
||||
"user-read-profiles" => Self::UserReadProfiles,
|
||||
"user-read-profile" => Self::UserReadProfile,
|
||||
"user-read-settings" => Self::UserReadSettings,
|
||||
"user-read-sessions" => Self::UserReadSessions,
|
||||
|
@ -124,6 +143,8 @@ impl AppScope {
|
|||
"user-read-drafts" => Self::UserReadDrafts,
|
||||
"user-read-communities" => Self::UserReadCommunities,
|
||||
"user-read-sockets" => Self::UserReadSockets,
|
||||
"user-read-notifications" => Self::UserReadNotifications,
|
||||
"user-read-requests" => Self::UserReadRequests,
|
||||
"user-create-posts" => Self::UserCreatePosts,
|
||||
"user-create-messages" => Self::UserCreateMessages,
|
||||
"user-create-questions" => Self::UserCreateQuestions,
|
||||
|
@ -138,12 +159,18 @@ impl AppScope {
|
|||
"user-manage-stacks" => Self::UserManageStacks,
|
||||
"user-manage-relationships" => Self::UserManageRelationships,
|
||||
"user-manage-memberships" => Self::UserManageMemberships,
|
||||
"user-manage-following" => Self::UserManageFollowing,
|
||||
"user-manage-followers" => Self::UserManageFollowers,
|
||||
"user-manage-blocks" => Self::UserManageBlocks,
|
||||
"user-manage-notifications" => Self::UserManageNotifications,
|
||||
"user-manage-requests" => Self::UserManageRequests,
|
||||
"user-edit-posts" => Self::UserEditPosts,
|
||||
"user-edit-drafts" => Self::UserEditDrafts,
|
||||
"user-vote" => Self::UserVote,
|
||||
"user-join-communities" => Self::UserJoinCommunities,
|
||||
"mod-purge-posts" => Self::ModPurgePosts,
|
||||
"mod-delete-posts" => Self::ModDeletePosts,
|
||||
"mod-manage-warnings" => Self::ModManageWarnings,
|
||||
"user-read-emojis" => Self::UserReadEmojis,
|
||||
"community-create-emojis" => Self::CommunityCreateEmojis,
|
||||
"community-manage-emojis" => Self::CommunityManageEmojis,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue