educative.io

Educative

Security/Permissions

Hi,

in the last paragraph: “Security/Permissions”, can you elaborate on this line:
“The columns will store the UserIDs of those users that have permission to see the URL.”

thanks

1 Like

Hi @milo_t!

It means that the record of only those users will be stored who have granted access/permission to use that specific URL. Other than those the other users whose IDs will not be inserted in the record would not be granted access to the URL. This means a standard has been set that permission granted users are only in the record.

Thanks @Rabia_Mumtaz. yes of course.

My question is HOW that table of permissions is formatted?

Please note that the authors are specifically talking about the Cassandra database and the fact that it is a ‘wide column’ database.

“Given that we are storing our data in a NoSQL wide-column database like Cassandra, the key for the table storing permissions would be the ‘Hash’ (or the KGS generated ‘key’). The columns will store the UserIDs of those users that have permission to see the URL.”

@Design_Gurus

1 Like

There can be multiple ways to do this in Cassandra.

One approach could be use a column to store each individual user’s ID.

CREATE TABLE permission_info(
key_hash text,
user_id text,
PRIMARY KEY (key_hash, user_id)
);

INSERT INTO permission_info (key_hash, user_id) 
    VALUES ('HG5YTS', 'user123');

INSERT INTO permission_info (key_hash, user_id) 
    VALUES ('HG5YTS', 'user456');

Another approach could be to use a Set, List or Map. A Map could also enable us to specify different permission types per user:

CREATE TABLE permission_info(
 key_hash text primary key,
 user_permissions map<text, text>
);

For more details, take a look at the Cassandra documents on how to insert/update data in Lists/Sets/Maps: https://docs.datastax.com/en/cql-oss/3.3/cql/cql_using/useInsertList.html

1 Like

Thanks, @Design_Gurus for clarification.

@milo_t hope you have got your answer now.

Regards,

Thanks @Design_Gurus, that helps. I have a couple of follow up questions:

  1. in the first method, would there be a scenario that we would benefit from swapping the columns? so the user_id would be the Cassandra partition key:
    CREATE TABLE permission_info(
    user_id text,
    key_hash text,
    PRIMARY KEY (user_id, key_hash)
    );

  2. considering that Cassandra allows for variable columns for each row, would there be a scenario that the following design would be preferred?
    key=user_id, col1=ShortUrl1, col2=ShortUrl2, …col_n=ShortUrl_n
    (in a way it is SET expanded)