1package OpenXPKI::Server::API2::Plugin::UI::get_motd;
2use OpenXPKI::Server::API2::EasyPlugin;
3
4=head1 NAME
5
6OpenXPKI::Server::API2::Plugin::UI::get_motd
7
8=cut
9
10# Project modules
11use OpenXPKI::Server::Context qw( CTX );
12use OpenXPKI::Server::API2::Types;
13
14
15
16=head1 COMMANDS
17
18=head2 get_motd
19
20Returns the message of the day (MOTD, from the datapool).
21
22By default, the MOTD for the current users' role is returned. Another role
23can be specified.
24
25B<Parameters>
26
27=over
28
29=item * C<role> I<Str> - user role for which the motd shall be returned.
30
31=back
32
33=cut
34command "get_motd" => {
35    role => { isa => 'Value', },
36} => sub {
37    my ($self, $params) = @_;
38
39
40    my $role = $params->has_role ? $params->role : CTX('session')->data->role;
41
42    # role is used as DP Key, can also be "_any"
43    my $datapool = $self->api->get_data_pool_entry(
44        namespace => 'webui.motd',
45        key       => $role,
46    );
47    ##! 16: 'Item for role ' . $role .': ' . Dumper $datapool
48
49    # nothing found for given role, so try _any
50    if (not $datapool) {
51        $datapool = $self->api->get_data_pool_entry(
52            namespace => 'webui.motd',
53            key       => '_any'
54        );
55        ##! 16: 'Item for _any: ' . Dumper $datapool
56    }
57
58    return unless $datapool;
59
60    return OpenXPKI::Serialization::Simple->new->deserialize($datapool->{value});
61};
62
63__PACKAGE__->meta->make_immutable;
64