mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-06-04 06:02:40 +02:00
Added permission check and fixed cart modification notification
This commit is contained in:
parent
18539d5282
commit
daf04dc774
@ -36,7 +36,6 @@
|
|||||||
#include "rdapplication.h"
|
#include "rdapplication.h"
|
||||||
#include "rdcart.h"
|
#include "rdcart.h"
|
||||||
#include "rdschedcode.h"
|
#include "rdschedcode.h"
|
||||||
#include "rdnotification.h"
|
|
||||||
|
|
||||||
#include "rdmetadata.h"
|
#include "rdmetadata.h"
|
||||||
|
|
||||||
@ -45,17 +44,10 @@ MainObject::MainObject(QObject *parent)
|
|||||||
{
|
{
|
||||||
QString err_msg;
|
QString err_msg;
|
||||||
|
|
||||||
verbose=false;
|
quiet=false;
|
||||||
cartnum=0;
|
cartnum=0;
|
||||||
year=0;
|
year=0;
|
||||||
|
bpm=0;
|
||||||
//
|
|
||||||
// Check for root permission
|
|
||||||
//
|
|
||||||
if(geteuid()!=0) {
|
|
||||||
fprintf(stderr,"rdmetadata: must be user \"root\"\n");
|
|
||||||
exit(256);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Open the Database
|
// Open the Database
|
||||||
@ -127,8 +119,8 @@ MainObject::MainObject(QObject *parent)
|
|||||||
rem_schedcode=rda->cmdSwitch()->value(i);
|
rem_schedcode=rda->cmdSwitch()->value(i);
|
||||||
rda->cmdSwitch()->setProcessed(i,true);
|
rda->cmdSwitch()->setProcessed(i,true);
|
||||||
}
|
}
|
||||||
if(rda->cmdSwitch()->key(i)=="--verbose") {
|
if(rda->cmdSwitch()->key(i)=="--quiet") {
|
||||||
verbose=true;
|
quiet=true;
|
||||||
rda->cmdSwitch()->setProcessed(i,true);
|
rda->cmdSwitch()->setProcessed(i,true);
|
||||||
}
|
}
|
||||||
if(!rda->cmdSwitch()->processed(i)) {
|
if(!rda->cmdSwitch()->processed(i)) {
|
||||||
@ -184,6 +176,24 @@ MainObject::MainObject(QObject *parent)
|
|||||||
|
|
||||||
void MainObject::userChangedData()
|
void MainObject::userChangedData()
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
// Get User Context
|
||||||
|
//
|
||||||
|
disconnect(rda->ripc(),SIGNAL(userChanged()),this,SLOT(userChangedData()));
|
||||||
|
|
||||||
|
//
|
||||||
|
// Verify Permissions
|
||||||
|
//
|
||||||
|
if(!rda->user()->modifyCarts()) {
|
||||||
|
fprintf(stderr,"%s",
|
||||||
|
qPrintable(QString("rdmetadata: user \"%1\" has no modify carts permission\n")
|
||||||
|
.arg(rda->user()->name())));
|
||||||
|
rda->log(RDConfig::LogErr,
|
||||||
|
QString("rdmetadata: user \"%1\" has no modify carts permission\n")
|
||||||
|
.arg(rda->user()->name()));
|
||||||
|
exit(256);
|
||||||
|
}
|
||||||
|
|
||||||
updateMetadata();
|
updateMetadata();
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -204,17 +214,17 @@ void MainObject::updateMetadata()
|
|||||||
|
|
||||||
schedcodes=cart->schedCodesList();
|
schedcodes=cart->schedCodesList();
|
||||||
|
|
||||||
if(!artist.isNull()) {
|
if(!artist.isEmpty()) {
|
||||||
cart->setArtist(artist);
|
cart->setArtist(artist);
|
||||||
Print(QString("rdmetadata: Set cart %1 artist to '%2'").arg(cartstring).arg(artist));
|
Print(QString("rdmetadata: Set cart %1 artist to '%2'").arg(cartstring).arg(artist));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!title.isNull()) {
|
if(!title.isEmpty()) {
|
||||||
cart->setTitle(title);
|
cart->setTitle(title);
|
||||||
Print(QString("rdmetadata: Set cart %1 title to '%2'").arg(cartstring).arg(title));
|
Print(QString("rdmetadata: Set cart %1 title to '%2'").arg(cartstring).arg(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!album.isNull()) {
|
if(!album.isEmpty()) {
|
||||||
cart->setAlbum(album);
|
cart->setAlbum(album);
|
||||||
Print(QString("rdmetadata: Set cart %1 album to '%2'").arg(cartstring).arg(album));
|
Print(QString("rdmetadata: Set cart %1 album to '%2'").arg(cartstring).arg(album));
|
||||||
}
|
}
|
||||||
@ -224,32 +234,32 @@ void MainObject::updateMetadata()
|
|||||||
Print(QString("rdmetadata: Set cart %1 year to '%2'").arg(cartstring).arg(year));
|
Print(QString("rdmetadata: Set cart %1 year to '%2'").arg(cartstring).arg(year));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!conductor.isNull()) {
|
if(!conductor.isEmpty()) {
|
||||||
cart->setConductor(conductor);
|
cart->setConductor(conductor);
|
||||||
Print(QString("rdmetadata: Set cart %1 conductor to '%2'").arg(cartstring).arg(conductor));
|
Print(QString("rdmetadata: Set cart %1 conductor to '%2'").arg(cartstring).arg(conductor));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!label.isNull()) {
|
if(!label.isEmpty()) {
|
||||||
cart->setLabel(label);
|
cart->setLabel(label);
|
||||||
Print(QString("rdmetadata: Set cart %1 label to '%2'").arg(cartstring).arg(label));
|
Print(QString("rdmetadata: Set cart %1 label to '%2'").arg(cartstring).arg(label));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!agency.isNull()) {
|
if(!agency.isEmpty()) {
|
||||||
cart->setAgency(agency);
|
cart->setAgency(agency);
|
||||||
Print(QString("rdmetadata: Set cart %1 agency to '%2'").arg(cartstring).arg(agency));
|
Print(QString("rdmetadata: Set cart %1 agency to '%2'").arg(cartstring).arg(agency));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!publisher.isNull()) {
|
if(!publisher.isEmpty()) {
|
||||||
cart->setPublisher(publisher);
|
cart->setPublisher(publisher);
|
||||||
Print(QString("rdmetadata: Set cart %1 publisher to '%2'").arg(cartstring).arg(publisher));
|
Print(QString("rdmetadata: Set cart %1 publisher to '%2'").arg(cartstring).arg(publisher));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!composer.isNull()) {
|
if(!composer.isEmpty()) {
|
||||||
cart->setComposer(composer);
|
cart->setComposer(composer);
|
||||||
Print(QString("rdmetadata: Set cart %1 composer to '%2'").arg(cartstring).arg(composer));
|
Print(QString("rdmetadata: Set cart %1 composer to '%2'").arg(cartstring).arg(composer));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!songid.isNull()) {
|
if(!songid.isEmpty()) {
|
||||||
cart->setSongId(songid);
|
cart->setSongId(songid);
|
||||||
Print(QString("rdmetadata: Set cart %1 songid to '%2'").arg(cartstring).arg(songid));
|
Print(QString("rdmetadata: Set cart %1 songid to '%2'").arg(cartstring).arg(songid));
|
||||||
}
|
}
|
||||||
@ -271,16 +281,27 @@ void MainObject::updateMetadata()
|
|||||||
|
|
||||||
delete cart;
|
delete cart;
|
||||||
|
|
||||||
RDNotification *notify=new RDNotification(
|
SendNotification(RDNotification::ModifyAction,cartnum);
|
||||||
RDNotification::CartType,RDNotification::ModifyAction,QVariant(cartnum));
|
}
|
||||||
|
|
||||||
|
void MainObject::SendNotification(RDNotification::Action action,unsigned cartnum)
|
||||||
|
{
|
||||||
|
RDNotification *notify=
|
||||||
|
new RDNotification(RDNotification::CartType,action,QVariant(cartnum));
|
||||||
rda->ripc()->sendNotification(*notify);
|
rda->ripc()->sendNotification(*notify);
|
||||||
delete notify;
|
delete notify;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Allow the notification to be processed
|
||||||
|
//
|
||||||
|
qApp->processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MainObject::Print(const QString &msg)
|
void MainObject::Print(const QString &msg)
|
||||||
{
|
{
|
||||||
if(verbose) {
|
if(!quiet) {
|
||||||
printf("%s\n",(const char *)msg);
|
printf("%s\n",(const char *)msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "rdnotification.h"
|
||||||
|
|
||||||
#define RDMETADATA_USAGE "--cart-number=<cart number> [options]\n\nThe following options are recognized:\n\n\
|
#define RDMETADATA_USAGE "--cart-number=<cart number> [options]\n\nThe following options are recognized:\n\n\
|
||||||
--agency=<agency>\n\
|
--agency=<agency>\n\
|
||||||
--album=<album>\n\
|
--album=<album>\n\
|
||||||
@ -43,7 +45,7 @@
|
|||||||
--year=<year>\n\
|
--year=<year>\n\
|
||||||
--add_schedcode=<schedcode>\n\
|
--add_schedcode=<schedcode>\n\
|
||||||
--rem-schedcode=<schedcode>\n\
|
--rem-schedcode=<schedcode>\n\
|
||||||
--verbose\n\
|
--quiet\n\
|
||||||
\n"
|
\n"
|
||||||
|
|
||||||
class MainObject : public QObject
|
class MainObject : public QObject
|
||||||
@ -57,8 +59,9 @@ class MainObject : public QObject
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void updateMetadata();
|
void updateMetadata();
|
||||||
|
void SendNotification(RDNotification::Action action,unsigned cartnum);
|
||||||
void Print(const QString &msg);
|
void Print(const QString &msg);
|
||||||
bool verbose;
|
bool quiet;
|
||||||
unsigned cartnum;
|
unsigned cartnum;
|
||||||
QString cartstring;
|
QString cartstring;
|
||||||
QString artist;
|
QString artist;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user