Explore this module further in the Mover Registry: @sage/shared
Structs
Moderation
Table of User
s authorized to take moderator actions on a forum.
public struct Moderation has store
moderation : sui :: table :: Table < address , u8 >
Constants
Represents that the moderator is the owner.
Represents that the moderator has the lowest permissions.
Represents that a moderator was added.
const MODERATOR_ADD : u8 = 10 ;
Represents that a moderator was removed.
const MODERATOR_REMOVE : u8 = 11 ;
Error code used when a moderator tries to remove the owner.
const EIsOwner : u64 = 370 ;
Error code used when a non-moderator attempts a moderator action.
const EIsNotModerator : u64 = 371 ;
Error code used when a non-owner attempts an owner action.
const EIsNotOwner : u64 = 372 ;
Functions
assert_is_moderator
Aborts with EIsNotModerator
if the user is not a moderator or owner.
public fun assert_is_moderator ( moderation : & Moderation , user : address )
public fun assert_is_moderator (
moderation : & Moderation ,
user : address
) {
let is_moderator = is_moderator (
moderation ,
user
);
assert! ( is_moderator , EIsNotModerator );
}
assert_is_owner
Aborts with EIsNotOwner
if the user is not the owner.
public fun assert_is_owner ( moderation : & Moderation , user : address )
public fun assert_is_owner (
moderation : & Moderation ,
user : address
) {
let is_owner = is_owner (
moderation ,
user
);
assert! ( is_owner , EIsNotOwner );
}
create
Creates a new Moderation
instance.
public fun create ( ctx : & mut TxContext ) : ( Moderation , u8 , u8 )
public fun create (
ctx : & mut TxContext
) : ( Moderation , u8 , u8 ) {
let self = tx_context :: sender ( ctx );
let mut moderation = Moderation {
moderation : table :: new ( ctx )
};
let ( event , message ) = make_owner (
& mut moderation ,
self
);
( moderation , event , message )
}
get_length
Get number of moderators and owners.
public fun get_length ( moderation : & Moderation ) : u64
public fun get_length (
moderation : & Moderation
) : u64 {
moderation . moderation . length ()
}
is_moderator
Returns true or false based on whether the address is a moderator.
public fun is_moderator ( moderation : & Moderation , user : address ) : bool
public fun is_moderator (
moderation : & Moderation ,
user : address
) : bool {
moderation . moderation . contains ( user )
}
is_owner
Returns true or false based on whether the address is the owner.
public fun is_owner ( moderation : & Moderation , user : address ) : bool
public fun is_owner (
moderation : & Moderation ,
user : address
) : bool {
let is_moderator = is_moderator (
moderation ,
user
);
if ( ! is_moderator ) {
false
} else {
moderation . moderation[ user ] == OWNER
}
}
make_moderator
Adds the address as a moderator.
public fun make_moderator ( moderation : & mut Moderation , user : address ) : ( u8 , u8 )
public fun make_moderator (
moderation : & mut Moderation ,
user : address
) : ( u8 , u8 ) {
moderation . moderation . add (
user ,
MODERATOR
);
( MODERATOR_ADD , MODERATOR )
}
make_owner
Adds the address as the owner.
public fun make_owner ( moderation : & mut Moderation , user : address ) : ( u8 , u8 )
public fun make_owner (
moderation : & mut Moderation ,
user : address
) : ( u8 , u8 ) {
moderation . moderation . add (
user ,
OWNER
);
( MODERATOR_ADD , OWNER )
}
remove_moderator
Removes the address as a moderator. Aborts with EIsOwner
if attempting to remove the owner.
public fun remove_moderator ( moderation : & mut Moderation , user : address ) : ( u8 , u8 )
public fun remove_moderator (
moderation : & mut Moderation ,
user : address
) : ( u8 , u8 ) {
let is_owner = is_owner (
moderation ,
user
);
assert! ( ! is_owner , EIsOwner );
moderation . moderation . remove ( user );
( MODERATOR_REMOVE , MODERATOR )
}