Skip to content

Commit

Permalink
Remove handles and scores from spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
F3Joule committed Jun 29, 2022
1 parent 3f309c6 commit 6e7e32d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 73 deletions.
46 changes: 1 addition & 45 deletions pallets/spaces/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! # Spaces Module
//!
//! Spaces are the primary components of Subsocial. This module allows you to create a Space
//! and customize it by updating its' owner(s), content, unique handle, and permissions.
//! and customize it by updating its' owner(s), content, and permissions.
//!
//! To understand how Spaces fit into the Subsocial ecosystem, you can think of how
//! folders and files work in a file system. Spaces are similar to folders, that can contain Posts,
Expand Down Expand Up @@ -65,9 +65,6 @@ pub mod pallet {

type IsContentBlocked: IsContentBlocked;

#[pallet::constant]
type MaxHandleLen: Get<u32>;

#[pallet::constant]
type MaxSpacesPerAccount: Get<u32>;
}
Expand All @@ -89,10 +86,6 @@ pub mod pallet {
pub enum Error<T> {
/// Space was not found by id.
SpaceNotFound,
/// Space handle is not unique.
SpaceHandleIsNotUnique,
/// Handles are disabled in `PalletSettings`.
HandlesAreDisabled,
/// Nothing to update in this space.
NoUpdatesForSpace,
/// Only space owners can manage this space.
Expand Down Expand Up @@ -124,22 +117,12 @@ pub mod pallet {
#[pallet::getter(fn space_by_id)]
pub type SpaceById<T: Config> = StorageMap<_, Twox64Concat, SpaceId, Space<T>>;

/// Find a given space id by its' unique handle.
/// If a handle is not registered, nothing will be returned (`None`).
#[pallet::storage]
#[pallet::getter(fn space_id_by_handle)]
pub type SpaceIdByHandle<T: Config> = StorageMap<_, Blake2_128Concat, Handle<T>, SpaceId>;

/// Find the ids of all spaces owned, by a given account.
#[pallet::storage]
#[pallet::getter(fn space_ids_by_owner)]
pub type SpaceIdsByOwner<T: Config> =
StorageMap<_, Twox64Concat, T::AccountId, SpacesByAccount<T>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn settings)]
pub type PalletSettings<T: Config> = StorageValue<_, SpacesSettings, ValueQuery>;

#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub endowed_account: Option<T::AccountId>,
Expand All @@ -165,15 +148,11 @@ pub mod pallet {
pub fn create_space(
origin: OriginFor<T>,
parent_id_opt: Option<SpaceId>,
// FIXME: unused since domains release
handle_opt: Option<Vec<u8>>,
content: Content,
permissions_opt: Option<SpacePermissions>,
) -> DispatchResultWithPostInfo {
let owner = ensure_signed(origin)?;

ensure!(handle_opt.is_none(), Error::<T>::HandlesAreDisabled);

ensure_content_is_valid(content.clone())?;

Self::ensure_space_limit_not_reached(&owner)?;
Expand Down Expand Up @@ -206,7 +185,6 @@ pub mod pallet {
let new_space =
&mut Space::new(space_id, parent_id_opt, owner.clone(), content, permissions);

// FIXME: What's about handle reservation if this fails?
T::BeforeSpaceCreated::before_space_created(owner.clone(), new_space)?;

SpaceById::<T>::insert(space_id, new_space);
Expand Down Expand Up @@ -234,8 +212,6 @@ pub mod pallet {

ensure!(has_updates, Error::<T>::NoUpdatesForSpace);

ensure!(update.handle.is_none(), Error::<T>::HandlesAreDisabled);

let mut space = Self::require_space(space_id)?;

ensure!(
Expand Down Expand Up @@ -327,21 +303,6 @@ pub mod pallet {
}
Ok(())
}

#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1, 1))]
pub fn update_settings(
origin: OriginFor<T>,
new_settings: SpacesSettings,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;

let space_settings = Self::settings();
ensure!(space_settings != new_settings, Error::<T>::NoUpdatesForSpacesSettings);

PalletSettings::<T>::mutate(|settings| *settings = new_settings);

Ok(().into())
}
}

impl<T: Config> Pallet<T> {
Expand Down Expand Up @@ -393,11 +354,6 @@ pub mod pallet {
T::Roles::ensure_account_has_space_permission(account, ctx, permission, error)
}

pub fn ensure_handles_enabled() -> DispatchResult {
ensure!(Self::settings().handles_enabled, Error::<T>::HandlesAreDisabled);
Ok(())
}

pub fn try_move_space_to_root(space_id: SpaceId) -> DispatchResult {
let mut space = Self::require_space(space_id)?;
space.parent_id = None;
Expand Down
22 changes: 0 additions & 22 deletions pallets/spaces/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use super::*;

pub const FIRST_SPACE_ID: u64 = 1;
pub const RESERVED_SPACE_COUNT: u64 = 1000;
pub const DEFAULT_MAX_HANDLE_LEN: u32 = 50;

pub(crate) type Handle<T> = BoundedVec<u8, <T as Config>::MaxHandleLen>;
pub(crate) type SpacesByAccount<T> = BoundedVec<SpaceId, <T as Config>::MaxSpacesPerAccount>;

/// Information about a space's owner, its' content, visibility and custom permissions.
Expand All @@ -27,10 +25,6 @@ pub struct Space<T: Config> {
// The next fields can be updated by the owner:
pub(super) parent_id: Option<SpaceId>,

/// Unique alpha-numeric identifier that can be used in a space's URL.
/// Handle can only contain numbers, letter and underscore: `0`-`9`, `a`-`z`, `_`.
pub handle: Option<Handle<T>>,

pub content: Content,

/// Hidden field is used to recommend to end clients (web and mobile apps) that a particular
Expand All @@ -46,8 +40,6 @@ pub struct Space<T: Config> {
/// The number of account following a given space.
pub followers_count: u32,

pub(super) score: i32,

/// This allows you to override Subsocial's default permissions by enabling or disabling role
/// permissions.
pub permissions: Option<SpacePermissions>,
Expand All @@ -56,23 +48,11 @@ pub struct Space<T: Config> {
#[derive(Encode, Decode, Clone, Eq, PartialEq, Default, RuntimeDebug, TypeInfo)]
pub struct SpaceUpdate {
pub parent_id: Option<Option<SpaceId>>,
pub handle: Option<Option<Vec<u8>>>,
pub content: Option<Content>,
pub hidden: Option<bool>,
pub permissions: Option<Option<SpacePermissions>>,
}

#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct SpacesSettings {
pub handles_enabled: bool,
}

impl Default for SpacesSettings {
fn default() -> Self {
Self { handles_enabled: true }
}
}

impl<T: Config> Space<T> {
pub fn new(
id: SpaceId,
Expand All @@ -87,13 +67,11 @@ impl<T: Config> Space<T> {
updated: None,
owner: created_by,
parent_id,
handle: Default::default(),
content,
hidden: false,
posts_count: 0,
hidden_posts_count: 0,
followers_count: 0,
score: 0,
permissions,
}
}
Expand Down
6 changes: 0 additions & 6 deletions pallets/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,6 @@ pub enum Error {
RawContentTypeNotSupported,
/// `Hyper` content type is not yet supported.
HypercoreContentTypeNotSupported,
/// Space handle is too short.
HandleIsTooShort,
/// Space handle is too long.
HandleIsTooLong,
/// Space handle contains invalid characters.
HandleContainsInvalidChars,
/// Content type is `None`.
ContentIsEmpty,
}
Expand Down

0 comments on commit 6e7e32d

Please sign in to comment.