overte-HifiExperiments/libraries/networking/src/NodePermissions.h
Zach Fox 7ad3a5a1e3 Commerce: Tons of Interface changes (#11463)
* canRez(Tmp)Certified()

* CertifiedItem beginnings

* Skeleton of verifyOwnerChallenge()

* Controlled failure; updateLocation() skeletion

* Controlled failure on checkout page with ctrl+f

* Skeleton Purchases first-use tutorial

* Initial progress on new setup

* Security pic tip

* Skeleton Certificate page

* Updates to Certificate

* General progress; setup is nearly complete

* Better buttons; last step almost done

* Initial progress on wallet home

* Completed recent transactions

* Security page

* Scrollbar

* Fix auth error text

* PassphraseSelection

* Change security pic

* Minor layout changes; beginnings of emulated header

* Various layout changes; wallet nav bar

* Help screen

* Quick onaccepted change

* First pass at new purchases

* Small style updates

* Some error progress

* Lightbox in purchases

* Collapse other help answers when clicking on another

* REZZED notif

* Commerce Lightbox

* Lots of new interactions in Purchases

* Hook up 'view certificate'

* Fix errors, fix close button on cert

* Purchases timer; much faster filter

* Add debugCheckout

* Purchase updates

* GlyphButton; separator; Checkout Success; Ledger fix; debug modes

* Lock glyph below security pic should be white

* Various fixes, round 1

* Circular mask

* Passphrase change button fix; TextField error edge highlighting

* Recent Activity fixes

* Various changes

* Standard Security Pic location

* Color changes

* Filter bar changes

* Styling for multiple owned items

* Minor language change

* Header dropdown (harder than expected)

* Small fixes

* View backup instructions

* marketplaces.js onCommerceScreen

* Beginnign of new injection

* Marketplace injection changes

* Purchase button style changes

* More button styling

* MY PURCHASES button

* marketplace onUsernameChanged

* New help QA

* Help text changes etc

* Downscale security image, reducing filesize

* Lots of bugfixes

* Cleanup before PR

* Only open cert during inspection if commerce switch is on

* Help text changes

* Purchase status incl. change to confirmed; Help text; Open Explorer to hifikey

* Quick glyph change

* New 'wallet not set up' flow for when entering Purchases or Checkout without set-up wallet
2017-09-27 14:43:51 -07:00

159 lines
5.6 KiB
C++

//
// NodePermissions.h
// libraries/networking/src/
//
// Created by Seth Alves on 2016-6-1.
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_NodePermissions_h
#define hifi_NodePermissions_h
#include <memory>
#include <unordered_map>
#include <QString>
#include <QMap>
#include <QVariant>
#include <QUuid>
#include <QHash>
#include <utility>
#include "GroupRank.h"
class NodePermissions;
using NodePermissionsPointer = std::shared_ptr<NodePermissions>;
using NodePermissionsKey = std::pair<QString, QUuid>; // name, rankID
using NodePermissionsKeyList = QList<QPair<QString, QUuid>>;
namespace std {
template<>
struct hash<NodePermissionsKey> {
size_t operator()(const NodePermissionsKey& key) const;
};
}
class NodePermissions {
public:
NodePermissions() { _id = QUuid::createUuid().toString(); _rankID = QUuid(); }
NodePermissions(const QString& name) { _id = name.toLower(); _rankID = QUuid(); }
NodePermissions(const NodePermissionsKey& key) { _id = key.first.toLower(); _rankID = key.second; }
NodePermissions(QMap<QString, QVariant> perms);
const QString& getID() const { return _id; } // a user-name or a group-name, not verified
void setID(const QString& id) { _id = id; }
void setRankID(QUuid& rankID) { _rankID = rankID; }
const QUuid& getRankID() const { return _rankID; }
NodePermissionsKey getKey() const { return NodePermissionsKey(_id, _rankID); }
// the _id member isn't authenticated/verified and _username is.
void setVerifiedUserName(QString userName) { _verifiedUserName = userName.toLower(); }
const QString& getVerifiedUserName() const { return _verifiedUserName; }
void setGroupID(QUuid groupID) { _groupID = groupID; if (!groupID.isNull()) { _groupIDSet = true; }}
const QUuid& getGroupID() const { return _groupID; }
bool isGroup() const { return _groupIDSet; }
bool isAssignment { false };
// these 3 names have special meaning.
static NodePermissionsKey standardNameLocalhost;
static NodePermissionsKey standardNameLoggedIn;
static NodePermissionsKey standardNameAnonymous;
static NodePermissionsKey standardNameFriends;
static QStringList standardNames;
enum class Permission {
none = 0,
canConnectToDomain = 1,
canAdjustLocks = 2,
canRezPermanentEntities = 4,
canRezTemporaryEntities = 8,
canWriteToAssetServer = 16,
canConnectPastMaxCapacity = 32,
canKick = 64,
canReplaceDomainContent = 128,
canRezPermanentCertifiedEntities = 256,
canRezTemporaryCertifiedEntities = 512
};
Q_DECLARE_FLAGS(Permissions, Permission)
Permissions permissions;
QVariant toVariant(QHash<QUuid, GroupRank> groupRanks = QHash<QUuid, GroupRank>());
void setAll(bool value);
NodePermissions& operator|=(const NodePermissions& rhs);
NodePermissions& operator&=(const NodePermissions& rhs);
NodePermissions operator~();
friend QDataStream& operator<<(QDataStream& out, const NodePermissions& perms);
friend QDataStream& operator>>(QDataStream& in, NodePermissions& perms);
void clear(Permission p) { permissions &= (Permission) (~(uint)p); }
void set(Permission p) { permissions |= p; }
bool can(Permission p) const { return permissions.testFlag(p); }
protected:
QString _id;
QUuid _rankID { QUuid() }; // 0 unless this is for a group
QString _verifiedUserName;
bool _groupIDSet { false };
QUuid _groupID;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(NodePermissions::Permissions)
// wrap QHash in a class that forces all keys to be lowercase
class NodePermissionsMap {
public:
NodePermissionsMap() { }
NodePermissionsPointer& operator[](const NodePermissionsKey& key) {
NodePermissionsKey dataKey(key.first.toLower(), key.second);
if (0 == _data.count(dataKey)) {
_data[dataKey] = NodePermissionsPointer(new NodePermissions(key));
}
return _data[dataKey];
}
NodePermissionsPointer operator[](const NodePermissionsKey& key) const {
NodePermissionsPointer result;
auto itr = _data.find(NodePermissionsKey(key.first.toLower(), key.second));
if (_data.end() != itr) {
result = itr->second;
}
return result;
}
bool contains(const NodePermissionsKey& key) const {
return 0 != _data.count(NodePermissionsKey(key.first.toLower(), key.second));
}
bool contains(const QString& keyFirst, const QUuid& keySecond) const {
return 0 != _data.count(NodePermissionsKey(keyFirst.toLower(), keySecond));
}
QList<NodePermissionsKey> keys() const {
QList<NodePermissionsKey> result;
for (const auto& entry : _data) {
result.push_back(entry.first);
}
return result;
}
const std::unordered_map<NodePermissionsKey, NodePermissionsPointer>& get() { return _data; }
void clear() { _data.clear(); }
void remove(const NodePermissionsKey& key) { _data.erase(key); }
private:
std::unordered_map<NodePermissionsKey, NodePermissionsPointer> _data;
};
const NodePermissions DEFAULT_AGENT_PERMISSIONS;
QDebug operator<<(QDebug debug, const NodePermissions& perms);
QDebug operator<<(QDebug debug, const NodePermissionsPointer& perms);
NodePermissionsPointer& operator&=(NodePermissionsPointer& lhs, const NodePermissionsPointer& rhs);
NodePermissionsPointer& operator&=(NodePermissionsPointer& lhs, NodePermissions::Permission rhs);
NodePermissionsPointer operator~(NodePermissionsPointer& lhs);
#endif // hifi_NodePermissions_h