Encapsulated checking of administrative rights in the 'Lablib' class

remotes/origin/HEAD
markuspg 8 years ago
parent c151717aee
commit ae5ae01800

@ -65,7 +65,6 @@ lc::Lablib::~Lablib () {
}
netstatThread.quit();
netstatThread.wait();
delete adminUsers;
if ( clients ) {
for ( QVector< Client* >::iterator it = clients->begin(); it != clients->end(); ++it ) {
delete *it;
@ -77,6 +76,17 @@ lc::Lablib::~Lablib () {
delete webcams;
}
bool lc::Lablib::CheckIfUserIsAdmin( const QString &argUserName ) const {
for ( const auto &s : adminUsers ) {
if ( s == argUserName ) {
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] User '%1' has administrative"
" rights." ).arg( argUserName ) );
return true;
}
}
return false;
}
void lc::Lablib::DetectInstalledZTreeVersionsAndLaTeXHeaders() {
// Detect the installed LaTeX headers
if ( !settings->lcInstDir.isEmpty() ) {
@ -145,8 +155,9 @@ void lc::Lablib::ReadSettings() {
messageBox.exec();
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] 'admin_users' was not set. No permission for administrative tasks." ) );
} else {
adminUsers = new QStringList{ labSettings.value( "admin_users", "" ).toString().split( '|', QString::SkipEmptyParts, Qt::CaseInsensitive ) };
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] 'admin_users': %1").arg( adminUsers->join(" / ") ) );
adminUsers = labSettings.value( "admin_users", "" ).toString()
.split( '|', QString::SkipEmptyParts, Qt::CaseInsensitive );
debugMessagesTextEdit->appendPlainText( tr( "[DEBUG] 'admin_users': %1").arg( adminUsers.join(" / ") ) );
}
// Read the port the ClientHelpNotificationServer shall listen on

@ -66,11 +66,12 @@ public:
/** Lablib's destructor
*/
~Lablib();
/*! Returns the users who have administrative rights
*
* @return The users with administrative rights
/*!
* \brief CheckIfUserIsAdmin checks if the account with the passed user name has administrative rights
* \param argUserName The account name which shall checked for administrative rights
* \return True, if the account has administrative rights; false, otherwise
*/
QStringList *GetAdminUsers() const { return adminUsers; }
bool CheckIfUserIsAdmin( const QString &argUserName ) const;
/*! Returns the currently set port number of zTree
*
* @return The currently set port number for zTree
@ -157,7 +158,7 @@ private:
*/
void ReadSettings();
QStringList *adminUsers = nullptr; //! Stores all users with administrative rights
QStringList adminUsers; //! Stores the names of all user accounts with administrative rights
QString chosenZTreeDataTargetPath;
int chosenZTreePort = 7000; //! Stores the currently chosen port for new zTree instances
ClientHelpNotificationServer *clientHelpNotificationServer = nullptr; //! A server to retrieve help requests from the clients

@ -62,7 +62,7 @@ bool lc::MainWindow::CheckIfUserIsAdmin() {
userName = env.value( "USERNAME", "" );
}
if ( userName == "" ) {
if ( userName.isEmpty() ) {
QMessageBox messageBox{ QMessageBox::Warning, tr( "User not detectable" ),
tr( "Your user name could not be queryed. The admin tab will be"
" disabled. You won't be able to perform administrative"
@ -76,19 +76,7 @@ bool lc::MainWindow::CheckIfUserIsAdmin() {
.arg( userName ) );
lablib->SetUserNameOnServer( userName );
QStringList *adminUsers = lablib->GetAdminUsers();
if ( adminUsers != nullptr ) {
for ( auto s : *adminUsers ) {
if ( s == userName ) {
ui->PTEDebugMessages->appendPlainText( tr( "[DEBUG] '%1' has administrative"
" rights." ).arg( userName ) );
return true;
}
}
}
return false;
return lablib->CheckIfUserIsAdmin( userName );
}
void lc::MainWindow::DisableDisfunctionalWidgets() {

Loading…
Cancel
Save