File indexing completed on 2024-05-12 05:04:11
0001 // SPDX-FileCopyrightText: 2023 Rishi Kumar <rsi.dev17@gmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 0004 #include "ipinfo.h" 0005 0006 #include <QJsonObject> 0007 0008 using namespace Qt::Literals::StringLiterals; 0009 0010 QString IpInfo::id() const 0011 { 0012 return m_id; 0013 } 0014 0015 QString IpInfo::ip() const 0016 { 0017 return m_ip; 0018 } 0019 0020 void IpInfo::setIp(const QString &ip) 0021 { 0022 m_ip = ip; 0023 } 0024 0025 IpInfo::SeverityValues IpInfo::severity() const 0026 { 0027 return m_severity; 0028 } 0029 0030 void IpInfo::setSeverity(const QString &severity) 0031 { 0032 const SeverityValues &newCalculatedSaverity = calculateSeverity(severity); 0033 m_severity = newCalculatedSaverity; 0034 } 0035 0036 QString IpInfo::comment() const 0037 { 0038 return m_comment; 0039 } 0040 0041 void IpInfo::setComment(const QString &comment) 0042 { 0043 m_comment = comment; 0044 } 0045 0046 QDateTime IpInfo::createdAt() const 0047 { 0048 return m_createdAt; 0049 } 0050 0051 QDateTime IpInfo::expiresAt() const 0052 { 0053 return m_expiresAt; 0054 } 0055 0056 void IpInfo::setExpiredAt(const int expiresAt) 0057 { 0058 const QDateTime expiryTime = QDateTime::currentDateTime().addSecs(expiresAt); 0059 m_expiresAt = expiryTime; 0060 } 0061 0062 IpInfo::SeverityValues IpInfo::calculateSeverity(const QString &severity) 0063 { 0064 if (severity == QStringLiteral("sign_up_requires_approval")) { 0065 return LimitSignUps; 0066 } else if (severity == QStringLiteral("sign_up_block")) { 0067 return BlockSignUps; 0068 } else { 0069 return BlockAccess; 0070 } 0071 } 0072 0073 IpInfo IpInfo::fromSourceData(const QJsonObject &doc) 0074 { 0075 IpInfo info; 0076 info.m_id = doc["id"_L1].toString(); 0077 info.m_ip = doc["ip"_L1].toString(); 0078 info.m_severity = calculateSeverity(doc["severity"_L1].toString()); 0079 info.m_comment = doc["comment"_L1].toString(); 0080 info.m_createdAt = QDateTime::fromString(doc["created_at"_L1].toString(), Qt::ISODate).toLocalTime(); 0081 info.m_expiresAt = QDateTime::fromString(doc["expires_at"_L1].toString(), Qt::ISODate).toLocalTime(); 0082 return info; 0083 } 0084 0085 #include "moc_ipinfo.cpp"