Take community id's instead of hosts

This commit is contained in:
jaina heartles 2022-10-03 22:57:09 -07:00
parent d6cf778053
commit 69a51a7d7f

View file

@ -29,8 +29,9 @@ pub const InviteRequest = struct {
lifespan: ?DateTime.Duration = null,
max_uses: ?u16 = null,
kind: Kind = .user, // must be user unless the creator is an admin
to_community: ?[]const u8 = null, // only valid on admin community
// admin only options
kind: Kind = .user,
to_community: ?Uuid = null,
};
pub const LoginResponse = services.auth.LoginResult;
@ -264,14 +265,11 @@ fn ApiConn(comptime DbConn: type) type {
// Only logged in users can make invites
const user_id = self.user_id orelse return error.TokenRequired;
const community_id = if (options.to_community) |host| blk: {
// You can only specify a different community if you're on the admin domain
if (self.community.kind != .admin) return error.WrongCommunity;
// Only admins can invite on the admin domain
const community_id = if (options.to_community) |id| blk: {
// Only admins can send invites for other communities
if (!self.isAdmin()) return error.PermissionDenied;
break :blk (try services.communities.getByHost(self.db, host, self.arena.allocator())).id;
break :blk id;
} else self.community.id;
// Users can only make user invites